Silex-WebProfiler
Silex-WebProfiler copied to clipboard
Silex 2.0 and 'Identifier "dispatcher" does not contain an object definition.'
Note: I'm using silex 2.0.x-dev#c207787 and WebProfiler 2.0.x-dev.
Registering the WebProfilerServiceProvider
with the following code:
$app->register(new WebProfilerServiceProvider, [
'profiler.cache_dir' => __DIR__ . $cacheDir,
'profiler.mount_prefix' => $mountPrefix
]);
Throws the following exception:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Identifier "dispatcher" does not contain an object definition.' in /vagrant/vendor/pimple/pimple/src/Pimple/Container.php on line 232 ( ! ) InvalidArgumentException: Identifier "dispatcher" does not contain an object definition. in /vagrant/vendor/pimple/pimple/src/Pimple/Container.php on line 232
It seems that Container::extend()
is throwing the exception because the value "dispatcher" (the EventDispatcher
object) doesn't contain the __invoke()
method:


I've had a similar issue and noticed that the sequence you add things to the container matters. For example, once I did $app['twig']->addGlobal('foo', 'bar');
, everything added after that failed. So by registering the WebProfilerServiceProvider
earlier, fixed it for me. Not too elegant, but at least I could continue. Just letting you know of a possible solution.
Hmm, thanks for the suggestion @xiaohutai. The only reason I registered it last is because the documentation states, in italics, I might add:
Make sure to register all other required or used service providers before WebProfilerServiceProvider.
I'll give switching things around a go anyway and see how that goes.
I've also had this issue although not specifically with the web profiler but other service providers. I've also found that moving things around can sometimes help. It just sounds like something that is fundamentally broken with Silex and needs to be fixed.
Same here, it seams to happen if $app['dispatcher'] was already evaluated with a $this['dispatcher']->addListener(...) or something else... be sure to put those calls in the boot() method => it s not a bug
Confirm that moving any dispatcher related code like addListener to the end fixes the problem
To avoid this bug, I either add listener (or subscribers) in boot
method, or use before
silex middleware:
$this->before(function () {
$this['dispatcher']->addListener($eventName, $callback);
});