fabpot/Pimple — pull request #62 by igorw (2013-01-13 20:53:55+00:00)
Title: Introduce two new convenience methods: registerSharedService, extendService

Registering a shared service for a certain class that has certain deps happens very often. I'd consider this the primary use case for pimple. As such, it makes sense to provide some shortcuts to make this easier to use.

`registerSharedService` addresses the common use case of:

$c['foo'] = $c->share(function ($c) {
return new Foo($c['bar']);
});

The shorter version of that is:

$c->registerSharedService('foo', 'Foo', array('bar'));

While not such a common use case, when extending a service, you usually want to re-share and assign it. And the code we have to write for that is clunky and verbose. It would make sense to have a dedicated method that makes things easier.

`extendService` is a shorthand for:

$c['foo'] = $c->share($c->extend('foo', function ($foo, $c) {
$foo->addBar(new Bar());
return $foo;
}));

The new version is:

$c->extendService('foo', function ($foo, $c) {
$foo->addBar(new Bar());
return $foo;
});

I'm open to splitting this PR if one of the proposed additions is controversial.