Silex/Pimple: app parameter not updated instantly by middleware

136 views Asked by At

I use the Silex/Pimple container to store parameters for my application. Some of those parameters are set using middleware.

Now I have come across the problem where I want to access a parameter value that should have been set through middleware. But when I output it, it still contains the old value.

This is a simplified version of my code:

    $app['test'] = 'old value';

    $app->before(function (Symfony\Component\HttpFoundation\Request $request, Silex\Application $app){
       // logic
       $app['test'] = 'new value';
    }, Silex\Application::EARLY_EVENT);

    echo $app['test'];

outputs:

old value

Does someone know how I can force the middleware to run first and then do the output? Or is there an other way to interact with the request before everything else?

0

There are 0 answers