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

after router middleware not keeping states? #205

Open
itskaoz opened this issue Apr 30, 2023 · 0 comments
Open

after router middleware not keeping states? #205

itskaoz opened this issue Apr 30, 2023 · 0 comments

Comments

@itskaoz
Copy link

itskaoz commented Apr 30, 2023

Hi!

I'm doing something like this

init stuff
$router->before stuff
$router->match stuff

$router->run(afterRouterMiddleware());

The route handling functions are setting some variables in static or singleton objects and everything runs fine between different objects. But the afterRouterMiddleware() function seems to forget all about these states. If i call the function just after $router->run() it runs fine but not as a callback.

I will write a more concrete example:

class AccessController
{
  public static function authenticateForAdmin() {
    User::getInstance()->setId(1337);
  }
}
// bootstrap
$router->before('GET|POST|PUT|DELETE', '/admin/(?!authenticate)(.*)', 'AccessController@isVerifiedAsAdmin');
$router->mount('/admin', function () use ($router) {
    $router->match('GET|POST', '/authenticate', 'AccessController@authenticateForAdmin');
}

$router->run(function() {
  User::getInstance()->getId(); // <<=== null
});

User::getInstance()->getId(); // <<=== 1337

I think this behaviour is not supposed to happen.

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

No branches or pull requests

1 participant