Skip to content
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

Update Router.php #133

Closed
wants to merge 2 commits into from
Closed

Update Router.php #133

wants to merge 2 commits into from

Conversation

WeaponsTheyFear
Copy link

Added the option to return matching routes rather than directly executing callbacks.

// Create Router instance
$router = new Bramus\Router\Router();
$router->setReturnRoutes(true);

$router->before('GET', '/', function() {
    echo 'before middleware';
});

// Define routes
$router->get('/', function() {
    echo 'hello';
});

// Run it!
$matches = $router->run();

foreach ($matches as $route) {
    $route['fn']();
}

Added the option to return matching routes rather than directly executing callbacks.

// Create Router instance
$router = new Bramus\Router\Router();
$router->setReturnRoutes(true);

$router->before('GET', '/', function() {
    echo 'before middleware';
});

// Define routes
$router->get('/', function() {
    echo 'hello';
});

// Run it!
$matches = $router->run();

foreach ($matches as $route) {
    $route['fn']();
}
Copy link
Owner

@bramus bramus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you swapped $numHandled for $this->numHandled, yet on line 330 it's still referring to $numHandled. Could you change that?

Looking good otherwise, although a test would also be welcome.

Fixed line 330, referring to $this->numHandled
@WeaponsTheyFear
Copy link
Author

Done!

@bassauer-storms-media
Copy link

this is an awesome feature (I coud just use very well) - looking forward to the moment this gets merged into the master 👍 👍 👍

@bramus
Copy link
Owner

bramus commented Feb 14, 2021

FYI: tests are failing:

$ composer test
> ./vendor/bin/phpunit --colors=always

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /Users/bramus/repos/projects/php-router/vendor/phpunit/phpunit/src/Util/Getopt.php on line 38
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

........................FFF.........

Time: 47 ms, Memory: 4.00MB

There were 3 failures:

1) RouterTest::test404
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'route not found'
+''

/Users/bramus/repos/projects/php-router/tests/RouterTest.php:641

2) RouterTest::test404WithClassAtMethod
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'route not found'
+''

/Users/bramus/repos/projects/php-router/tests/RouterTest.php:667

3) RouterTest::test404WithClassAtStaticMethod
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'route not found'
+''

/Users/bramus/repos/projects/php-router/tests/RouterTest.php:693

FAILURES!
Tests: 36, Assertions: 63, Failures: 3.
Script ./vendor/bin/phpunit --colors=always handling the test event returned with error code 1

It looks like there is an unwanted side-effect when it comes to handling 404's.

Also spotted a lost $numHandled on line 311.

@WeaponsTheyFear WeaponsTheyFear closed this by deleting the head repository Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants