Comments (7)
It's not something that is intended. Once documentation is written then it will include a section on this.
What is your use case to dispatch twice?
On Thu, Oct 8, 2015 at 10:02 PM, Bernardo [email protected]
wrote:
When I try to dispatch more than once on the same
RouteCollection
instance, I get the following exception:FastRoute\BadRouteException: Cannot register two routes matching "/" for method "GET" in /home/ubuntu/workspace/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php on line 55
If it's not intended to do so, this behaviour should probably be documented.
I can probably work around this with a factory of some sorts, but it would be neat if it was supported.
Minimal testcase:use League\Route\RouteCollection; use Zend\Diactoros\Response; use Zend\Diactoros\ServerRequest; use Zend\Diactoros\Uri; $routes = new RouteCollection(); $routes->get('/', function() { return 'foo'; }); $routes->dispatch((new ServerRequest())->withUri(new Uri('/')), new Response()); $routes->dispatch((new ServerRequest())->withUri(new Uri('/')), new Response());
Reply to this email directly or view it on GitHub:
#75
from route.
My main use case at the moment is unit testing. I generate various requests
and run them against the same RouteCollection.
Another use case could be internal routing to achieve something like HMVC (
https://en.m.wikipedia.org/wiki/Hierarchical_model–view–controller).
On Oct 8, 2015 11:06 PM, "Phil Bennett" [email protected] wrote:
It's not something that is intended. Once documentation is written then it
will include a section on this.What is your use case to dispatch twice?
On Thu, Oct 8, 2015 at 10:02 PM, Bernardo [email protected]
wrote:When I try to dispatch more than once on the same
RouteCollection
instance, I get the following exception:FastRoute\BadRouteException: Cannot register two routes matching "/" for method "GET" in /home/ubuntu/workspace/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php on line 55
If it's not intended to do so, this behaviour should probably be
documented.
I can probably work around this with a factory of some sorts, but it
would be neat if it was supported.
Minimal testcase:use League\Route\RouteCollection; use Zend\Diactoros\Response; use Zend\Diactoros\ServerRequest; use Zend\Diactoros\Uri; $routes = new RouteCollection(); $routes->get('/', function() { return 'foo'; }); $routes->dispatch((new ServerRequest())->withUri(new Uri('/')), new Response()); $routes->dispatch((new ServerRequest())->withUri(new Uri('/')), new Response());
Reply to this email directly or view it on GitHub:
#75—
Reply to this email directly or view it on GitHub
#75 (comment).
from route.
Well the issue here is less the dispatch but the fact that the underlying router (FastRoute) does not allow matching twice so it's not something I can implement in the manner you describe.
When it comes to unit tests, my personal opinion is that if you're routing, then it's not a unit test really, unit test the controller callable and let your other test suites look after routing or trust that the router is unit tested to ensure your routes will be matched.
That being said, by using named routes you can achieve what you want to achieve by just pulling the route from the collection and dispatching the route directly. Handling it this way also has the benefit of not relying on paths, so they can change without having to then reactor where you're dispatching them from.
On Thu, Oct 8, 2015 at 10:21 PM, Bernardo [email protected]
wrote:
My main use case at the moment is unit testing. I generate various requests
and run them against the same RouteCollection.
Another use case could be internal routing to achieve something like HMVC (
https://en.m.wikipedia.org/wiki/Hierarchical_model–view–controller).
On Oct 8, 2015 11:06 PM, "Phil Bennett" [email protected] wrote:It's not something that is intended. Once documentation is written then it
will include a section on this.What is your use case to dispatch twice?
On Thu, Oct 8, 2015 at 10:02 PM, Bernardo [email protected]
wrote:When I try to dispatch more than once on the same
RouteCollection
instance, I get the following exception:FastRoute\BadRouteException: Cannot register two routes matching "/" for method "GET" in /home/ubuntu/workspace/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php on line 55
If it's not intended to do so, this behaviour should probably be
documented.
I can probably work around this with a factory of some sorts, but it
would be neat if it was supported.
Minimal testcase:use League\Route\RouteCollection; use Zend\Diactoros\Response; use Zend\Diactoros\ServerRequest; use Zend\Diactoros\Uri; $routes = new RouteCollection(); $routes->get('/', function() { return 'foo'; }); $routes->dispatch((new ServerRequest())->withUri(new Uri('/')), new Response()); $routes->dispatch((new ServerRequest())->withUri(new Uri('/')), new Response());
Reply to this email directly or view it on GitHub:
#75—
Reply to this email directly or view it on GitHub
#75 (comment).
Reply to this email directly or view it on GitHub:
#75 (comment)
from route.
Fair enough, I'll try that.
from route.
Too bad it's because of fastroute. Would be nice to use league/route in a reactphp powered application or something, where the router object is reused for every request
from route.
You still can, but you'll have to build a wrapper around the dispatch method that creates a new RouteCollection
and loads the routes for each dispatch.
from route.
Well, that's exactly what you would want to avoid :-)
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.