NEW: Allow “%$” prefix in Injector::get()

Injector::get() looks up services by name. In yaml config it can make
things clearer to prefix service names by %$, which is how they must
be prefixed when referencing nested services within service definitions.

This change means that any other system referencing services will
support an optional prefix without needing to specifically code support
in themselves.
This commit is contained in:
Sam Minnee 2017-06-23 11:15:51 +12:00 committed by Damian Mooyman
parent 0ed1750106
commit 26b9bf11ed

View File

@ -929,6 +929,11 @@ class Injector implements ContainerInterface
*/ */
protected function getNamedService($name, $asSingleton = true, $constructorArgs = []) protected function getNamedService($name, $asSingleton = true, $constructorArgs = [])
{ {
// Allow service names of the form "%$ServiceName"
if (substr($name, 0, 2) == '%$') {
$name = substr($name, 2);
}
// Normalise service / args // Normalise service / args
list($name, $constructorArgs) = $this->normaliseArguments($name, $constructorArgs); list($name, $constructorArgs) = $this->normaliseArguments($name, $constructorArgs);