lyrixx / Silex-Kitchen-Edition

This project is a sample or a bootstrap silex application
MIT License
643 stars 141 forks source link

debug=true produces ProfilerListener::__construct() fatal error #60

Closed bantar closed 8 years ago

bantar commented 8 years ago

I did a fresh install of Kitchen-Edition. The pertinent installed packages for this error are as follows:

silex/silex                 v1.3.4  The PHP micro-framework based on the Symfony Components
silex/web-profiler          v1.0.7  A WebProfiler for Silex
symfony/http-kernel         v3.0.0  Symfony HttpKernel Component
symfony/http-foundation     v3.0.0  Symfony HttpFoundation Component
symfony/web-profiler-bundle v2.8.0  Symfony WebProfilerBundle

If you enable debug, it throws this fatal error: Catchable fatal error: Argument 2 passed to Symfony\Component\HttpKernel\EventListener\ProfilerListener::__construct() must be an instance of Symfony\Component\HttpFoundation\RequestStack, null given, called in \ske\vendor\silex\web-profiler\Silex\Provider\WebProfilerServiceProvider.php on line 184 and defined in \ske\vendor\symfony\http-kernel\EventListener\ProfilerListener.php on line 48

It appears to be a combination of mismatched package installs. I found that the errored call is indeed fixed in 2.0-dev of silex/web-profiler, however, if you include it, it wants to also include silex/silex 2.0. Rather than go down that alley, I cobbled something together. It's a minor change, so I did the following to temporarily correct it.

Changed ...\vendor\silex\web-profiler\Silex\Provider\WebProfilerServiceProvider.php

// HTTPKernel 3.0 changed the ProfileListener constructor.  This is fixed in 
// Silex-WebProfiler/WebProfilerServiceProvider.php v2.0, but it requires 
// Silex/Silex 2.0 as well.  I'm running 1.3.4
//
        $app['profiler.listener'] = $app->share(function ($app) {
            return new ProfilerListener(
                $app['profiler'], 
                $app['request_stack'], 
                $app['profiler.request_matcher'], 
                $app['profiler.only_exceptions'], 
                $app['profiler.only_master_requests']
             );
        });
//        
/*  Commented out this older ProfilerListener constructor call
        $app['profiler.listener'] = $app->share(function ($app) {
            return new ProfilerListener(
                $app['profiler'],
                $app['profiler.request_matcher'],
                $app['profiler.only_exceptions'],
                $app['profiler.only_master_requests'],
                $app['request_stack']
            );
        });
 */

It now works. Hopefully there is a better solution.

lyrixx commented 8 years ago

Fixed by #62 (The profile is now gone ; Will re-add it later)