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

The middleware does not stop the route as expected. #2291

Closed
ghost opened this issue Apr 3, 2014 · 4 comments
Closed

The middleware does not stop the route as expected. #2291

ghost opened this issue Apr 3, 2014 · 4 comments

Comments

@ghost
Copy link

ghost commented Apr 3, 2014

Hello,

I have a middleware like this:

// Autoloaded class
class HelloMiddleware implements \Phalcon\Mvc\Micro\MiddlewareInterface
{
    public function call($app)
    {
        // $logger->info(1);
        return false;
        // or $app->stop();
    }
}

I want to make it work:

$app = new \Phalcon\Mvc\Micro();
$app->before(new HelloMiddleware());
$app->get('/', function () use ($app) {
    // $logger->info(2);
});

The HelloMiddleware does not stop the route as expected and both the 1 and 2 are logged.


Do you have any idea about why it does not work?

Versions:

Phalcon: 1.3.1
PHP: 5.3.10-1ubuntu3.10

Thanks.

@dreamsxin
Copy link
Contributor

Use like this:

class HelloMiddleware implements Phalcon\Mvc\Micro\MiddlewareInterface
{
    protected $_number = 0;

    public function call($app)
    {
        $app->stop();
    }
}

@ghost
Copy link
Author

ghost commented Apr 13, 2014

Thanks for your patch, but the compile failed.

I send a PR #2333 to make return false and stop method in middleware work as same as which in anonymous function for before event.

@dreamsxin
Copy link
Contributor

Don't use PR, Only use method stop.

@ghost
Copy link
Author

ghost commented Apr 14, 2014

Method stop in middleware does not stop the route but only other middlewares.

But method stop in anonymous function does.

This issue was closed.
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

2 participants