Code Monkey home page Code Monkey logo

Comments (3)

bramus avatar bramus commented on July 29, 2024 1

For the first part of your question (the logging part):

Don't forget that the current URI can be found in $_SERVER['REQUEST_URI']. Combined with a Before Router Middleware you can log all requests.

Something like this:

$router->before('GET|POST|PUT|DELETE|PATCH|OPTIONS', '.*', function() use ($logger) {
  $logger->log($_SERVER['REQUEST_URI']);
}

For the second part of your question (to know which route has been run): I can look into this, or will happily accept a PR that provides this feature.

from router.

bramus avatar bramus commented on July 29, 2024

Reopening, didn't get into the 2nd part of the question … oops 😊

from router.

WeaponsTheyFear avatar WeaponsTheyFear commented on July 29, 2024

I kinda hacked up Bramus slightly to do just this; return the routes that run rather than execute the callback handlers. The run function returns an array of Route objects, which from there you can handle as you need. In my instance, I needed to be able to have each call back class created by my dependency injector (Auryn). I could submit a pr, but I need to change a few things first as I altered the handler method to no longer function as expected.

To get the router to return the routes rather than execute the callbacks, it could set a simple boolean.

$router = new \Bramus\Router\Router();
$router->setReturnRoutes(true);
// Define routes as normal
$matches = $router->run();

$matches would contain the method, pattern and callback of any/all routes that matched, including before middleware. From this point, you could handle as you see fit. If the interest and willingness to add the feature is there, I'll gladly submit the PR.

from router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.