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

Bugfix #10912 (Micro Middleware (before) does not stop operation) #10923

Closed
wants to merge 1 commit into from
Closed

Bugfix #10912 (Micro Middleware (before) does not stop operation) #10923

wants to merge 1 commit into from

Conversation

pauliuspetronis
Copy link
Contributor

In this pull request is one important change.

before this change:

  1. if event (before) is closure and return false - cancels the route execution
  2. if event (before) is MiddlewareInterface object and return false/true/... - not cancels route execution

In this change:

  1. if event (before) is closure and return false/true/... - not cancels route execution
  2. if event (before) is MiddlewareInterface and return false/true/... - not cancels route execution

If you need to cancel execution on event (before) - in both cases must be called $microApplication->stop();

For example:

<?php
$app = new Phalcon\Mvc\Micro();
$app->before(function () use ($app) {
    if ($app['session']->get('auth') == false) {
        $app->stop();
        return false;
    }
    return true;
});
$app->handle();

or

<?php
class Auth implements Phalcon\Mvc\Micro\MiddlewareInterface
{
    public function call(Phalcon\Mvc\Micro $app)
    {
         if ($app['session']->get('auth') == false) {
            $app->stop();
            return false;
        }
        return true;
    }
}
$app = new Phalcon\Mvc\Micro();
$app->before(new Access());
$app->handle();

@andresgutierrez
Copy link
Sponsor Contributor

I think this must be submitted to 2.1.x

@sszdh
Copy link

sszdh commented Sep 10, 2015

So what is return false/true for, anymore?

Why we should use $app->stop()

Thanks

@pauliuspetronis
Copy link
Contributor Author

@andresgutierrez - submitted (#10931)

@JuliusKoronci
Copy link

This is still there even with version 3+ ..no matter if your return true, false or call $app->stop() it will not top with the MiddlewareInterface

@pauliuspetronis pauliuspetronis deleted the BugFix10912in2.0.x branch April 26, 2017 21:07
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.

None yet

5 participants