Comments (17)
@maiorano84 I ended up going with a different routing solution, but Iām sure it would make a good reference for someone if you wanted to post it.
from route.
This is something I'd be interested in adding, it needs more discussion around the format of the configuration array though as there is the possibility of adding named routes in the future but it's not something currently implemented.
Also we have to take per route configuration in to account for strategies.
Your example has the knowledge of modules/sections which I also like but again would need discussion around planned future features. I plan to release a roadmap at some point soon so would you be happy to pick this back up with me once I've finalised that?
from route.
Yeah, I would be more than happy.
In terms of the named routes part, is it more that I am assuming that everyone would be using named routes? If that is the case, what is the cost of having 2 methods?
$router->addNamedRoutesFromConfig($routes);
// --or--
$router->addRoutesFromConfig($routes);
from route.
It will definitely be an optional thing, having several conversations about the benefits of named routes before any decision is made as I don't personally see how I would use them in my own projects that would benefit me over what I'm doing now. I'd love ALL input I can get on that and any code examples of how it would ideally work for people if you have any input?
from route.
So, last night I was thinking and I have come up with an idea on how it could be done...
This takes named routes into consideration
Instead of having two functions, we could have a function takes three parameters:
- array $routes | default: []
- boolean $namesRoutes | default: false
- StrategyInterface $strategy | default: null
It is a very quick and dirty implementation of my idea but serves its basic purpose
I am implementing this into my own micro framework for learning purposes and would be good for me for the following:
The reason for a route config for me would be the ability to separate have them in one file along with separating them into several configs (as per the example). It also allows for developers to go to one place on a project.
The reason for named parameters would be the ability to create a url parser (similar to the path() functionality in twig) for a php, mustache or twig template allowing me to edit routes easily by changing the parameter requirements or doing a search and replace across the project. I can search for every instance of route article_by_category_and_year
, if this rendered as /articles/{{ article.category }}/{{ article.year }}
then I can use the route name to search on.
from route.
š Couldn't you fit all options into an array:
$routes = [
[
'pattern' => '/demo/{name}',
'controller' => 'Demo\Controller\DemoController::index',
'method' => 'GET',
'name' => ''demo_page',
'strategy' => 'FQNS\CustomStrategy'
],
];
from route.
@patrickheeney yes, this is planned in the near future for v2.
from route.
@philipobenito Sounds good. Was just adding my feedback from your suggestion:
I'd love ALL input I can get on that and any code examples of how it would ideally work for people if you have any input?
from route.
Yes, mentioned on the other thread, apologies if I ever appear to be curt, it's generally just jumping on and and addressing issues and discussions in the middle of something else so I get straight to my point, don't want that to discourage you from contributing with discussion and suggestions.
from route.
š
from route.
@NigelGreenway I'm building a Service Provider to go with version 2.0.0 that will allow use of config. Are you happy with that as a resolution to this?
from route.
Hi @philipobenito,
Sorry, had my email app closed.
A service provider would be great, cheers.
I would then be able to create the config as I see fit and then create a service provider to manage it?
If you need any help with anything like testing, let me know. Will be glad to help where I can.
from route.
@NigelGreenway yup, taking a new tact with config and handling it with bootable service providers in v2 of container, that way there's no real defined structure and anybody can build their own service provider to handle it in a different way if they feel they want to/need to. i.e. migrations from frameworks etc.
So if you're happy with that I'll close this and consider it resolved by that.
from route.
@philipobenito Yeah, more than happy. Cheers
š
from route.
To my knowledge, this concept didn't get fleshed out, and at least as of v4 it's not possible to reference an external routes.php
file. Mind providing a little insight into the trouble implementing this concept? I'm curious about whether it might be possible in the future.
from route.
@kevinsmith I know I'm responding over a year later, but I just found this discussion.
I have an implementation I'm actually currently putting together using Container and a YAML file. Seems to work pretty well so far, but I haven't built out any unit tests yet. Is this something you're still interested in? If so, I can work on decoupling this from my personal implementation and getting a quick Composer package up.
from route.
I am currently working on a yaml configuration parser as well, so it is a feature at least a couple of us are looking for.
from route.
Related Issues (20)
- Feature request: custom attributes for route and route group accessible within a middleware HOT 6
- Catch Exception Best Way HOT 3
- Feature request: map with array of methods HOT 1
- Feature request: make $request available in getOptionsCallable HOT 2
- I cannot make post requests HOT 5
- Url resolve fails with 2 numeric parameter HOT 3
- Add an option to get the target route from the middleware HOT 2
- Why isn't the middleware stack executed for unmatched routes? HOT 2
- psr/simple-cache version constraints HOT 2
- Allow for empty route paths to be treat as the base route path HOT 2
- Nested groups are required HOT 1
- Feature request: Treat Route `$handler` that implements RequestHandlerInterface as callable
- Root exception class (and possibly, its children) not compatible with PHP7+
- Request matcher? guess if ServerRequest can be handled
- Dispatcher: handle and find HOT 1
- Feature: Extra map() options
- Method to get declared routes?
- How can I assign controller to errors http ? HOT 1
- Cannot Change Cache Key
- Is this package still actively maintained? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from route.