fabpot/Silex — pull request #705 by igorw (2013-05-15 19:08:37+00:00)
Title: Make dispatcher lazy, do not trigger its creation on middleware definition

The dispatcher has quite a few dependencies due to all of the subscribers
that are added to it. One of these is the logger, several other services
are affected as well though.

The listener shortcut methods like on(), before(), after(), error() all
force creation of the dispatcher and thus all of its dependencies. This
makes it impossible to have lazy configuration of those services.

The specific issue that triggered this was lazy configuration of the logger,
which simply does not work once you have before() or after().

By using extend(), all of those shortcut calls can delay the creation of
the dispatcher and thus solve the issue. It will add a slight overhead, but
it should be relatively small, since the results of creating a service are
memoized through share().