-
Notifications
You must be signed in to change notification settings - Fork 25
PSR-11 Container Interface #33
PSR-11 Container Interface #33
Conversation
Instead of using a custom regex, nikic suggests to use parsed results: nikic/FastRoute#66 (comment) This also throws errors for missing mandatory parameters (#30).
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.
@xtreamwayz looks good overall but I left some feedback for a minor docblock typo and for a str_replace(...)
call that might not actually be necessary.
src/FastRouteRouter.php
Outdated
* @throws Exception\InvalidArgumentException if the route name is not | ||
* known. | ||
* @throws Exception\InvalidArgumentException if the route name is not known or | ||
* or a parameter value does not match its regex. |
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.
Typo - double "or"
src/FastRouteRouter.php
Outdated
} | ||
|
||
// Check substitute value with regex | ||
$regex = '~^' . str_replace('/', '\/', $part[1]) . '$~'; |
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.
I'm not 100% clear on why the str_replace
is necessary here. If we're adding ~
to the start and end, preg_match
doesn't need the forward slashes escaped. For instance, if $part[1]
is foo/bar/baz
, then all of the following return 1
:
preg_match('/^foo\/bar\/baz$/', $part[1]);
preg_match('~^foo\/bar\/baz$~', $part[1]);
preg_match('~^foo/bar/baz$~', $part[1]);
If I haven't misunderstood something, then I suggest we remove line 288
and replace the next line with:
if (! preg_match('~^' . $part[1] . '$~', $substitutions[$part[0]])) {
PSR-11 Container Interface
Built on top of #32