-
Notifications
You must be signed in to change notification settings - Fork 195
Conversation
This method is useful for defining a single middleware that will respond to any of the $httpRouteMethods. For example, a Restful controller that has logic to route to the appropriate method internally: $app->any('/foo', Api\RestfulController::class); Remove any check
$this->assertEquals('/foo', $route->getPath()); | ||
$this->assertSame($this->noopMiddleware, $route->getMiddleware()); | ||
|
||
$reflClass = new \ReflectionClass($this->getApp()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move ReflectionClass
to use statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spiffyjr I agree with @samsonasik - but have a different suggestion:
- Import
ReflectionProperty
into the file. - Use the following:
php $app = $this->getApp(); $r = new ReflectionProperty($app, 'httpRouteMethods'); $r->setAccessible(true); $routeMethods = $r->getValue($app);
Since you're interested in a specific property, do reflection directly on it, instead of pulling it from class reflection. 😄
That's what the route() method already does if no HTTP method are provided.
|
Oh, honestly, I just assumed that route() required methods. I should RTFM? |
Relevant docs are: Essentially, if you only pass the route and middleware to That said, it's more verbose than your proposed |
I'd agree. It's also similar to other frameworks where route is typically used for custom mapping, e.g., POST and PUT but not GET, etc. |
@spiffyjr Can you also update the |
I originally had an entire section on any() but removed in favor of this version. It's simple and the word "any" makes it obvious what it does. |
*/ | ||
public function any($path, $middleware, $name = null) | ||
{ | ||
return $this->route($path, $middleware, $this->httpRouteMethods, $name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass a null
or Router\Route::HTTP_METHOD_ANY
for the third argument. $httpRouteMethods
only really exists to determine what methods are valid overloading methods.
I used Router\Route::METHOD_ANY for brevity (and clarity!). |
You mean "clarity," right? :) Looks good; will merge later today! |
Dammit man, I'm a programmer not an English major. :D |
@spiffyjr Looks like you need to use |
That's what I get for using the online editor. That's also what Travis is for! Hooray! |
Still failing: Essentially, you should be asserting against |
- Assert against `Route::HTTP_METHOD_ANY`, not array of routes.
Merged to develop for release with 0.2.0. |
Having a kid at the moment so thanks for updating this. |
This method is useful for defining a single middleware that will respond to any of the $httpRouteMethods. For example, a Restful controller that has logic to route to the appropriate method internally: