This PR was merged into the 3.3-dev branch. Discussion ---------- Revert "feature #20973 [DI] Add getter injection (nicolas-grekas)" This reverts commit2183f98f54
, reversing changes made tob465634a55
. | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no (master only) | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Let's remove getter injection, we now have enough alternative mechanisms to achieve almost the same results (e.g. `ServiceSubscriberInterface`, see #21708)., and I'm tired being called by names because of it. The only use case in core is `ControllerTrait`, but this should be gone if #22157 is merged. Commits -------23fa3a09bf
Revert "feature #20973 [DI] Add getter injection (nicolas-grekas)"
This commit is contained in:
commit
9896f86743
@ -14,8 +14,6 @@ CHANGELOG
|
||||
* deprecated `ContainerBuilder::getClassResource()`, use `ContainerBuilder::getReflectionClass()` or `ContainerBuilder::addObjectResource()` instead
|
||||
* added `ContainerBuilder::fileExists()` for checking and tracking file or directory existence
|
||||
* deprecated autowiring-types, use aliases instead
|
||||
* [EXPERIMENTAL] added support for getter autowiring
|
||||
* [EXPERIMENTAL] added support for getter-injection
|
||||
* added support for omitting the factory class name in a service definition if the definition class is set
|
||||
* deprecated case insensitivity of service identifiers
|
||||
* added "iterator" argument type for lazy iteration over a set of values and services
|
||||
|
@ -61,7 +61,6 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
} elseif ($value instanceof Definition) {
|
||||
$value->setArguments($this->processValue($value->getArguments()));
|
||||
$value->setProperties($this->processValue($value->getProperties()));
|
||||
$value->setOverriddenGetters($this->processValue($value->getOverriddenGetters()));
|
||||
$value->setMethodCalls($this->processValue($value->getMethodCalls()));
|
||||
|
||||
if ($v = $value->getFactory()) {
|
||||
|
@ -109,9 +109,6 @@ class AnalyzeServiceReferencesPass extends AbstractRecursivePass implements Repe
|
||||
|
||||
if (!$this->onlyConstructorArguments) {
|
||||
$this->processValue($value->getProperties());
|
||||
$this->lazy = true;
|
||||
$this->processValue($value->getOverriddenGetters());
|
||||
$this->lazy = false;
|
||||
$this->processValue($value->getMethodCalls());
|
||||
$this->processValue($value->getConfigurator());
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\Config\AutowireServiceResource;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyHelper;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\TypedReference;
|
||||
|
||||
@ -125,7 +125,6 @@ class AutowirePass extends AbstractRecursivePass
|
||||
}
|
||||
|
||||
$methodCalls = $this->autowireCalls($reflectionClass, $methodCalls, $autowiredMethods);
|
||||
$overriddenGetters = $this->autowireOverridenGetters($value->getOverriddenGetters(), $autowiredMethods);
|
||||
|
||||
if ($constructor) {
|
||||
list(, $arguments) = array_shift($methodCalls);
|
||||
@ -139,10 +138,6 @@ class AutowirePass extends AbstractRecursivePass
|
||||
$value->setMethodCalls($methodCalls);
|
||||
}
|
||||
|
||||
if ($overriddenGetters !== $value->getOverriddenGetters()) {
|
||||
$value->setOverriddenGetters($overriddenGetters);
|
||||
}
|
||||
|
||||
return parent::processValue($value, $isRoot);
|
||||
} finally {
|
||||
$this->currentDefinition = $parentDefinition;
|
||||
@ -165,7 +160,7 @@ class AutowirePass extends AbstractRecursivePass
|
||||
$methodsToAutowire[strtolower($reflectionMethod->name)] = $reflectionMethod;
|
||||
}
|
||||
|
||||
foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $reflectionMethod) {
|
||||
foreach ($reflectionClass->getMethods() as $reflectionMethod) {
|
||||
$r = $reflectionMethod;
|
||||
|
||||
while (true) {
|
||||
@ -224,9 +219,6 @@ class AutowirePass extends AbstractRecursivePass
|
||||
}
|
||||
|
||||
foreach ($autowiredMethods as $lcMethod => $reflectionMethod) {
|
||||
if (!$reflectionMethod->getNumberOfParameters()) {
|
||||
continue; // skip getters
|
||||
}
|
||||
$method = $reflectionMethod->name;
|
||||
|
||||
if (!$reflectionMethod->isPublic()) {
|
||||
@ -270,7 +262,7 @@ class AutowirePass extends AbstractRecursivePass
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = InheritanceProxyHelper::getTypeHint($reflectionMethod, $parameter, true);
|
||||
$type = ProxyHelper::getTypeHint($reflectionMethod, $parameter, true);
|
||||
|
||||
if (!$type) {
|
||||
// no default value? Then fail
|
||||
@ -311,41 +303,6 @@ class AutowirePass extends AbstractRecursivePass
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Autowires getters.
|
||||
*
|
||||
* @param array $overridenGetters
|
||||
* @param array $autowiredMethods
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function autowireOverridenGetters(array $overridenGetters, array $autowiredMethods)
|
||||
{
|
||||
foreach ($autowiredMethods as $lcMethod => $reflectionMethod) {
|
||||
if (isset($overridenGetters[$lcMethod]) || $reflectionMethod->getNumberOfParameters() || $reflectionMethod->isConstructor()) {
|
||||
continue;
|
||||
}
|
||||
$class = $reflectionMethod->class;
|
||||
$method = $reflectionMethod->name;
|
||||
|
||||
if (!$type = InheritanceProxyHelper::getTypeHint($reflectionMethod, null, true)) {
|
||||
$type = InheritanceProxyHelper::getTypeHint($reflectionMethod);
|
||||
|
||||
throw new RuntimeException(sprintf('Cannot autowire service "%s": getter %s() must%s have its return value be configured explicitly.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method, $type ? '' : ' have a return-type hint or'));
|
||||
}
|
||||
|
||||
if (!$typeRef = $this->getAutowiredReference($type)) {
|
||||
$this->container->log($this, $this->createTypeNotFoundMessage($type, sprintf('return value of method %s()', $class !== $this->currentId ? $class.'::'.$method : $method)));
|
||||
continue;
|
||||
}
|
||||
|
||||
$overridenGetters[$lcMethod] = $typeRef;
|
||||
$this->usedTypes[$type] = $this->currentId;
|
||||
}
|
||||
|
||||
return $overridenGetters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Reference|null A reference to the service matching the given type, if any
|
||||
*/
|
||||
|
@ -88,7 +88,6 @@ class ResolveDefinitionTemplatesPass extends AbstractRecursivePass
|
||||
$def->setClass($parentDef->getClass());
|
||||
$def->setArguments($parentDef->getArguments());
|
||||
$def->setMethodCalls($parentDef->getMethodCalls());
|
||||
$def->setOverriddenGetters($parentDef->getOverriddenGetters());
|
||||
$def->setProperties($parentDef->getProperties());
|
||||
if ($parentDef->getAutowiringTypes(false)) {
|
||||
$def->setAutowiringTypes($parentDef->getAutowiringTypes(false));
|
||||
@ -183,10 +182,5 @@ class ResolveDefinitionTemplatesPass extends AbstractRecursivePass
|
||||
if ($calls = $definition->getMethodCalls()) {
|
||||
$def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
|
||||
}
|
||||
|
||||
// merge overridden getters
|
||||
foreach ($definition->getOverriddenGetters() as $k => $v) {
|
||||
$def->setOverriddenGetter($k, $v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,6 @@ class ResolveInvalidReferencesPass implements CompilerPassInterface
|
||||
}
|
||||
$value->setArguments($this->processValue($value->getArguments(), 0));
|
||||
$value->setProperties($this->processValue($value->getProperties(), 1));
|
||||
$value->setOverriddenGetters($this->processValue($value->getOverriddenGetters(), 1));
|
||||
$value->setMethodCalls($this->processValue($value->getMethodCalls(), 2));
|
||||
} elseif (is_array($value)) {
|
||||
$i = 0;
|
||||
|
@ -42,7 +42,6 @@ class ResolveReferencesToAliasesPass implements CompilerPassInterface
|
||||
|
||||
$definition->setArguments($this->processArguments($definition->getArguments()));
|
||||
$definition->setMethodCalls($this->processArguments($definition->getMethodCalls()));
|
||||
$definition->setOverriddenGetters($this->processArguments($definition->getOverriddenGetters()));
|
||||
$definition->setProperties($this->processArguments($definition->getProperties()));
|
||||
$definition->setFactory($this->processFactory($definition->getFactory()));
|
||||
}
|
||||
|
@ -37,8 +37,6 @@ use Symfony\Component\Config\Resource\ReflectionClassResource;
|
||||
use Symfony\Component\Config\Resource\ResourceInterface;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\InstantiatorInterface;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyHelper;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyInterface;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\ExpressionLanguage\Expression;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||
@ -1042,9 +1040,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
$arguments = $this->resolveServices($parameterBag->unescapeValue($parameterBag->resolveValue($definition->getArguments())));
|
||||
|
||||
if (null !== $factory = $definition->getFactory()) {
|
||||
if ($definition->getOverriddenGetters()) {
|
||||
throw new RuntimeException(sprintf('Cannot create service "%s": factories and overridden getters are incompatible with each other.', $id));
|
||||
}
|
||||
if (is_array($factory)) {
|
||||
$factory = array($this->resolveServices($parameterBag->resolveValue($factory[0])), $factory[1]);
|
||||
} elseif (!is_string($factory)) {
|
||||
@ -1063,31 +1058,11 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
} else {
|
||||
$r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass()));
|
||||
|
||||
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
|
||||
|
||||
if (!$definition->isDeprecated() && 0 < strpos($r->getDocComment(), "\n * @deprecated ")) {
|
||||
@trigger_error(sprintf('The "%s" service relies on the deprecated "%s" class. It should either be deprecated or its implementation upgraded.', $id, $r->name), E_USER_DEPRECATED);
|
||||
}
|
||||
if ($definition->getOverriddenGetters()) {
|
||||
static $salt;
|
||||
if (null === $salt) {
|
||||
$salt = str_replace('.', '', uniqid('', true));
|
||||
}
|
||||
$service = sprintf('%s implements \\%s { private $container%4$s; private $getters%4$s; %s }', $r->name, InheritanceProxyInterface::class, $this->generateOverriddenMethods($id, $definition, $r, $salt), $salt);
|
||||
if (!class_exists($proxyClass = 'SymfonyProxy_'.md5($service), false)) {
|
||||
eval(sprintf('class %s extends %s', $proxyClass, $service));
|
||||
}
|
||||
$r = new \ReflectionClass($proxyClass);
|
||||
$constructor = $r->getConstructor();
|
||||
if ($constructor && !defined('HHVM_VERSION') && $constructor->getDeclaringClass()->isInternal()) {
|
||||
$constructor = null;
|
||||
}
|
||||
$service = $constructor ? $r->newInstanceWithoutConstructor() : $r->newInstanceArgs($arguments);
|
||||
call_user_func(\Closure::bind(function ($c, $g, $s) { $this->{'container'.$s} = $c; $this->{'getters'.$s} = $g; }, $service, $service), $this, $definition->getOverriddenGetters(), $salt);
|
||||
if ($constructor) {
|
||||
$constructor->invokeArgs($service, $arguments);
|
||||
}
|
||||
} else {
|
||||
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
|
||||
}
|
||||
}
|
||||
|
||||
if ($tryProxy || !$definition->isLazy()) {
|
||||
@ -1348,44 +1323,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
return $this->envCounters;
|
||||
}
|
||||
|
||||
private function generateOverriddenMethods($id, Definition $definition, \ReflectionClass $class, $salt)
|
||||
{
|
||||
if ($class->isFinal()) {
|
||||
throw new RuntimeException(sprintf('Unable to configure service "%s": class "%s" cannot be marked as final.', $id, $class->name));
|
||||
}
|
||||
|
||||
return $this->generateOverriddenGetters($id, $definition, $class, $salt);
|
||||
}
|
||||
|
||||
private function generateOverriddenGetters($id, Definition $definition, \ReflectionClass $class, $salt)
|
||||
{
|
||||
$getters = '';
|
||||
|
||||
foreach ($definition->getOverriddenGetters() as $name => $returnValue) {
|
||||
$r = InheritanceProxyHelper::getGetterReflector($class, $name, $id);
|
||||
$signature = InheritanceProxyHelper::getSignature($r);
|
||||
$visibility = $r->isProtected() ? 'protected' : 'public';
|
||||
$getters .= <<<EOF
|
||||
|
||||
{$visibility} function {$signature} {
|
||||
\$c = \$this->container{$salt};
|
||||
\$b = \$c->getParameterBag();
|
||||
\$v = \$this->getters{$salt}['{$name}'];
|
||||
|
||||
foreach (\$c->getServiceConditionals(\$v) as \$s) {
|
||||
if (!\$c->has(\$s)) {
|
||||
return parent::{$r->name}();
|
||||
}
|
||||
}
|
||||
|
||||
return \$c->resolveServices(\$b->unescapeValue(\$b->resolveValue(\$v)));
|
||||
}
|
||||
EOF;
|
||||
}
|
||||
|
||||
return $getters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
|
@ -29,7 +29,6 @@ class Definition
|
||||
private $deprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.';
|
||||
private $properties = array();
|
||||
private $calls = array();
|
||||
private $getters = array();
|
||||
private $instanceof = array();
|
||||
private $configurator;
|
||||
private $tags = array();
|
||||
@ -329,41 +328,6 @@ class Definition
|
||||
return $this->calls;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*
|
||||
* @experimental in version 3.3
|
||||
*/
|
||||
public function setOverriddenGetter($name, $returnValue)
|
||||
{
|
||||
if (!$name) {
|
||||
throw new InvalidArgumentException(sprintf('Getter name cannot be empty.'));
|
||||
}
|
||||
$this->getters[strtolower($name)] = $returnValue;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*
|
||||
* @experimental in version 3.3
|
||||
*/
|
||||
public function setOverriddenGetters(array $getters)
|
||||
{
|
||||
$this->getters = array_change_key_case($getters, CASE_LOWER);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @experimental in version 3.3
|
||||
*/
|
||||
public function getOverriddenGetters()
|
||||
{
|
||||
return $this->getters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the definition templates to conditionally apply on the current definition, keyed by parent interface/class.
|
||||
*
|
||||
|
@ -80,13 +80,6 @@ class GraphvizDumper extends Dumper
|
||||
$this->findEdges($id, $call[1], false, $call[0].'()')
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($definition->getOverriddenGetters() as $name => $value) {
|
||||
$this->edges[$id] = array_merge(
|
||||
$this->edges[$id],
|
||||
$this->findEdges($id, $value, false, $name.'()')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->container->resolveEnvPlaceholders($this->startDot().$this->addNodes().$this->addEdges().$this->endDot(), '__ENV_%s__');
|
||||
|
@ -27,8 +27,7 @@ use Symfony\Component\DependencyInjection\Exception\EnvParameterException;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyHelper;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyInterface;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface as ProxyDumper;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\NullDumper;
|
||||
use Symfony\Component\DependencyInjection\ExpressionLanguage;
|
||||
@ -69,9 +68,6 @@ class PhpDumper extends Dumper
|
||||
private $serviceIdToMethodNameMap;
|
||||
private $usedMethodNames;
|
||||
private $baseClass;
|
||||
private $inheritanceProxies = array();
|
||||
private $useInstantiateProxy;
|
||||
private $salt;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface
|
||||
@ -127,9 +123,7 @@ class PhpDumper extends Dumper
|
||||
'debug' => true,
|
||||
), $options);
|
||||
|
||||
$this->salt = substr(strtr(base64_encode(md5($options['namespace'].'\\'.$options['class'].'+'.$options['base_class'], true)), '+/', '__'), 0, -2);
|
||||
$this->inheritanceProxies = array();
|
||||
$this->useInstantiateProxy = false;
|
||||
$this->classResources = array();
|
||||
$this->initializeMethodNamesMap($options['base_class']);
|
||||
$this->baseClass = $options['base_class'];
|
||||
|
||||
@ -177,7 +171,6 @@ class PhpDumper extends Dumper
|
||||
$this->addProxyClasses()
|
||||
;
|
||||
$this->targetDirRegex = null;
|
||||
$this->inheritanceProxies = array();
|
||||
|
||||
$unusedEnvs = array();
|
||||
foreach ($this->container->getEnvCounters() as $env => $use) {
|
||||
@ -281,10 +274,6 @@ class PhpDumper extends Dumper
|
||||
$code .= $proxyCode;
|
||||
}
|
||||
|
||||
foreach ($this->inheritanceProxies as $proxyClass => $proxyCode) {
|
||||
$code .= sprintf("\nclass %s extends %s", $proxyClass, $proxyCode);
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
@ -498,83 +487,6 @@ class PhpDumper extends Dumper
|
||||
return $calls;
|
||||
}
|
||||
|
||||
private function addServiceOverriddenMethods($id, Definition $definition)
|
||||
{
|
||||
$class = $this->container->getReflectionClass($definition->getClass());
|
||||
|
||||
if (!$class) {
|
||||
throw new RuntimeException(sprintf('Unable to configure service "%s": class "%s" not found.', $id, $definition->getClass()));
|
||||
}
|
||||
|
||||
if ($class->isFinal()) {
|
||||
throw new RuntimeException(sprintf('Unable to configure service "%s": class "%s" cannot be marked as final.', $id, $class->name));
|
||||
}
|
||||
|
||||
if ($r = $class->getConstructor()) {
|
||||
if ($r->isAbstract()) {
|
||||
throw new RuntimeException(sprintf('Unable to configure service "%s": the constructor of the "%s" class cannot be abstract.', $id, $class->name));
|
||||
}
|
||||
if (!$r->isPublic()) {
|
||||
throw new RuntimeException(sprintf('Unable to configure service "%s": the constructor of the "%s" class must be public.', $id, $class->name));
|
||||
}
|
||||
if (!$r->isFinal()) {
|
||||
if (0 < $r->getNumberOfParameters()) {
|
||||
$constructor = implode('($container'.$this->salt.', ', explode('(', InheritanceProxyHelper::getSignature($r, $call), 2));
|
||||
} else {
|
||||
$constructor = $r->name.'($container'.$this->salt.')';
|
||||
$call = $r->name.'()';
|
||||
}
|
||||
$constructor = sprintf("\n public function %s\n {\n \$this->container%3\$s = \$container%3\$s;\n parent::%s;\n }\n", $constructor, $call, $this->salt);
|
||||
} else {
|
||||
$constructor = '';
|
||||
}
|
||||
} else {
|
||||
$constructor = sprintf("\n public function __construct(\$container%1\$s)\n {\n \$this->container%1\$s = \$container%1\$s;\n }\n", $this->salt);
|
||||
}
|
||||
|
||||
return $constructor.$this->addServiceOverriddenGetters($id, $definition, $class);
|
||||
}
|
||||
|
||||
private function addServiceOverriddenGetters($id, Definition $definition, \ReflectionClass $class)
|
||||
{
|
||||
$getters = '';
|
||||
|
||||
foreach ($definition->getOverriddenGetters() as $name => $returnValue) {
|
||||
$r = InheritanceProxyHelper::getGetterReflector($class, $name, $id);
|
||||
|
||||
$getter = array();
|
||||
$getter[] = sprintf('%s function %s', $r->isProtected() ? 'protected' : 'public', InheritanceProxyHelper::getSignature($r));
|
||||
$getter[] = '{';
|
||||
|
||||
if (false === strpos($dumpedReturnValue = $this->dumpValue($returnValue), '$this')) {
|
||||
$getter[] = sprintf(' return %s;', $dumpedReturnValue);
|
||||
} else {
|
||||
$getter[] = sprintf(' if (null === $g = &$this->getters%s[__FUNCTION__]) {', $this->salt);
|
||||
$getter[] = sprintf(' $g = \Closure::bind(function () { return %s; }, %2$s, %2$s);', $dumpedReturnValue, '$this->container'.$this->salt);
|
||||
$getter[] = ' }';
|
||||
$getter[] = '';
|
||||
foreach (explode("\n", $this->wrapServiceConditionals($returnValue, " return \$g();\n", $isUnconditional, '$this->container'.$this->salt)) as $code) {
|
||||
if ($code) {
|
||||
$getter[] = substr($code, 4);
|
||||
}
|
||||
}
|
||||
if (!$isUnconditional) {
|
||||
$getter[] = '';
|
||||
$getter[] = sprintf(' return parent::%s();', $r->name);
|
||||
}
|
||||
}
|
||||
|
||||
$getter[] = '}';
|
||||
$getter[] = '';
|
||||
|
||||
foreach ($getter as $code) {
|
||||
$getters .= $code ? "\n ".$code : "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $getters;
|
||||
}
|
||||
|
||||
private function addServiceProperties($id, Definition $definition, $variableName = 'instance')
|
||||
{
|
||||
$code = '';
|
||||
@ -820,9 +732,6 @@ EOF;
|
||||
}
|
||||
|
||||
if (null !== $definition->getFactory()) {
|
||||
if ($definition->getOverriddenGetters()) {
|
||||
throw new RuntimeException(sprintf('Cannot dump definition for service "%s": factories and overridden getters are incompatible with each other.', $id));
|
||||
}
|
||||
$callable = $definition->getFactory();
|
||||
if (is_array($callable)) {
|
||||
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $callable[1])) {
|
||||
@ -855,31 +764,10 @@ EOF;
|
||||
}
|
||||
|
||||
if (false !== strpos($class, '$')) {
|
||||
if ($definition->getOverriddenGetters()) {
|
||||
throw new RuntimeException(sprintf('Cannot dump definition for service "%s": dynamic class names and overridden getters are incompatible with each other.', $id));
|
||||
}
|
||||
|
||||
return sprintf(" \$class = %s;\n\n $return{$instantiation}new \$class(%s);\n", $class, implode(', ', $arguments));
|
||||
}
|
||||
$class = $this->dumpLiteralClass($class);
|
||||
|
||||
if ($definition->getOverriddenGetters()) {
|
||||
$inheritanceProxy = " private \$container{$this->salt};\n private \$getters{$this->salt};\n";
|
||||
$inheritanceProxy = sprintf("%s implements \\%s\n{\n%s%s}\n", $class, InheritanceProxyInterface::class, $inheritanceProxy, $this->addServiceOverriddenMethods($id, $definition));
|
||||
$class = 'SymfonyProxy_'.md5($inheritanceProxy);
|
||||
$this->inheritanceProxies[$class] = $inheritanceProxy;
|
||||
$constructor = $this->container->getReflectionClass($definition->getClass())->getConstructor();
|
||||
|
||||
if ($constructor && $constructor->isFinal()) {
|
||||
$this->useInstantiateProxy = true;
|
||||
$useConstructor = $constructor->getDeclaringClass()->isInternal() ? "defined('HHVM_VERSION')" : 'true';
|
||||
|
||||
return sprintf(" $return{$instantiation}\$this->instantiateProxy(%s::class, array(%s), %s);\n", $class, implode(', ', $arguments), $useConstructor);
|
||||
}
|
||||
array_unshift($arguments, '$this');
|
||||
}
|
||||
|
||||
return sprintf(" $return{$instantiation}new %s(%s);\n", $class, implode(', ', $arguments));
|
||||
return sprintf(" $return{$instantiation}new %s(%s);\n", $this->dumpLiteralClass($class), implode(', ', $arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1329,34 +1217,6 @@ EOF;
|
||||
*/
|
||||
private function endClass()
|
||||
{
|
||||
if ($this->useInstantiateProxy) {
|
||||
return sprintf(<<<'EOF'
|
||||
|
||||
private function instantiateProxy($class, $args, $useConstructor)
|
||||
{
|
||||
static $reflectionCache;
|
||||
|
||||
if (null === $r = &$reflectionCache[$class]) {
|
||||
$r[0] = new \ReflectionClass($class);
|
||||
$r[1] = $r[0]->getProperty('container%s');
|
||||
$r[1]->setAccessible(true);
|
||||
$r[2] = $r[0]->getConstructor();
|
||||
}
|
||||
$service = $useConstructor ? $r[0]->newInstanceWithoutConstructor() : $r[0]->newInstanceArgs($args);
|
||||
$r[1]->setValue($service, $this);
|
||||
if ($r[2] && $useConstructor) {
|
||||
$r[2]->invokeArgs($service, $args);
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
}
|
||||
|
||||
EOF
|
||||
, $this->salt
|
||||
);
|
||||
}
|
||||
|
||||
return <<<'EOF'
|
||||
}
|
||||
|
||||
@ -1368,14 +1228,12 @@ EOF;
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $code
|
||||
* @param bool &$isUnconditional
|
||||
* @param string $containerRef
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function wrapServiceConditionals($value, $code, &$isUnconditional = null, $containerRef = '$this')
|
||||
private function wrapServiceConditionals($value, $code)
|
||||
{
|
||||
if ($isUnconditional = !$condition = $this->getServiceConditionals($value, $containerRef)) {
|
||||
if (!$condition = $this->getServiceConditionals($value)) {
|
||||
return $code;
|
||||
}
|
||||
|
||||
@ -1389,11 +1247,10 @@ EOF;
|
||||
* Get the conditions to execute for conditional services.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $containerRef
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
private function getServiceConditionals($value, $containerRef = '$this')
|
||||
private function getServiceConditionals($value)
|
||||
{
|
||||
if (!$services = ContainerBuilder::getServiceConditionals($value)) {
|
||||
return null;
|
||||
@ -1401,7 +1258,7 @@ EOF;
|
||||
|
||||
$conditions = array();
|
||||
foreach ($services as $service) {
|
||||
$conditions[] = sprintf("%s->has('%s')", $containerRef, $service);
|
||||
$conditions[] = sprintf("\$this->has('%s')", $service);
|
||||
}
|
||||
|
||||
return implode(' && ', $conditions);
|
||||
@ -1449,7 +1306,6 @@ EOF;
|
||||
$definitions = array_merge(
|
||||
$this->getDefinitionsFromArguments($definition->getArguments()),
|
||||
$this->getDefinitionsFromArguments($definition->getMethodCalls()),
|
||||
$this->getDefinitionsFromArguments($definition->getOverriddenGetters()),
|
||||
$this->getDefinitionsFromArguments($definition->getProperties()),
|
||||
$this->getDefinitionsFromArguments(array($definition->getConfigurator())),
|
||||
$this->getDefinitionsFromArguments(array($definition->getFactory()))
|
||||
@ -1596,9 +1452,6 @@ EOF;
|
||||
if ($value->getMethodCalls()) {
|
||||
throw new RuntimeException('Cannot dump definitions which have method calls.');
|
||||
}
|
||||
if ($value->getOverriddenGetters()) {
|
||||
throw new RuntimeException('Cannot dump definitions which have overridden getters.');
|
||||
}
|
||||
if (null !== $value->getConfigurator()) {
|
||||
throw new RuntimeException('Cannot dump definitions which have a configurator.');
|
||||
}
|
||||
@ -1663,9 +1516,9 @@ EOF;
|
||||
if (!$r->isPublic()) {
|
||||
throw new InvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" must be public.', $reference, $class, $method));
|
||||
}
|
||||
$signature = preg_replace('/^(&?)[^(]*/', '$1', InheritanceProxyHelper::getSignature($r, $call));
|
||||
$signature = preg_replace('/^(&?)[^(]*/', '$1', ProxyHelper::getSignature($r, $call));
|
||||
|
||||
$return = 'void' !== InheritanceProxyHelper::getTypeHint($r);
|
||||
$return = 'void' !== ProxyHelper::getTypeHint($r);
|
||||
|
||||
return sprintf("/** @closure-proxy %s::%s */ function %s {\n %s%s->%s;\n }", $class, $method, $signature, $return ? 'return ' : '', $this->dumpValue($reference), $call);
|
||||
} elseif ($value instanceof Variable) {
|
||||
|
@ -168,10 +168,6 @@ class XmlDumper extends Dumper
|
||||
$this->convertParameters($parameters, 'property', $service, 'name');
|
||||
}
|
||||
|
||||
if ($parameters = $definition->getOverriddenGetters()) {
|
||||
$this->convertParameters($parameters, 'getter', $service, 'name');
|
||||
}
|
||||
|
||||
$this->addMethodCalls($definition->getMethodCalls(), $service);
|
||||
|
||||
if ($callable = $definition->getFactory()) {
|
||||
|
@ -129,10 +129,6 @@ class YamlDumper extends Dumper
|
||||
$code .= sprintf(" properties: %s\n", $this->dumper->dump($this->dumpValue($definition->getProperties()), 0));
|
||||
}
|
||||
|
||||
if ($definition->getOverriddenGetters()) {
|
||||
$code .= sprintf(" getters:\n%s\n", $this->dumper->dump($this->dumpValue($definition->getOverriddenGetters()), 0));
|
||||
}
|
||||
|
||||
if ($definition->getMethodCalls()) {
|
||||
$code .= sprintf(" calls:\n%s\n", $this->dumper->dump($this->dumpValue($definition->getMethodCalls()), 1, 12));
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\LazyProxy;
|
||||
|
||||
/**
|
||||
* Interface used to label proxy classes with overridden methods as generated while compiling the container.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @experimental in version 3.3
|
||||
*/
|
||||
interface InheritanceProxyInterface
|
||||
{
|
||||
}
|
@ -11,40 +11,13 @@
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\LazyProxy;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class InheritanceProxyHelper
|
||||
class ProxyHelper
|
||||
{
|
||||
public static function getGetterReflector(\ReflectionClass $class, $name, $id)
|
||||
{
|
||||
if (!$class->hasMethod($name)) {
|
||||
throw new RuntimeException(sprintf('Unable to configure getter injection for service "%s": method "%s::%s" does not exist.', $id, $class->name, $name));
|
||||
}
|
||||
$r = $class->getMethod($name);
|
||||
if ($r->isPrivate()) {
|
||||
throw new RuntimeException(sprintf('Unable to configure getter injection for service "%s": method "%s::%s" must be public or protected.', $id, $class->name, $r->name));
|
||||
}
|
||||
if ($r->isStatic()) {
|
||||
throw new RuntimeException(sprintf('Unable to configure getter injection for service "%s": method "%s::%s" cannot be static.', $id, $class->name, $r->name));
|
||||
}
|
||||
if ($r->isFinal()) {
|
||||
throw new RuntimeException(sprintf('Unable to configure getter injection for service "%s": method "%s::%s" cannot be marked as final.', $id, $class->name, $r->name));
|
||||
}
|
||||
if ($r->returnsReference()) {
|
||||
throw new RuntimeException(sprintf('Unable to configure getter injection for service "%s": method "%s::%s" cannot return by reference.', $id, $class->name, $r->name));
|
||||
}
|
||||
if (0 < $r->getNumberOfParameters()) {
|
||||
throw new RuntimeException(sprintf('Unable to configure getter injection for service "%s": method "%s::%s" cannot have any arguments.', $id, $class->name, $r->name));
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string The signature of the passed function, return type and function/method name included if any
|
||||
*/
|
@ -253,7 +253,6 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
$definition->setArguments($this->getArgumentsAsPhp($service, 'argument', false, $definition instanceof ChildDefinition));
|
||||
$definition->setProperties($this->getArgumentsAsPhp($service, 'property'));
|
||||
$definition->setOverriddenGetters($this->getArgumentsAsPhp($service, 'getter'));
|
||||
|
||||
if ($factories = $this->getChildren($service, 'factory')) {
|
||||
$factory = $factories[0];
|
||||
@ -380,7 +379,7 @@ class XmlFileLoader extends FileLoader
|
||||
$xpath->registerNamespace('container', self::NS);
|
||||
|
||||
// anonymous services as arguments/properties
|
||||
if (false !== $nodes = $xpath->query('//container:argument[@type="service"][not(@id)]|//container:property[@type="service"][not(@id)]|//container:getter[@type="service"][not(@id)]')) {
|
||||
if (false !== $nodes = $xpath->query('//container:argument[@type="service"][not(@id)]|//container:property[@type="service"][not(@id)]')) {
|
||||
foreach ($nodes as $node) {
|
||||
// give it a unique name
|
||||
$id = sprintf('%d_%s', ++$count, hash('sha256', $file));
|
||||
|
@ -48,7 +48,6 @@ class YamlFileLoader extends FileLoader
|
||||
'file' => 'file',
|
||||
'arguments' => 'arguments',
|
||||
'properties' => 'properties',
|
||||
'getters' => 'getters',
|
||||
'configurator' => 'configurator',
|
||||
'calls' => 'calls',
|
||||
'tags' => 'tags',
|
||||
@ -71,7 +70,6 @@ class YamlFileLoader extends FileLoader
|
||||
'factory' => 'factory',
|
||||
'arguments' => 'arguments',
|
||||
'properties' => 'properties',
|
||||
'getters' => 'getters',
|
||||
'configurator' => 'configurator',
|
||||
'calls' => 'calls',
|
||||
'tags' => 'tags',
|
||||
@ -88,7 +86,6 @@ class YamlFileLoader extends FileLoader
|
||||
'factory' => 'factory',
|
||||
'arguments' => 'arguments',
|
||||
'properties' => 'properties',
|
||||
'getters' => 'getters',
|
||||
'configurator' => 'configurator',
|
||||
'calls' => 'calls',
|
||||
'tags' => 'tags',
|
||||
@ -427,10 +424,6 @@ class YamlFileLoader extends FileLoader
|
||||
$definition->setConfigurator($this->parseCallable($service['configurator'], 'configurator', $id, $file));
|
||||
}
|
||||
|
||||
if (isset($service['getters'])) {
|
||||
$definition->setOverriddenGetters($this->resolveServices($service['getters'], $file));
|
||||
}
|
||||
|
||||
if (isset($service['calls'])) {
|
||||
if (!is_array($service['calls'])) {
|
||||
throw new InvalidArgumentException(sprintf('Parameter "calls" must be an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
|
||||
|
@ -116,7 +116,6 @@
|
||||
<xsd:element name="call" type="call" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="tag" type="tag" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="getter" type="getter" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="autowiring-type" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="id" type="xsd:string" />
|
||||
@ -144,7 +143,6 @@
|
||||
<xsd:element name="call" type="call" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="tag" type="tag" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="getter" type="getter" minOccurs="0" maxOccurs="unbounded" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="id" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="shared" type="boolean" />
|
||||
@ -163,7 +161,6 @@
|
||||
<xsd:element name="call" type="call" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="tag" type="tag" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="getter" type="getter" minOccurs="0" maxOccurs="unbounded" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="namespace" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="resource" type="xsd:string" use="required" />
|
||||
@ -212,18 +209,6 @@
|
||||
<xsd:attribute name="strict" type="boolean" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="getter" mixed="true">
|
||||
<xsd:choice minOccurs="0" maxOccurs="1">
|
||||
<xsd:element name="getter" type="getter" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="service" type="service" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="type" type="argument_type" />
|
||||
<xsd:attribute name="id" type="xsd:string" />
|
||||
<xsd:attribute name="key" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="on-invalid" type="invalid_sequence" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="argument" mixed="true">
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="argument" type="argument" minOccurs="0" maxOccurs="unbounded" />
|
||||
|
@ -17,7 +17,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\FooVariadic;
|
||||
use Symfony\Component\DependencyInjection\Tests\Fixtures\GetterOverriding;
|
||||
use Symfony\Component\DependencyInjection\TypedReference;
|
||||
|
||||
/**
|
||||
@ -535,51 +534,6 @@ class AutowirePassTest extends TestCase
|
||||
$this->assertSame(A::class, $container->getDefinition('autowired.'.A::class)->getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.1
|
||||
*/
|
||||
public function testGetterOverriding()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('b', B::class);
|
||||
|
||||
$container
|
||||
->register('getter_overriding', GetterOverriding::class)
|
||||
->setOverriddenGetter('getExplicitlyDefined', new Reference('b'))
|
||||
->setAutowired(true)
|
||||
;
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
|
||||
$overridenGetters = $container->getDefinition('getter_overriding')->getOverriddenGetters();
|
||||
$this->assertEquals(array(
|
||||
'getexplicitlydefined' => new Reference('b'),
|
||||
'getfoo' => new Reference('autowired.Symfony\Component\DependencyInjection\Tests\Compiler\Foo'),
|
||||
'getbar' => new Reference('autowired.Symfony\Component\DependencyInjection\Tests\Compiler\Bar'),
|
||||
), $overridenGetters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.1
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Cannot autowire service "getter_overriding": multiple candidate services exist for class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo". This type-hint could be aliased to one of these existing services: "a1", "a2".
|
||||
*/
|
||||
public function testGetterOverridingWithAmbiguousServices()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->register('a1', Foo::class);
|
||||
$container->register('a2', Foo::class);
|
||||
|
||||
$container
|
||||
->register('getter_overriding', GetterOverriding::class)
|
||||
->setAutowired(true)
|
||||
;
|
||||
|
||||
$pass = new AutowirePass();
|
||||
$pass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getCreateResourceTests
|
||||
* @group legacy
|
||||
|
@ -109,19 +109,6 @@ class ResolveInvalidReferencesPassTest extends TestCase
|
||||
$this->assertEquals(array(), $def->getProperties());
|
||||
}
|
||||
|
||||
public function testProcessRemovesOverriddenGettersOnInvalid()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$def = $container
|
||||
->register('foo')
|
||||
->setOverriddenGetter('foo', new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEquals(array(), $def->getOverriddenGetters());
|
||||
}
|
||||
|
||||
public function testProcessRemovesArgumentsOnInvalid()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -905,65 +905,6 @@ class ContainerBuilderTest extends TestCase
|
||||
$this->assertEquals(array($second, $first), $configs);
|
||||
}
|
||||
|
||||
public function testOverriddenGetter()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
$builder
|
||||
->register('foo', 'ReflectionClass')
|
||||
->addArgument('stdClass')
|
||||
->setOverriddenGetter('getName', 'bar');
|
||||
|
||||
$foo = $builder->get('foo');
|
||||
|
||||
$this->assertInstanceOf('ReflectionClass', $foo);
|
||||
$this->assertSame('bar', $foo->getName());
|
||||
}
|
||||
|
||||
public function testOverriddenGetterOnInvalid()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
$builder
|
||||
->register('foo', 'ReflectionClass')
|
||||
->addArgument('stdClass')
|
||||
->setOverriddenGetter('getName', new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE));
|
||||
|
||||
$foo = $builder->get('foo');
|
||||
|
||||
$this->assertInstanceOf('ReflectionClass', $foo);
|
||||
$this->assertSame('stdClass', $foo->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideBadOverridenGetters
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
*/
|
||||
public function testBadOverridenGetters($expectedMessage, $getter, $id = 'foo')
|
||||
{
|
||||
$container = include __DIR__.'/Fixtures/containers/container30.php';
|
||||
$container->getDefinition($id)->setOverriddenGetter($getter, 123);
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessage($expectedMessage);
|
||||
} else {
|
||||
$this->setExpectedException(RuntimeException::class, $expectedMessage);
|
||||
}
|
||||
|
||||
$container->get($id);
|
||||
}
|
||||
|
||||
public function provideBadOverridenGetters()
|
||||
{
|
||||
yield array('Unable to configure getter injection for service "foo": method "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Foo::getnotfound" does not exist.', 'getNotFound');
|
||||
yield array('Unable to configure getter injection for service "foo": method "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Foo::getPrivate" must be public or protected.', 'getPrivate');
|
||||
yield array('Unable to configure getter injection for service "foo": method "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Foo::getStatic" cannot be static.', 'getStatic');
|
||||
yield array('Unable to configure getter injection for service "foo": method "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Foo::getFinal" cannot be marked as final.', 'getFinal');
|
||||
yield array('Unable to configure getter injection for service "foo": method "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Foo::getRef" cannot return by reference.', 'getRef');
|
||||
yield array('Unable to configure getter injection for service "foo": method "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Foo::getParam" cannot have any arguments.', 'getParam');
|
||||
yield array('Unable to configure service "bar": class "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Bar" cannot be marked as final.', 'getParam', 'bar');
|
||||
yield array('Cannot create service "baz": factories and overridden getters are incompatible with each other.', 'getParam', 'baz');
|
||||
}
|
||||
|
||||
public function testAbstractAlias()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -23,7 +23,6 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\TypedReference;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||
use Symfony\Component\DependencyInjection\Variable;
|
||||
@ -320,110 +319,6 @@ class PhpDumperTest extends TestCase
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services24.php', $dumper->dump());
|
||||
}
|
||||
|
||||
public function testDumpOverridenGetters()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container29.php';
|
||||
$container->compile();
|
||||
$container->getDefinition('foo')
|
||||
->setOverriddenGetter('getInvalid', array(new Reference('bar', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE)));
|
||||
$dumper = new PhpDumper($container);
|
||||
|
||||
$dump = $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Overriden_Getters'));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services29.php', $dump);
|
||||
$res = $container->getResources();
|
||||
$this->assertSame('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Container29\Foo', (string) array_pop($res));
|
||||
|
||||
eval('?>'.$dump);
|
||||
|
||||
$container = new \Symfony_DI_PhpDumper_Test_Overriden_Getters();
|
||||
|
||||
$foo = $container->get('foo');
|
||||
|
||||
$this->assertSame('public', $foo->getPublic());
|
||||
$this->assertSame('protected', $foo->getGetProtected());
|
||||
$this->assertSame($foo, $foo->getSelf());
|
||||
$this->assertSame(456, $foo->getInvalid());
|
||||
|
||||
$baz = $container->get('baz');
|
||||
$r = new \ReflectionMethod($baz, 'getBaz');
|
||||
$r->setAccessible(true);
|
||||
|
||||
$this->assertTrue($r->isProtected());
|
||||
$this->assertSame('baz', $r->invoke($baz));
|
||||
}
|
||||
|
||||
public function testDumpOverridenGettersWithConstructor()
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container_dump_overriden_getters_with_constructor.php';
|
||||
$container->compile();
|
||||
$container->getDefinition('foo')
|
||||
->setOverriddenGetter('getInvalid', array(new Reference('bar', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE)));
|
||||
$dumper = new PhpDumper($container);
|
||||
|
||||
$dump = $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Overriden_Getters_With_Constructor'));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_dump_overriden_getters_with_constructor.php', $dump);
|
||||
$res = $container->getResources();
|
||||
$this->assertSame('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Container34\Foo', (string) array_pop($res));
|
||||
|
||||
$baz = $container->get('baz');
|
||||
$r = new \ReflectionMethod($baz, 'getBaz');
|
||||
$r->setAccessible(true);
|
||||
|
||||
$this->assertTrue($r->isProtected());
|
||||
$this->assertSame('baz', $r->invoke($baz));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideBadOverridenGetters
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
*/
|
||||
public function testBadOverridenGetters($expectedMessage, $getter, $id = 'foo')
|
||||
{
|
||||
$container = include self::$fixturesPath.'/containers/container30.php';
|
||||
$container->getDefinition($id)->setOverriddenGetter($getter, 123);
|
||||
|
||||
$container->compile();
|
||||
$dumper = new PhpDumper($container);
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessage($expectedMessage);
|
||||
} else {
|
||||
$this->setExpectedException(RuntimeException::class, $expectedMessage);
|
||||
}
|
||||
|
||||
$dumper->dump();
|
||||
}
|
||||
|
||||
public function provideBadOverridenGetters()
|
||||
{
|
||||
yield array('Unable to configure getter injection for service "foo": method "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Foo::getnotfound" does not exist.', 'getNotFound');
|
||||
yield array('Unable to configure getter injection for service "foo": method "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Foo::getPrivate" must be public or protected.', 'getPrivate');
|
||||
yield array('Unable to configure getter injection for service "foo": method "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Foo::getStatic" cannot be static.', 'getStatic');
|
||||
yield array('Unable to configure getter injection for service "foo": method "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Foo::getFinal" cannot be marked as final.', 'getFinal');
|
||||
yield array('Unable to configure getter injection for service "foo": method "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Foo::getRef" cannot return by reference.', 'getRef');
|
||||
yield array('Unable to configure getter injection for service "foo": method "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Foo::getParam" cannot have any arguments.', 'getParam');
|
||||
yield array('Unable to configure service "bar": class "Symfony\Component\DependencyInjection\Tests\Fixtures\Container30\Bar" cannot be marked as final.', 'getParam', 'bar');
|
||||
yield array('Cannot dump definition for service "baz": factories and overridden getters are incompatible with each other.', 'getParam', 'baz');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage Unable to configure service "Acme\FooNonExistent": class "Acme\FooNonExistent" not found.
|
||||
*/
|
||||
public function testDumpOverriddenGetterOnNonExistentClassTriggersException()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$definition = $container->register('Acme\\FooNonExistent');
|
||||
$definition->setOverriddenGetter('getFoo', array('foo'));
|
||||
|
||||
$container->compile();
|
||||
|
||||
$dumper = new PhpDumper($container);
|
||||
$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Overriden_Getters_On_Non_Existent_Definition'));
|
||||
}
|
||||
|
||||
public function testEnvParameter()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Tests\Compiler\A;
|
||||
use Symfony\Component\DependencyInjection\Tests\Compiler\B;
|
||||
use Symfony\Component\DependencyInjection\Tests\Compiler\Bar;
|
||||
use Symfony\Component\DependencyInjection\Tests\Compiler\Foo;
|
||||
|
||||
/**
|
||||
* To test getter autowiring with PHP >= 7.1.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class GetterOverriding
|
||||
{
|
||||
/** @required */
|
||||
public function getFoo(): ?Foo
|
||||
{
|
||||
// should be called
|
||||
}
|
||||
|
||||
/** @required */
|
||||
protected function getBar(): Bar
|
||||
{
|
||||
// should be called
|
||||
}
|
||||
|
||||
/** @required */
|
||||
public function getUnknown(): NotExist
|
||||
{
|
||||
// should not be called
|
||||
}
|
||||
|
||||
/** @required */
|
||||
public function getExplicitlyDefined(): B
|
||||
{
|
||||
// should be called but not autowired
|
||||
}
|
||||
|
||||
final public function getFinal(): A
|
||||
{
|
||||
// should not be called
|
||||
}
|
||||
|
||||
public function &getReference(): A
|
||||
{
|
||||
// should not be called
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container29;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
if (!class_exists(Foo::class, false)) {
|
||||
abstract class Foo
|
||||
{
|
||||
abstract public function getPublic();
|
||||
abstract protected function getProtected();
|
||||
|
||||
public function getSelf()
|
||||
{
|
||||
return 123;
|
||||
}
|
||||
|
||||
public function getInvalid()
|
||||
{
|
||||
return 456;
|
||||
}
|
||||
|
||||
public function getGetProtected()
|
||||
{
|
||||
return $this->getProtected();
|
||||
}
|
||||
}
|
||||
|
||||
class Baz
|
||||
{
|
||||
final public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
protected function getBaz()
|
||||
{
|
||||
return 234;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('foo', Foo::class)
|
||||
->setOverriddenGetter('getPublic', 'public')
|
||||
->setOverriddenGetter('getProtected', 'protected')
|
||||
->setOverriddenGetter('getSelf', new Reference('foo'))
|
||||
;
|
||||
|
||||
$container
|
||||
->register('baz', Baz::class)
|
||||
->setOverriddenGetter('getBaz', 'baz')
|
||||
;
|
||||
|
||||
return $container;
|
@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container30;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
if (!class_exists(Foo::class, false)) {
|
||||
class Foo
|
||||
{
|
||||
public static function getStatic()
|
||||
{
|
||||
}
|
||||
|
||||
final public function getFinal()
|
||||
{
|
||||
}
|
||||
|
||||
public function &getRef()
|
||||
{
|
||||
}
|
||||
|
||||
public function getParam($a = null)
|
||||
{
|
||||
}
|
||||
|
||||
private function getPrivate()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
final class Bar
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('foo', Foo::class);
|
||||
$container->register('bar', Bar::class);
|
||||
$container->register('baz', Bar::class)->setFactory('foo');
|
||||
|
||||
return $container;
|
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container34;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
if (!class_exists(Foo::class, false)) {
|
||||
abstract class Foo
|
||||
{
|
||||
protected $bar;
|
||||
|
||||
public function __construct($bar = 'bar')
|
||||
{
|
||||
$this->bar = $bar;
|
||||
}
|
||||
|
||||
abstract public function getPublic();
|
||||
abstract protected function getProtected();
|
||||
|
||||
public function getSelf()
|
||||
{
|
||||
return 123;
|
||||
}
|
||||
|
||||
public function getInvalid()
|
||||
{
|
||||
return 456;
|
||||
}
|
||||
|
||||
public function getGetProtected()
|
||||
{
|
||||
return $this->getProtected();
|
||||
}
|
||||
}
|
||||
|
||||
class Baz
|
||||
{
|
||||
final public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
protected function getBaz()
|
||||
{
|
||||
return 234;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container
|
||||
->register('foo', Foo::class)
|
||||
->setOverriddenGetter('getPublic', 'public')
|
||||
->setOverriddenGetter('getProtected', 'protected')
|
||||
->setOverriddenGetter('getSelf', new Reference('foo'))
|
||||
;
|
||||
|
||||
$container
|
||||
->register('baz', Baz::class)
|
||||
->setOverriddenGetter('getBaz', 'baz')
|
||||
;
|
||||
|
||||
return $container;
|
@ -1,166 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
|
||||
|
||||
/**
|
||||
* Symfony_DI_PhpDumper_Test_Overriden_Getters.
|
||||
*
|
||||
* This class has been auto-generated
|
||||
* by the Symfony Dependency Injection Component.
|
||||
*
|
||||
* @final since Symfony 3.3
|
||||
*/
|
||||
class Symfony_DI_PhpDumper_Test_Overriden_Getters extends Container
|
||||
{
|
||||
private $parameters;
|
||||
private $targetDirs = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->services = array();
|
||||
$this->normalizedIds = array(
|
||||
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
|
||||
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
|
||||
);
|
||||
$this->methodMap = array(
|
||||
'baz' => 'getBazService',
|
||||
'foo' => 'getFooService',
|
||||
);
|
||||
|
||||
$this->aliases = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function compile()
|
||||
{
|
||||
throw new LogicException('You cannot compile a dumped container that was already compiled.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isCompiled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isFrozen()
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 'baz' service.
|
||||
*
|
||||
* This service is shared.
|
||||
* This method always returns the same instance of the service.
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\Container29\Baz A Symfony\Component\DependencyInjection\Tests\Fixtures\Container29\Baz instance
|
||||
*/
|
||||
protected function getBazService()
|
||||
{
|
||||
return $this->services['baz'] = $this->instantiateProxy(SymfonyProxy_1e2f71108c6e0938cdbc9e38cae3dcb5::class, array(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 'foo' service.
|
||||
*
|
||||
* This service is shared.
|
||||
* This method always returns the same instance of the service.
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\Container29\Foo A Symfony\Component\DependencyInjection\Tests\Fixtures\Container29\Foo instance
|
||||
*/
|
||||
protected function getFooService()
|
||||
{
|
||||
return $this->services['foo'] = new SymfonyProxy_4a8df73e139322e3fa994cdec2f5b203($this);
|
||||
}
|
||||
|
||||
private function instantiateProxy($class, $args, $useConstructor)
|
||||
{
|
||||
static $reflectionCache;
|
||||
|
||||
if (null === $r = &$reflectionCache[$class]) {
|
||||
$r[0] = new \ReflectionClass($class);
|
||||
$r[1] = $r[0]->getProperty('container6HqvH3fsTTC6dr66HyT2Jw');
|
||||
$r[1]->setAccessible(true);
|
||||
$r[2] = $r[0]->getConstructor();
|
||||
}
|
||||
$service = $useConstructor ? $r[0]->newInstanceWithoutConstructor() : $r[0]->newInstanceArgs($args);
|
||||
$r[1]->setValue($service, $this);
|
||||
if ($r[2] && $useConstructor) {
|
||||
$r[2]->invokeArgs($service, $args);
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
}
|
||||
|
||||
class SymfonyProxy_1e2f71108c6e0938cdbc9e38cae3dcb5 extends \Symfony\Component\DependencyInjection\Tests\Fixtures\Container29\Baz implements \Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyInterface
|
||||
{
|
||||
private $container6HqvH3fsTTC6dr66HyT2Jw;
|
||||
private $getters6HqvH3fsTTC6dr66HyT2Jw;
|
||||
|
||||
protected function getBaz()
|
||||
{
|
||||
return 'baz';
|
||||
}
|
||||
}
|
||||
|
||||
class SymfonyProxy_4a8df73e139322e3fa994cdec2f5b203 extends \Symfony\Component\DependencyInjection\Tests\Fixtures\Container29\Foo implements \Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyInterface
|
||||
{
|
||||
private $container6HqvH3fsTTC6dr66HyT2Jw;
|
||||
private $getters6HqvH3fsTTC6dr66HyT2Jw;
|
||||
|
||||
public function __construct($container6HqvH3fsTTC6dr66HyT2Jw)
|
||||
{
|
||||
$this->container6HqvH3fsTTC6dr66HyT2Jw = $container6HqvH3fsTTC6dr66HyT2Jw;
|
||||
}
|
||||
|
||||
public function getPublic()
|
||||
{
|
||||
return 'public';
|
||||
}
|
||||
|
||||
protected function getProtected()
|
||||
{
|
||||
return 'protected';
|
||||
}
|
||||
|
||||
public function getSelf()
|
||||
{
|
||||
if (null === $g = &$this->getters6HqvH3fsTTC6dr66HyT2Jw[__FUNCTION__]) {
|
||||
$g = \Closure::bind(function () { return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}; }, $this->container6HqvH3fsTTC6dr66HyT2Jw, $this->container6HqvH3fsTTC6dr66HyT2Jw);
|
||||
}
|
||||
|
||||
return $g();
|
||||
}
|
||||
|
||||
public function getInvalid()
|
||||
{
|
||||
if (null === $g = &$this->getters6HqvH3fsTTC6dr66HyT2Jw[__FUNCTION__]) {
|
||||
$g = \Closure::bind(function () { return array(0 => $this->get('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)); }, $this->container6HqvH3fsTTC6dr66HyT2Jw, $this->container6HqvH3fsTTC6dr66HyT2Jw);
|
||||
}
|
||||
|
||||
if ($this->container6HqvH3fsTTC6dr66HyT2Jw->has('bar')) {
|
||||
return $g();
|
||||
}
|
||||
|
||||
return parent::getInvalid();
|
||||
}
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
|
||||
|
||||
/**
|
||||
* Symfony_DI_PhpDumper_Test_Overriden_Getters_With_Constructor.
|
||||
*
|
||||
* This class has been auto-generated
|
||||
* by the Symfony Dependency Injection Component.
|
||||
*
|
||||
* @final since Symfony 3.3
|
||||
*/
|
||||
class Symfony_DI_PhpDumper_Test_Overriden_Getters_With_Constructor extends Container
|
||||
{
|
||||
private $parameters;
|
||||
private $targetDirs = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->services = array();
|
||||
$this->normalizedIds = array(
|
||||
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
|
||||
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
|
||||
);
|
||||
$this->methodMap = array(
|
||||
'baz' => 'getBazService',
|
||||
'foo' => 'getFooService',
|
||||
);
|
||||
|
||||
$this->aliases = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function compile()
|
||||
{
|
||||
throw new LogicException('You cannot compile a dumped container that was already compiled.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isCompiled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isFrozen()
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 'baz' service.
|
||||
*
|
||||
* This service is shared.
|
||||
* This method always returns the same instance of the service.
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\Container34\Baz A Symfony\Component\DependencyInjection\Tests\Fixtures\Container34\Baz instance
|
||||
*/
|
||||
protected function getBazService()
|
||||
{
|
||||
return $this->services['baz'] = $this->instantiateProxy(SymfonyProxy_f0afdd0cd14cc92319c3f5d20cec315a::class, array(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 'foo' service.
|
||||
*
|
||||
* This service is shared.
|
||||
* This method always returns the same instance of the service.
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\Container34\Foo A Symfony\Component\DependencyInjection\Tests\Fixtures\Container34\Foo instance
|
||||
*/
|
||||
protected function getFooService()
|
||||
{
|
||||
return $this->services['foo'] = new SymfonyProxy_4fb8f9a44021ab78702917f65fade566($this);
|
||||
}
|
||||
|
||||
private function instantiateProxy($class, $args, $useConstructor)
|
||||
{
|
||||
static $reflectionCache;
|
||||
|
||||
if (null === $r = &$reflectionCache[$class]) {
|
||||
$r[0] = new \ReflectionClass($class);
|
||||
$r[1] = $r[0]->getProperty('containerg3aCmsigw5jaB68sqMSEQQ');
|
||||
$r[1]->setAccessible(true);
|
||||
$r[2] = $r[0]->getConstructor();
|
||||
}
|
||||
$service = $useConstructor ? $r[0]->newInstanceWithoutConstructor() : $r[0]->newInstanceArgs($args);
|
||||
$r[1]->setValue($service, $this);
|
||||
if ($r[2] && $useConstructor) {
|
||||
$r[2]->invokeArgs($service, $args);
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
}
|
||||
|
||||
class SymfonyProxy_f0afdd0cd14cc92319c3f5d20cec315a extends \Symfony\Component\DependencyInjection\Tests\Fixtures\Container34\Baz implements \Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyInterface
|
||||
{
|
||||
private $containerg3aCmsigw5jaB68sqMSEQQ;
|
||||
private $gettersg3aCmsigw5jaB68sqMSEQQ;
|
||||
|
||||
protected function getBaz()
|
||||
{
|
||||
return 'baz';
|
||||
}
|
||||
}
|
||||
|
||||
class SymfonyProxy_4fb8f9a44021ab78702917f65fade566 extends \Symfony\Component\DependencyInjection\Tests\Fixtures\Container34\Foo implements \Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyInterface
|
||||
{
|
||||
private $containerg3aCmsigw5jaB68sqMSEQQ;
|
||||
private $gettersg3aCmsigw5jaB68sqMSEQQ;
|
||||
|
||||
public function __construct($containerg3aCmsigw5jaB68sqMSEQQ, $bar = 'bar')
|
||||
{
|
||||
$this->containerg3aCmsigw5jaB68sqMSEQQ = $containerg3aCmsigw5jaB68sqMSEQQ;
|
||||
parent::__construct($bar);
|
||||
}
|
||||
|
||||
public function getPublic()
|
||||
{
|
||||
return 'public';
|
||||
}
|
||||
|
||||
protected function getProtected()
|
||||
{
|
||||
return 'protected';
|
||||
}
|
||||
|
||||
public function getSelf()
|
||||
{
|
||||
if (null === $g = &$this->gettersg3aCmsigw5jaB68sqMSEQQ[__FUNCTION__]) {
|
||||
$g = \Closure::bind(function () { return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}; }, $this->containerg3aCmsigw5jaB68sqMSEQQ, $this->containerg3aCmsigw5jaB68sqMSEQQ);
|
||||
}
|
||||
|
||||
return $g();
|
||||
}
|
||||
|
||||
public function getInvalid()
|
||||
{
|
||||
if (null === $g = &$this->gettersg3aCmsigw5jaB68sqMSEQQ[__FUNCTION__]) {
|
||||
$g = \Closure::bind(function () { return array(0 => $this->get('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)); }, $this->containerg3aCmsigw5jaB68sqMSEQQ, $this->containerg3aCmsigw5jaB68sqMSEQQ);
|
||||
}
|
||||
|
||||
if ($this->containerg3aCmsigw5jaB68sqMSEQQ->has('bar')) {
|
||||
return $g();
|
||||
}
|
||||
|
||||
return parent::getInvalid();
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<services>
|
||||
<service id="foo" class="Foo">
|
||||
<getter name="getBar" type="collection">
|
||||
<getter key="bar" type="service" id="bar" />
|
||||
</getter>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
@ -1,6 +0,0 @@
|
||||
services:
|
||||
foo:
|
||||
class: Foo
|
||||
getters:
|
||||
getBar: { bar: '@bar' }
|
||||
|
@ -580,15 +580,6 @@ class XmlFileLoaderTest extends TestCase
|
||||
$this->assertTrue($container->getDefinition('bar')->isAutowired());
|
||||
}
|
||||
|
||||
public function testGetter()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
|
||||
$loader->load('services31.xml');
|
||||
|
||||
$this->assertEquals(array('getbar' => array('bar' => new Reference('bar'))), $container->getDefinition('foo')->getOverriddenGetters());
|
||||
}
|
||||
|
||||
public function testClassFromId()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -425,15 +425,6 @@ class YamlFileLoaderTest extends TestCase
|
||||
$this->assertFalse($container->getDefinition('no_defaults_child')->isAutowired());
|
||||
}
|
||||
|
||||
public function testGetter()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('services31.yml');
|
||||
|
||||
$this->assertEquals(array('getbar' => array('bar' => new Reference('bar'))), $container->getDefinition('foo')->getOverriddenGetters());
|
||||
}
|
||||
|
||||
public function testNamedArguments()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace Symfony\Component\HttpKernel\Controller;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
@ -235,10 +234,6 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
|
||||
|
||||
$className = is_object($controller) ? get_class($controller) : $controller;
|
||||
|
||||
if (is_subclass_of($className, InheritanceProxyInterface::class)) {
|
||||
$className = get_parent_class($className);
|
||||
}
|
||||
|
||||
if (method_exists($controller, $method)) {
|
||||
return sprintf('Method "%s" on class "%s" should be public and non-abstract.', $method, $className);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyHelper;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||
use Symfony\Component\DependencyInjection\TypedReference;
|
||||
@ -111,7 +111,7 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
||||
// create a per-method map of argument-names to service/type-references
|
||||
$args = array();
|
||||
foreach ($parameters as $p) {
|
||||
$type = $target = InheritanceProxyHelper::getTypeHint($r, $p, true);
|
||||
$type = $target = ProxyHelper::getTypeHint($r, $p, true);
|
||||
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
|
||||
|
||||
if (isset($arguments[$r->name][$p->name])) {
|
||||
|
@ -13,7 +13,6 @@ namespace Symfony\Component\HttpKernel\Tests\Controller;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyInterface;
|
||||
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\NullableController;
|
||||
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\VariadicController;
|
||||
@ -278,18 +277,6 @@ class ControllerResolverTest extends TestCase
|
||||
$this->assertEquals(array(null, null, 'value', 'mandatory'), $resolver->getArguments($request, $controller));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The controller for URI "/" is not callable. Method "protectedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract.
|
||||
*/
|
||||
public function testGetControllerFailsUsingParentClassForProxies()
|
||||
{
|
||||
$resolver = new ControllerResolver();
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'Symfony\Component\HttpKernel\Tests\Controller\ControllerProxy::protectedAction');
|
||||
$resolver->getController($request);
|
||||
}
|
||||
|
||||
protected function createControllerResolver(LoggerInterface $logger = null)
|
||||
{
|
||||
return new ControllerResolver($logger);
|
||||
@ -342,7 +329,3 @@ class ControllerTest
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ControllerProxy extends ControllerTest implements InheritanceProxyInterface
|
||||
{
|
||||
}
|
||||
|
@ -11,8 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\VarDumper\Caster;
|
||||
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyInterface;
|
||||
|
||||
/**
|
||||
* Represents a PHP class identifier.
|
||||
*
|
||||
@ -68,18 +66,6 @@ class ClassStub extends ConstStub
|
||||
return;
|
||||
}
|
||||
|
||||
if (interface_exists(InheritanceProxyInterface::class, false)) {
|
||||
$c = $r instanceof \ReflectionMethod ? $r->getDeclaringClass() : $r;
|
||||
if ($c instanceof \ReflectionClass && $c->implementsInterface(InheritanceProxyInterface::class)) {
|
||||
$p = $c->getParentClass();
|
||||
$this->value = $identifier = str_replace($c->name, $p->name.'@proxy', $identifier);
|
||||
if (0 < $i = strrpos($identifier, '\\')) {
|
||||
$this->attr['ellipsis'] = strlen($identifier) - $i;
|
||||
}
|
||||
$r = $r instanceof \ReflectionMethod ? $p->getMethod($r->name) : $p;
|
||||
}
|
||||
}
|
||||
|
||||
if ($f = $r->getFileName()) {
|
||||
$this->attr['file'] = $f;
|
||||
$this->attr['line'] = $r->getStartLine();
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\VarDumper\Caster;
|
||||
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\VarDumper\Cloner\Stub;
|
||||
|
||||
@ -41,19 +40,4 @@ class SymfonyCaster
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
public static function castInheritanceProxy(InheritanceProxyInterface $proxy, array $a, Stub $stub, $isNested)
|
||||
{
|
||||
$privatePrefix = sprintf("\0%s\0", $stub->class);
|
||||
$stub->class = get_parent_class($proxy).'@proxy';
|
||||
|
||||
foreach ($a as $k => $v) {
|
||||
if ("\0" === $k[0] && 0 === strpos($k, $privatePrefix)) {
|
||||
++$stub->cut;
|
||||
unset($a[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,6 @@ abstract class AbstractCloner implements ClonerInterface
|
||||
'Exception' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castException'),
|
||||
'Error' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castError'),
|
||||
'Symfony\Component\DependencyInjection\ContainerInterface' => array('Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'),
|
||||
'Symfony\Component\DependencyInjection\LazyProxy\InheritanceProxyInterface' => array('Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castInheritanceProxy'),
|
||||
'Symfony\Component\HttpFoundation\Request' => array('Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castRequest'),
|
||||
'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'),
|
||||
'Symfony\Component\VarDumper\Caster\TraceStub' => array('Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'),
|
||||
|
Reference in New Issue
Block a user