Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

Silex 2.0 and 'Identifier "dispatcher" does not contain an object definition.' #70

Open
J7mbo opened this issue Sep 5, 2015 · 6 comments

Comments

@J7mbo
Copy link

J7mbo commented Sep 5, 2015

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:

screen shot 2015-09-05 at 18 36 28

screen shot 2015-09-05 at 18 37 10

@xiaohutai
Copy link

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.

@J7mbo
Copy link
Author

J7mbo commented Sep 11, 2015

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.

@kabudu
Copy link

kabudu commented Dec 26, 2015

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.

@quazardous
Copy link

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

@sinasalek
Copy link

Confirm that moving any dispatcher related code like addListener to the end fixes the problem

@alcalyn
Copy link

alcalyn commented Jun 19, 2016

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);
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants