From 57daadbf67f3090f8bcd32e6cf70e9266dad9d3e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 1 Jun 2017 22:30:09 +0200 Subject: [PATCH] [Di] Remove closure-proxy arguments --- UPGRADE-3.3.md | 2 +- UPGRADE-4.0.md | 2 +- .../Console/Descriptor/Descriptor.php | 4 - .../Console/Descriptor/TextDescriptor.php | 4 - .../Console/Descriptor/XmlDescriptor.php | 6 -- .../Console/Descriptor/ObjectsProvider.php | 2 - .../Descriptor/builder_1_arguments.json | 7 -- .../Descriptor/builder_1_arguments.xml | 1 - .../Descriptor/definition_arguments_1.json | 7 -- .../Descriptor/definition_arguments_1.txt | 43 ++++---- .../Descriptor/definition_arguments_1.xml | 1 - .../Argument/ClosureProxyArgument.php | 50 ---------- .../DependencyInjection/CHANGELOG.md | 1 - .../DependencyInjection/ContainerBuilder.php | 26 ----- .../DependencyInjection/Dumper/PhpDumper.php | 32 ------ .../DependencyInjection/Dumper/XmlDumper.php | 6 -- .../DependencyInjection/Dumper/YamlDumper.php | 3 - .../LazyProxy/ProxyHelper.php | 48 --------- .../Loader/XmlFileLoader.php | 10 -- .../Loader/YamlFileLoader.php | 16 --- .../schema/dic/services/services-1.0.xsd | 2 - .../InlineServiceDefinitionsPassTest.php | 8 +- .../Tests/ContainerBuilderTest.php | 62 ------------ .../Tests/Dumper/PhpDumperTest.php | 40 -------- .../Tests/Fixtures/containers/container31.php | 37 ------- .../Tests/Fixtures/containers/container32.php | 37 ------- .../Tests/Fixtures/containers/container33.php | 1 - .../Tests/Fixtures/containers/container9.php | 5 - ...ainer_dump_proxy_with_void_return_type.php | 27 ----- .../Tests/Fixtures/graphviz/services9.dot | 2 - .../Tests/Fixtures/php/services31.php | 23 ----- .../Tests/Fixtures/php/services32.php | 99 ------------------- .../Tests/Fixtures/php/services9.php | 16 --- .../Tests/Fixtures/php/services9_compiled.php | 16 --- ...vices_dump_proxy_with_void_return_type.php | 95 ------------------ .../Tests/Fixtures/xml/services9.xml | 3 - .../Tests/Fixtures/yaml/services9.yml | 3 - .../Component/EventDispatcher/CHANGELOG.md | 2 +- .../ContainerAwareEventDispatcher.php | 2 +- .../EventDispatcher/Debug/WrappedListener.php | 8 +- .../Component/VarDumper/Caster/ClassStub.php | 4 - 41 files changed, 30 insertions(+), 733 deletions(-) delete mode 100644 src/Symfony/Component/DependencyInjection/Argument/ClosureProxyArgument.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container31.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container32.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_dump_proxy_with_void_return_type.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dump_proxy_with_void_return_type.php diff --git a/UPGRADE-3.3.md b/UPGRADE-3.3.md index 05f44e549e11b..b8d2524654386 100644 --- a/UPGRADE-3.3.md +++ b/UPGRADE-3.3.md @@ -127,7 +127,7 @@ EventDispatcher --------------- * The `ContainerAwareEventDispatcher` class has been deprecated. - Use `EventDispatcher` with closure-proxy injection instead. + Use `EventDispatcher` with closure factories instead. Finder ------ diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 6c10190c7c502..b06145202e7cd 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -132,7 +132,7 @@ EventDispatcher --------------- * The `ContainerAwareEventDispatcher` class has been removed. - Use `EventDispatcher` with closure-proxy injection instead. + Use `EventDispatcher` with closure factories instead. ExpressionLanguage ------------------ diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php index 268a7818979cb..acaec0bf5dbab 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php @@ -312,10 +312,6 @@ protected function formatClosure(\Closure $closure) { $r = new \ReflectionFunction($closure); - if (preg_match('#^/\*\* @closure-proxy ([^: ]++)::([^: ]++) \*/$#', $r->getDocComment(), $m)) { - return sprintf('%s::%s', $m[1], $m[2]); - } - return 'closure'; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 64c38cdff759f..06a404080d32d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -14,7 +14,6 @@ use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -343,9 +342,6 @@ protected function describeContainerDefinition(Definition $definition, array $op $argumentsInformation[] = sprintf('Service(%s)', (string) $argument); } elseif ($argument instanceof IteratorArgument) { $argumentsInformation[] = sprintf('Iterator (%d element(s))', count($argument->getValues())); - } elseif ($argument instanceof ClosureProxyArgument) { - list($reference, $method) = $argument->getValues(); - $argumentsInformation[] = sprintf('ClosureProxy(Service(%s)::%s())', $reference, $method); } elseif ($argument instanceof Definition) { $argumentsInformation[] = 'Inlined Service'; } else { diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index c1e586cf927f5..f1770d8c3c453 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -12,7 +12,6 @@ namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -444,11 +443,6 @@ private function getArgumentNodes(array $arguments, \DOMDocument $dom) foreach ($this->getArgumentNodes($argument->getValues(), $dom) as $childArgumentXML) { $argumentXML->appendChild($childArgumentXML); } - } elseif ($argument instanceof ClosureProxyArgument) { - list($reference, $method) = $argument->getValues(); - $argumentXML->setAttribute('type', 'closure-proxy'); - $argumentXML->setAttribute('id', (string) $reference); - $argumentXML->setAttribute('method', $method); } elseif ($argument instanceof Definition) { $argumentXML->appendChild($dom->importNode($this->getContainerDefinitionDocument($argument, null, false, true)->childNodes->item(0), true)); } elseif (is_array($argument)) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php index 0c0363c482bab..9eb2e874d63d5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php @@ -12,7 +12,6 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -119,7 +118,6 @@ public static function getContainerDefinitions() new Reference('definition_1'), new Reference('definition_2'), ))) - ->addArgument(new ClosureProxyArgument('definition1', 'get')) ->setFactory(array('Full\\Qualified\\FactoryClass', 'get')), 'definition_2' => $definition2 ->setPublic(false) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json index dd3f81f1768e4..e2ab628937760 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json @@ -60,13 +60,6 @@ "type": "service", "id": "definition_2" } - ], - [ - { - "type": "service", - "id": "definition1" - }, - "get" ] ], "file": null, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml index 91b292da50248..b016ae382a908 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.xml @@ -22,7 +22,6 @@ - diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.json index 0590d3f76a611..5074d4fba6170 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.json @@ -58,13 +58,6 @@ "type": "service", "id": "definition_2" } - ], - [ - { - "type": "service", - "id": "definition1" - }, - "get" ] ], "file": null, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.txt index 0bb95302f8315..989f96ee1369f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.txt +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.txt @@ -1,23 +1,22 @@ - ---------------- ------------------------------------------- -  Option   Value  - ---------------- ------------------------------------------- - Service ID - - Class Full\Qualified\Class1 - Tags - - Public yes - Synthetic no - Lazy yes - Shared yes - Abstract yes - Autowired no - Autoconfigured no - Factory Class Full\Qualified\FactoryClass - Factory Method get - Arguments Service(definition2)  - %parameter%  - Inlined Service  - Array (3 element(s))  - Iterator (2 element(s))  - ClosureProxy(Service(definition1)::get()) - ---------------- ------------------------------------------- + ---------------- ----------------------------- +  Option   Value  + ---------------- ----------------------------- + Service ID - + Class Full\Qualified\Class1 + Tags - + Public yes + Synthetic no + Lazy yes + Shared yes + Abstract yes + Autowired no + Autoconfigured no + Factory Class Full\Qualified\FactoryClass + Factory Method get + Arguments Service(definition2)  + %parameter%  + Inlined Service  + Array (3 element(s))  + Iterator (2 element(s)) + ---------------- ----------------------------- diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.xml index 6d3cb8eea40be..732f99f7839a1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.xml @@ -20,5 +20,4 @@ - diff --git a/src/Symfony/Component/DependencyInjection/Argument/ClosureProxyArgument.php b/src/Symfony/Component/DependencyInjection/Argument/ClosureProxyArgument.php deleted file mode 100644 index 94ba13241a108..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Argument/ClosureProxyArgument.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Argument; - -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; -use Symfony\Component\DependencyInjection\Reference; - -/** - * @author Nicolas Grekas - */ -class ClosureProxyArgument implements ArgumentInterface -{ - private $reference; - private $method; - - public function __construct($id, $method, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) - { - $this->reference = new Reference($id, $invalidBehavior); - $this->method = $method; - } - - /** - * {@inheritdoc} - */ - public function getValues() - { - return array($this->reference, $this->method); - } - - /** - * {@inheritdoc} - */ - public function setValues(array $values) - { - if (!$values[0] instanceof Reference) { - throw new InvalidArgumentException(sprintf('A ClosureProxyArgument must hold a Reference, "%s" given.', is_object($values[0]) ? get_class($values[0]) : gettype($values[0]))); - } - list($this->reference, $this->method) = $values; - } -} diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index b591c5958dae7..457e22413ea5f 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -20,7 +20,6 @@ CHANGELOG * 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 - * added "closure-proxy" argument type for turning services' methods into lazy callables * added file-wide configurable defaults for service attributes "public", "tags", "autowire" and "autoconfigure" * made the "class" attribute optional, using the "id" as fallback diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 0675dd6f58071..3887e56fc244a 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection; use Psr\Container\ContainerInterface as PsrContainerInterface; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; @@ -1161,31 +1160,6 @@ public function resolveServices($value) return $count; }); - } elseif ($value instanceof ClosureProxyArgument) { - $parameterBag = $this->getParameterBag(); - list($reference, $method) = $value->getValues(); - if ('service_container' === $id = (string) $reference) { - $class = parent::class; - } elseif (!$this->hasDefinition($id) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) { - return; - } else { - $class = $parameterBag->resolveValue($this->findDefinition($id)->getClass()); - } - if (!method_exists($class, $method = $parameterBag->resolveValue($method))) { - throw new InvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" does not exist.', $id, $class, $method)); - } - $r = new \ReflectionMethod($class, $method); - if (!$r->isPublic()) { - throw new RuntimeException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" must be public.', $id, $class, $method)); - } - foreach ($r->getParameters() as $p) { - if ($p->isPassedByReference()) { - throw new RuntimeException(sprintf('Cannot create closure-proxy for service "%s": parameter "$%s" of method "%s::%s" must not be passed by reference.', $id, $p->name, $class, $method)); - } - } - $value = function () use ($id, $method) { - return call_user_func_array(array($this->get($id), $method), func_get_args()); - }; } elseif ($value instanceof Reference) { $value = $this->get((string) $value, $value->getInvalidBehavior()); } elseif ($value instanceof Definition) { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index a1fb8950e0871..840b670f165f5 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -12,7 +12,6 @@ namespace Symfony\Component\DependencyInjection\Dumper; use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\Variable; @@ -27,7 +26,6 @@ use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException; -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; @@ -67,7 +65,6 @@ class PhpDumper extends Dumper private $docStar; private $serviceIdToMethodNameMap; private $usedMethodNames; - private $baseClass; /** * @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface @@ -125,7 +122,6 @@ public function dump(array $options = array()) $this->classResources = array(); $this->initializeMethodNamesMap($options['base_class']); - $this->baseClass = $options['base_class']; $this->docStar = $options['debug'] ? '*' : ''; @@ -1465,34 +1461,6 @@ private function dumpValue($value, $interpolate = true) return implode("\n", $code); } - - if ($value instanceof ClosureProxyArgument) { - list($reference, $method) = $value->getValues(); - $method = substr($this->dumpLiteralClass($this->dumpValue($method)), 1); - - if ('service_container' === (string) $reference) { - $class = $this->baseClass; - } elseif (!$this->container->hasDefinition((string) $reference) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) { - return 'null'; - } else { - $class = substr($this->dumpLiteralClass($this->dumpValue($this->container->findDefinition((string) $reference)->getClass())), 1); - } - if (false !== strpos($class, '$') || false !== strpos($method, '$')) { - throw new RuntimeException(sprintf('Cannot dump definition for service "%s": dynamic class names or methods, and closure-proxies are incompatible with each other.', $reference)); - } - if (!method_exists($class, $method)) { - throw new InvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" does not exist.', $reference, $class, $method)); - } - $r = $this->container->getReflectionClass($class)->getMethod($method); - 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', ProxyHelper::getSignature($r, $call)); - - $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); - } } finally { list($this->definitionVariables, $this->referenceVariables, $this->variableCount) = $scope; } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php index 61978dcd28971..c6b3be06a1402 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php @@ -11,7 +11,6 @@ namespace Symfony\Component\DependencyInjection\Dumper; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -302,11 +301,6 @@ private function convertParameters(array $parameters, $type, \DOMElement $parent } elseif ($value instanceof IteratorArgument) { $element->setAttribute('type', 'iterator'); $this->convertParameters($value->getValues(), $type, $element, 'key'); - } elseif ($value instanceof ClosureProxyArgument) { - list($reference, $method) = $value->getValues(); - $element->setAttribute('type', 'closure-proxy'); - $element->setAttribute('id', (string) $reference); - $element->setAttribute('method', $method); } elseif ($value instanceof Reference) { $element->setAttribute('type', 'service'); $element->setAttribute('id', (string) $value); diff --git a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php index 81951fe536699..e71df2af24c14 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php @@ -15,7 +15,6 @@ use Symfony\Component\Yaml\Tag\TaggedValue; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -256,8 +255,6 @@ private function dumpValue($value) if ($value instanceof ArgumentInterface) { if ($value instanceof IteratorArgument) { $tag = 'iterator'; - } elseif ($value instanceof ClosureProxyArgument) { - $tag = 'closure_proxy'; } else { throw new RuntimeException(sprintf('Unspecified Yaml tag for type "%s".', get_class($value))); } diff --git a/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php b/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php index 5f0c8772fef43..84686efff5d6a 100644 --- a/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php +++ b/src/Symfony/Component/DependencyInjection/LazyProxy/ProxyHelper.php @@ -18,54 +18,6 @@ */ class ProxyHelper { - /** - * @return string The signature of the passed function, return type and function/method name included if any - */ - public static function getSignature(\ReflectionFunctionAbstract $r, &$call = null) - { - $signature = array(); - $call = array(); - - foreach ($r->getParameters() as $i => $p) { - $k = '$'.$p->name; - if (method_exists($p, 'isVariadic') && $p->isVariadic()) { - $k = '...'.$k; - } - $call[] = $k; - - if ($p->isPassedByReference()) { - $k = '&'.$k; - } - if ($type = self::getTypeHint($r, $p)) { - $k = $type.' '.$k; - } - if ($type && $p->allowsNull()) { - $k = '?'.$k; - } - - try { - $k .= ' = '.self::export($p->getDefaultValue()); - if ($type && $p->allowsNull() && null === $p->getDefaultValue()) { - $k = substr($k, 1); - } - } catch (\ReflectionException $e) { - if ($type && $p->allowsNull() && !class_exists('ReflectionNamedType', false)) { - $k .= ' = null'; - $k = substr($k, 1); - } - } - - $signature[] = $k; - } - $call = ($r->isClosure() ? '' : $r->name).'('.implode(', ', $call).')'; - - if ($type = self::getTypeHint($r)) { - $type = ': '.($r->getReturnType()->allowsNull() ? '?' : '').$type; - } - - return ($r->returnsReference() ? '&' : '').($r->isClosure() ? '' : $r->name).'('.implode(', ', $signature).')'.$type; - } - /** * @return string|null The FQCN or builtin name of the type hint, or null when the type hint references an invalid self|parent context */ diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 79c8fbf9677ab..4b07e5c58581e 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -14,7 +14,6 @@ use Symfony\Component\Config\Util\XmlUtils; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ChildDefinition; @@ -493,15 +492,6 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase = case 'expression': $arguments[$key] = new Expression($arg->nodeValue); break; - case 'closure-proxy': - if (!$arg->getAttribute('id')) { - throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="closure-proxy" has no or empty "id" attribute in "%s".', $name, $file)); - } - if (!$arg->getAttribute('method')) { - throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="closure-proxy" has no or empty "method" attribute in "%s".', $name, $file)); - } - $arguments[$key] = new ClosureProxyArgument($arg->getAttribute('id'), $arg->getAttribute('method'), $invalidBehavior); - break; case 'collection': $arguments[$key] = $this->getArgumentsAsPhp($arg, $name, $file, false); break; diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index c3e697c1b5207..7a0123ba21bf5 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -13,7 +13,6 @@ use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -679,21 +678,6 @@ private function resolveServices($value, $file, $isParameter = false) throw new InvalidArgumentException(sprintf('"!iterator" tag only accepts arrays of "@service" references in "%s".', $file)); } } - if ('closure_proxy' === $value->getTag()) { - if (!is_array($argument) || array(0, 1) !== array_keys($argument) || !is_string($argument[0]) || !is_string($argument[1]) || 0 !== strpos($argument[0], '@') || 0 === strpos($argument[0], '@@')) { - throw new InvalidArgumentException(sprintf('"!closure_proxy" tagged values must be arrays of [@service, method] in "%s".', $file)); - } - - if (0 === strpos($argument[0], '@?')) { - $argument[0] = substr($argument[0], 2); - $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE; - } else { - $argument[0] = substr($argument[0], 1); - $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE; - } - - return new ClosureProxyArgument($argument[0], $argument[1], $invalidBehavior); - } if ('service' === $value->getTag()) { if ($isParameter) { throw new InvalidArgumentException(sprintf('Using an anonymous service in a parameter is not allowed in "%s".', $file)); diff --git a/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd b/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd index 2de786bdb7cba..6f5c8ccc543d3 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd +++ b/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd @@ -218,7 +218,6 @@ - @@ -244,7 +243,6 @@ - diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php index f0dd7fe74dc4c..26b24fa713242 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -18,7 +18,7 @@ use Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; +use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; class InlineServiceDefinitionsPassTest extends TestCase @@ -233,8 +233,8 @@ public function testProcessDoesNotSetLazyArgumentValuesAfterInlining() ->setShared(false) ; $container - ->register('closure-proxy') - ->setArguments(array(new ClosureProxyArgument('inline', 'method'))) + ->register('service-closure') + ->setArguments(array(new ServiceClosureArgument(new Reference('inline')))) ; $container ->register('iterator') @@ -243,7 +243,7 @@ public function testProcessDoesNotSetLazyArgumentValuesAfterInlining() $this->process($container); - $values = $container->getDefinition('closure-proxy')->getArgument(0)->getValues(); + $values = $container->getDefinition('service-closure')->getArgument(0)->getValues(); $this->assertInstanceOf(Reference::class, $values[0]); $this->assertSame('inline', (string) $values[0]); diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 3558c7bd226e1..51f7001491a19 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -20,7 +20,6 @@ use Symfony\Component\Config\Resource\ResourceInterface; use Symfony\Component\Config\Resource\DirectoryResource; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; @@ -1008,63 +1007,6 @@ public function testAutowiring() $this->assertEquals(A::class, (string) $container->getDefinition('b')->getArgument(0)); } - public function testClosureProxy() - { - $container = new ContainerBuilder(); - - $container->register('foo', 'stdClass') - ->setProperty('foo', new ClosureProxyArgument('bar', 'c')) - ; - $container->register('bar', A::class); - - $foo = $container->get('foo'); - - $this->assertInstanceOf('Closure', $foo->foo); - $this->assertSame(123, call_user_func($foo->foo)); - } - - public function testClosureProxyContainer() - { - $container = new ContainerBuilder(); - - $container->register('foo', 'stdClass') - ->setProperty('foo', new ClosureProxyArgument('service_container', 'get')) - ; - - $foo = $container->get('foo'); - - $this->assertInstanceOf('Closure', $foo->foo); - $this->assertSame($foo, call_user_func($foo->foo, 'foo')); - } - - public function testClosureProxyOnInvalidNull() - { - $container = new ContainerBuilder(); - - $container->register('foo', 'stdClass') - ->setProperty('foo', new ClosureProxyArgument('bar', 'c', ContainerInterface::NULL_ON_INVALID_REFERENCE)) - ; - - $foo = $container->get('foo'); - - $this->assertNull($foo->foo); - } - - /** - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException - * @expectedExceptionMessage You have requested a non-existent service "bar". - */ - public function testClosureProxyOnInvalidException() - { - $container = new ContainerBuilder(); - - $container->register('foo', 'stdClass') - ->setProperty('foo', new ClosureProxyArgument('bar', 'c')) - ; - - $container->get('foo'); - } - public function testClassFromId() { $container = new ContainerBuilder(); @@ -1148,10 +1090,6 @@ class FooClass class A { - public function c() - { - return 123; - } } class B diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index b11201111c1f5..fe53b941006de 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -472,46 +472,6 @@ public function testLazyArgumentProvideGenerator() $this->assertEmpty(iterator_to_array($lazyContext->lazyEmptyValues)); } - public function testClosureProxy() - { - $container = include self::$fixturesPath.'/containers/container31.php'; - $container->compile(); - $dumper = new PhpDumper($container); - - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services31.php', $dumper->dump()); - $res = $container->getResources(); - $this->assertSame('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Container31\Foo', (string) array_pop($res)); - } - - /** - * @requires PHP 7.1 - */ - public function testClosureProxyWithVoidReturnType() - { - $container = include self::$fixturesPath.'/containers/container_dump_proxy_with_void_return_type.php'; - - $container->compile(); - $dumper = new PhpDumper($container); - - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_dump_proxy_with_void_return_type.php', $dumper->dump()); - $res = $container->getResources(); - $this->assertSame('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\ContainerVoid\Foo', (string) array_pop($res)); - } - - /** - * @requires PHP 7.1 - */ - public function testClosureProxyPhp71() - { - $container = include self::$fixturesPath.'/containers/container32.php'; - $container->compile(); - $dumper = new PhpDumper($container); - - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services32.php', $dumper->dump()); - $res = $container->getResources(); - $this->assertSame('reflection.Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo', (string) array_pop($res)); - } - public function testNormalizedId() { $container = include self::$fixturesPath.'/containers/container33.php'; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container31.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container31.php deleted file mode 100644 index e8493ad02cdf6..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container31.php +++ /dev/null @@ -1,37 +0,0 @@ -register('foo', Foo::class); - -$container->register('bar', 'stdClass') - ->setProperty('foo', array( - new ClosureProxyArgument('foo', 'withNoArgs'), - new ClosureProxyArgument('foo', 'withArgs'), - new ClosureProxyArgument('foo', 'withRefs'), - )) -; - -return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container32.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container32.php deleted file mode 100644 index 00d5654a5b464..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container32.php +++ /dev/null @@ -1,37 +0,0 @@ -register('foo', Foo::class); - -$container->register('bar', 'stdClass') - ->setProperty('foo', array( - new ClosureProxyArgument('foo', 'withVariadic'), - new ClosureProxyArgument('foo', 'withNullable'), - new ClosureProxyArgument('foo', 'withReturnType'), - )) -; - -return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container33.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container33.php index 482558cb0d352..6deb52d170af8 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container33.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container33.php @@ -2,7 +2,6 @@ namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container33; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; if (!class_exists(Foo::class, false)) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php index 2a31ec6d76e47..13b45fda07a70 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php @@ -3,7 +3,6 @@ require_once __DIR__.'/../includes/classes.php'; require_once __DIR__.'/../includes/foo.php'; -use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -140,9 +139,5 @@ ->register('lazy_context_ignore_invalid_ref', 'LazyContext') ->setArguments(array(new IteratorArgument(array(new Reference('foo.baz'), new Reference('invalid', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))), new IteratorArgument(array()))) ; -$container - ->register('closure_proxy', 'BarClass') - ->setArguments(array(new ClosureProxyArgument('closure_proxy', 'getBaz'))) -; return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_dump_proxy_with_void_return_type.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_dump_proxy_with_void_return_type.php deleted file mode 100644 index ef9cb92a6c141..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_dump_proxy_with_void_return_type.php +++ /dev/null @@ -1,27 +0,0 @@ -register('foo', Foo::class); - -$container->register('bar', 'stdClass') - ->setProperty('foo', array( - new ClosureProxyArgument('foo', 'withVoid'), - )) -; - -return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot index ac6a9c38d1d51..b316b93c1576b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot @@ -29,7 +29,6 @@ digraph sc { node_factory_service_simple [label="factory_service_simple\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_lazy_context [label="lazy_context\nLazyContext\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_lazy_context_ignore_invalid_ref [label="lazy_context_ignore_invalid_ref\nLazyContext\n", shape=record, fillcolor="#eeeeee", style="filled"]; - node_closure_proxy [label="closure_proxy\nBarClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"]; node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"]; node_foobaz [label="foobaz\n\n", shape=record, fillcolor="#ff9999", style="filled"]; @@ -51,5 +50,4 @@ digraph sc { node_lazy_context -> node_service_container [label="" style="filled" color="#9999ff"]; node_lazy_context_ignore_invalid_ref -> node_foo_baz [label="" style="filled" color="#9999ff"]; node_lazy_context_ignore_invalid_ref -> node_invalid [label="" style="filled" color="#9999ff"]; - node_closure_proxy -> node_closure_proxy [label="" style="filled" color="#9999ff"]; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php index d22a130cd0514..daf0ed5d60a19 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services31.php @@ -61,29 +61,6 @@ public function isFrozen() return true; } - /** - * Gets the 'bar' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance - */ - protected function getBarService() - { - $this->services['bar'] = $instance = new \stdClass(); - - $instance->foo = array(0 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\Container31\Foo::withNoArgs */ function () { - return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withNoArgs(); - }, 1 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\Container31\Foo::withArgs */ function ($a, \Symfony\Component\DependencyInjection\Tests\Fixtures\Container31\Foo $b = NULL, $c = array(0 => 123)) { - return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withArgs($a, $b, $c); - }, 2 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\Container31\Foo::withRefs */ function &(&$a = NULL, &$b) { - return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withRefs($a, $b); - }); - - return $instance; - } - /** * Gets the 'foo' service. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php deleted file mode 100644 index 08ca63092a6a6..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services32.php +++ /dev/null @@ -1,99 +0,0 @@ -services = array(); - $this->methodMap = array( - 'bar' => 'getBarService', - '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 'bar' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance - */ - protected function getBarService() - { - $this->services['bar'] = $instance = new \stdClass(); - - $instance->foo = array(0 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo::withVariadic */ function ($a, &...$c) { - return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withVariadic($a, ...$c); - }, 1 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo::withNullable */ function (?int $a) { - return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withNullable($a); - }, 2 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo::withReturnType */ function (): \Bar { - return ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withReturnType(); - }); - - return $instance; - } - - /** - * Gets the 'foo' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo A Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo instance - */ - protected function getFooService() - { - return $this->services['foo'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\Container32\Foo(); - } -} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index b8d5aeafacf24..2f8de5c8c0eb1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -34,7 +34,6 @@ public function __construct() $this->methodMap = array( 'bar' => 'getBarService', 'baz' => 'getBazService', - 'closure_proxy' => 'getClosureProxyService', 'configurator_service' => 'getConfiguratorServiceService', 'configurator_service_simple' => 'getConfiguratorServiceSimpleService', 'configured_service' => 'getConfiguredServiceService', @@ -109,21 +108,6 @@ protected function getBazService() return $instance; } - /** - * Gets the 'closure_proxy' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \BarClass A BarClass instance - */ - protected function getClosureProxyService() - { - return $this->services['closure_proxy'] = new \BarClass(/** @closure-proxy BarClass::getBaz */ function () { - return ${($_ = isset($this->services['closure_proxy']) ? $this->services['closure_proxy'] : $this->get('closure_proxy')) && false ?: '_'}->getBaz(); - }); - } - /** * Gets the 'configured_service' service. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index a519cece6e297..08707b3b692c1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -32,7 +32,6 @@ public function __construct() $this->methodMap = array( 'bar' => 'getBarService', 'baz' => 'getBazService', - 'closure_proxy' => 'getClosureProxyService', 'configured_service' => 'getConfiguredServiceService', 'configured_service_simple' => 'getConfiguredServiceSimpleService', 'decorator_service' => 'getDecoratorServiceService', @@ -119,21 +118,6 @@ protected function getBazService() return $instance; } - /** - * Gets the 'closure_proxy' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \BarClass A BarClass instance - */ - protected function getClosureProxyService() - { - return $this->services['closure_proxy'] = new \BarClass(/** @closure-proxy BarClass::getBaz */ function () { - return ${($_ = isset($this->services['closure_proxy']) ? $this->services['closure_proxy'] : $this->get('closure_proxy')) && false ?: '_'}->getBaz(); - }); - } - /** * Gets the 'configured_service' service. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dump_proxy_with_void_return_type.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dump_proxy_with_void_return_type.php deleted file mode 100644 index ec6af7fc2c8c5..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_dump_proxy_with_void_return_type.php +++ /dev/null @@ -1,95 +0,0 @@ -services = array(); - $this->methodMap = array( - 'bar' => 'getBarService', - '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 'bar' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance - */ - protected function getBarService() - { - $this->services['bar'] = $instance = new \stdClass(); - - $instance->foo = array(0 => /** @closure-proxy Symfony\Component\DependencyInjection\Tests\Fixtures\ContainerVoid\Foo::withVoid */ function (): void { - ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->get('foo')) && false ?: '_'}->withVoid(); - }); - - return $instance; - } - - /** - * Gets the 'foo' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \Symfony\Component\DependencyInjection\Tests\Fixtures\ContainerVoid\Foo A Symfony\Component\DependencyInjection\Tests\Fixtures\ContainerVoid\Foo instance - */ - protected function getFooService() - { - return $this->services['foo'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\ContainerVoid\Foo(); - } -} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml index 79fdff4c4e2d0..100a23a9c5b7e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml @@ -130,9 +130,6 @@ - - - diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml index bfee29fb605e5..a7a9cc28fd61b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml @@ -116,9 +116,6 @@ services: lazy_context_ignore_invalid_ref: class: LazyContext arguments: [!iterator ['@foo.baz', '@?invalid'], !iterator []] - closure_proxy: - class: BarClass - arguments: [!closure_proxy ['@closure_proxy', getBaz]] alias_for_foo: '@foo' alias_for_alias: '@foo' Psr\Container\ContainerInterface: diff --git a/src/Symfony/Component/EventDispatcher/CHANGELOG.md b/src/Symfony/Component/EventDispatcher/CHANGELOG.md index 51c1d919bb4df..736bd84903b4b 100644 --- a/src/Symfony/Component/EventDispatcher/CHANGELOG.md +++ b/src/Symfony/Component/EventDispatcher/CHANGELOG.md @@ -4,7 +4,7 @@ CHANGELOG 3.3.0 ----- - * The ContainerAwareEventDispatcher class has been deprecated. Use EventDispatcher with closure-proxy injection instead. + * The ContainerAwareEventDispatcher class has been deprecated. Use EventDispatcher with closure factories instead. 3.0.0 ----- diff --git a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php index 72eca3deb0490..f9e51b1a8b864 100644 --- a/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php @@ -160,7 +160,7 @@ public function getListenerPriority($eventName, $listener) */ public function addSubscriberService($serviceId, $class) { - @trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use EventDispatcher with closure-proxy injection instead.', __CLASS__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED); foreach ($class::getSubscribedEvents() as $eventName => $params) { if (is_string($params)) { diff --git a/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php b/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php index 130cc54d343bd..4029883dd98c7 100644 --- a/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php +++ b/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php @@ -46,13 +46,7 @@ public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatc $this->name = is_object($listener[0]) ? get_class($listener[0]) : $listener[0]; $this->pretty = $this->name.'::'.$listener[1]; } elseif ($listener instanceof \Closure) { - $r = new \ReflectionFunction($listener); - if (preg_match('#^/\*\* @closure-proxy ([^: ]++)::([^: ]++) \*/$#', $r->getDocComment(), $m)) { - $this->name = $m[1]; - $this->pretty = $m[1].'::'.$m[2]; - } else { - $this->pretty = $this->name = 'closure'; - } + $this->pretty = $this->name = 'closure'; } elseif (is_string($listener)) { $this->pretty = $this->name = $listener; } else { diff --git a/src/Symfony/Component/VarDumper/Caster/ClassStub.php b/src/Symfony/Component/VarDumper/Caster/ClassStub.php index 51990bc356c0d..4765174d08670 100644 --- a/src/Symfony/Component/VarDumper/Caster/ClassStub.php +++ b/src/Symfony/Component/VarDumper/Caster/ClassStub.php @@ -38,10 +38,6 @@ public function __construct($identifier, $callable = null) if (null !== $callable) { if ($callable instanceof \Closure) { $r = new \ReflectionFunction($callable); - - if (preg_match('#^/\*\* @closure-proxy ([^: ]++)::([^: ]++) \*/$#', $r->getDocComment(), $m)) { - $r = array($m[1], $m[2]); - } } elseif (is_object($callable)) { $r = array($callable, '__invoke'); } elseif (is_array($callable)) {