Fix Route::add('/foo/bar/foo/bar') in index.php
ImMaax opened this issue · 4 comments
Lines 80-85, index.php:
// Long route example
// This route gets never triggered because the route before matches too
// TODO: Fix this; it'll get triggered
Route::add('/foo/bar/foo/bar', function() {
echo 'This is the second match <br>';
});
This route IS working BUT it matches a pattern which it shouldn't. Tested with PHP 7.4.1 Testing Server and Apache2.4.25
I tested the behavior of the /foo/bar/foo/bar URL. It will print the following lines using PHP 7.4.1:
This is the first match: foo / bar / foo / bar
This is the second match
This is the expected behavior because both routes will match this URL.
But I think this comment does not make sens at the moment: "This route gets never triggered because the route before matches too"
In another project I currenty working on I added a fourth parameter to the run() method. This boolean flag named $first_match_only will ony execute the first matching route. I think this option would solve the "problem". Maybe its a good idea to switch this multi matching behaviour off by default.
Switching to that is a good idea. I was already confused by that comment because it just makes sense that both the first and the second one are getting triggered.
I think I have never changed this comment after adding this feature^^
I will add this switch in the next few days.
I now added a fourth parameter to the run() method. The multi match mode is now disabled by default.