Skip to content

[Di] Remove closure-proxy arguments #23022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion UPGRADE-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------
Expand Down
2 changes: 1 addition & 1 deletion UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@
"type": "service",
"id": "definition_2"
}
],
[
{
"type": "service",
"id": "definition1"
},
"get"
]
],
"file": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<argument type="service" id="definition_1"/>
<argument type="service" id="definition_2"/>
</argument>
<argument type="closure-proxy" id="definition1" method="get"/>
</definition>
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@
"type": "service",
"id": "definition_2"
}
],
[
{
"type": "service",
"id": "definition1"
},
"get"
]
],
"file": null,
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
---------------- -----------------------------

Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@
<argument type="service" id="definition_1"/>
<argument type="service" id="definition_2"/>
</argument>
<argument type="closure-proxy" id="definition1" method="get"/>
</definition>

This file was deleted.

1 change: 0 additions & 1 deletion src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 0 additions & 26 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
32 changes: 0 additions & 32 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -67,7 +65,6 @@ class PhpDumper extends Dumper
private $docStar;
private $serviceIdToMethodNameMap;
private $usedMethodNames;
private $baseClass;

/**
* @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface
Expand Down Expand Up @@ -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'] ? '*' : '';

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}
Expand Down
Loading