laravel/framework — pull request #5985 by franzliedke (2014-10-05 22:30:13+00:00)
Title: Change implementation of Container::extend()

I previously called `Container::extend()` nearly useless because calling it was dependent on `bind()` being called in advance.

It turned out, that's not quite true, as instead `extend()` checks whether services have already been instantiated and, if they do, simply applies the closures to the instances.

This means `extend()` would always have to be called in service providers' `boot()` method, though, because you could not sure the extended services exist when extended in `register()`, but the container took care of applying extensions to already instantiated services.

Well, this change makes sure `extend()` works even for services that have not been registered yet, which might be a point of discussion. All previously existing unit tests pass.

To me, this would make `extend()` the preferred solution (over binding a listener to `resolving()`) - it could safely be called in `register()` without any dependence on the order of service providers. Which is nice because `extend()` is more powerful for doing stuff like decorators etc.