New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added option to have empty paths #233
Conversation
…parenthesis where they should have been)
Couldn't you achieve this same thing with just: $klein->with('/users', function () use ($klein) {
$klein->respond('GET', '/?', function () {
echo 'Hello World';
});
}); |
Yes |
Hmm, I can see a case for an empty string, but its implicit nature is strange to me. |
Could it be replaced by a Example: $klein->with('/users/', function () use ($klein) {
$klein->respond('GET', '.', function () {
echo 'Hello World';
});
}); Should match the path But, I beleive my current pull request should be considered a bug fix since all it does is prevent an undesirable notice. Maybe we could remove the unit test as it may not be a documented behaviour, but it should not throw notices anyhow. |
Very true. Not checking for the offset first is bad, so this PR fixes that. An empty string is weird, but I guess its technically legal. If you could just split up the line into a multi-line if block so it doesn't go beyond 120 characters, then the Travis style tests would pass. Maybe like this?: if ($this->namespace
&& (isset($path[0]) && $path[0] === '@')
|| (isset($path[0]) && $path[0] === '!' && isset($path[1]) && $path[1] === '@')) { |
Is that the intended condition? Because before it was this: $this->namespace && $path[0] === '@' || ($path[0] === '!' && $path[1] === '@') which match With the one you provided, it would be |
Alright, so, using your condition, this PR should be good to go. I'll open an issue to discuss the addition of the |
@@ -53,7 +53,7 @@ public function testBuildBasic( | |||
$should_match = true | |||
) { | |||
// Test data | |||
$test_path = $test_path ?: '/test'; | |||
$test_path = !is_string($test_path) ? '/test' : $test_path; |
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 hate to be a pain, but this would be a bit more readable to me if it wasn't negated in front:
$test_path = is_string($test_path) ? $test_path : '/test';
Alright, done |
Awesome! Tests passed! |
Added option to have empty paths
For example, this code:
Responds to the given the path
/users/
, as it should, but throws an error:This PR fixes that bug and allows for paths to be empty.
Please note that providing
null
as an argument for the path creates a catch-all route so this is not an option.