Skip to content

Commit 0ae6541

Browse files
[Di] Remove closure-proxy arguments
1 parent 552468b commit 0ae6541

26 files changed

+4
-664
lines changed

Argument/ClosureProxyArgument.php

Lines changed: 0 additions & 50 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ CHANGELOG
2020
* added support for omitting the factory class name in a service definition if the definition class is set
2121
* deprecated case insensitivity of service identifiers
2222
* added "iterator" argument type for lazy iteration over a set of values and services
23-
* added "closure-proxy" argument type for turning services' methods into lazy callables
2423
* added file-wide configurable defaults for service attributes "public", "tags",
2524
"autowire" and "autoconfigure"
2625
* made the "class" attribute optional, using the "id" as fallback

ContainerBuilder.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\DependencyInjection;
1313

1414
use Psr\Container\ContainerInterface as PsrContainerInterface;
15-
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
1615
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1716
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
1817
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
@@ -1161,31 +1160,6 @@ public function resolveServices($value)
11611160

11621161
return $count;
11631162
});
1164-
} elseif ($value instanceof ClosureProxyArgument) {
1165-
$parameterBag = $this->getParameterBag();
1166-
list($reference, $method) = $value->getValues();
1167-
if ('service_container' === $id = (string) $reference) {
1168-
$class = parent::class;
1169-
} elseif (!$this->hasDefinition($id) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) {
1170-
return;
1171-
} else {
1172-
$class = $parameterBag->resolveValue($this->findDefinition($id)->getClass());
1173-
}
1174-
if (!method_exists($class, $method = $parameterBag->resolveValue($method))) {
1175-
throw new InvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" does not exist.', $id, $class, $method));
1176-
}
1177-
$r = new \ReflectionMethod($class, $method);
1178-
if (!$r->isPublic()) {
1179-
throw new RuntimeException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" must be public.', $id, $class, $method));
1180-
}
1181-
foreach ($r->getParameters() as $p) {
1182-
if ($p->isPassedByReference()) {
1183-
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));
1184-
}
1185-
}
1186-
$value = function () use ($id, $method) {
1187-
return call_user_func_array(array($this->get($id), $method), func_get_args());
1188-
};
11891163
} elseif ($value instanceof Reference) {
11901164
$value = $this->get((string) $value, $value->getInvalidBehavior());
11911165
} elseif ($value instanceof Definition) {

Dumper/PhpDumper.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\DependencyInjection\Dumper;
1313

1414
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
15-
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
1615
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1716
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1817
use Symfony\Component\DependencyInjection\Variable;
@@ -27,7 +26,6 @@
2726
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
2827
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
2928
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
30-
use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper;
3129
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface as ProxyDumper;
3230
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\NullDumper;
3331
use Symfony\Component\DependencyInjection\ExpressionLanguage;
@@ -67,7 +65,6 @@ class PhpDumper extends Dumper
6765
private $docStar;
6866
private $serviceIdToMethodNameMap;
6967
private $usedMethodNames;
70-
private $baseClass;
7168

7269
/**
7370
* @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface
@@ -125,7 +122,6 @@ public function dump(array $options = array())
125122

126123
$this->classResources = array();
127124
$this->initializeMethodNamesMap($options['base_class']);
128-
$this->baseClass = $options['base_class'];
129125

130126
$this->docStar = $options['debug'] ? '*' : '';
131127

@@ -1465,34 +1461,6 @@ private function dumpValue($value, $interpolate = true)
14651461

14661462
return implode("\n", $code);
14671463
}
1468-
1469-
if ($value instanceof ClosureProxyArgument) {
1470-
list($reference, $method) = $value->getValues();
1471-
$method = substr($this->dumpLiteralClass($this->dumpValue($method)), 1);
1472-
1473-
if ('service_container' === (string) $reference) {
1474-
$class = $this->baseClass;
1475-
} elseif (!$this->container->hasDefinition((string) $reference) && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) {
1476-
return 'null';
1477-
} else {
1478-
$class = substr($this->dumpLiteralClass($this->dumpValue($this->container->findDefinition((string) $reference)->getClass())), 1);
1479-
}
1480-
if (false !== strpos($class, '$') || false !== strpos($method, '$')) {
1481-
throw new RuntimeException(sprintf('Cannot dump definition for service "%s": dynamic class names or methods, and closure-proxies are incompatible with each other.', $reference));
1482-
}
1483-
if (!method_exists($class, $method)) {
1484-
throw new InvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" does not exist.', $reference, $class, $method));
1485-
}
1486-
$r = $this->container->getReflectionClass($class)->getMethod($method);
1487-
if (!$r->isPublic()) {
1488-
throw new InvalidArgumentException(sprintf('Cannot create closure-proxy for service "%s": method "%s::%s" must be public.', $reference, $class, $method));
1489-
}
1490-
$signature = preg_replace('/^(&?)[^(]*/', '$1', ProxyHelper::getSignature($r, $call));
1491-
1492-
$return = 'void' !== ProxyHelper::getTypeHint($r);
1493-
1494-
return sprintf("/** @closure-proxy %s::%s */ function %s {\n %s%s->%s;\n }", $class, $method, $signature, $return ? 'return ' : '', $this->dumpValue($reference), $call);
1495-
}
14961464
} finally {
14971465
list($this->definitionVariables, $this->referenceVariables, $this->variableCount) = $scope;
14981466
}

Dumper/XmlDumper.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Dumper;
1313

14-
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
1514
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1615
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1716
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -302,11 +301,6 @@ private function convertParameters(array $parameters, $type, \DOMElement $parent
302301
} elseif ($value instanceof IteratorArgument) {
303302
$element->setAttribute('type', 'iterator');
304303
$this->convertParameters($value->getValues(), $type, $element, 'key');
305-
} elseif ($value instanceof ClosureProxyArgument) {
306-
list($reference, $method) = $value->getValues();
307-
$element->setAttribute('type', 'closure-proxy');
308-
$element->setAttribute('id', (string) $reference);
309-
$element->setAttribute('method', $method);
310304
} elseif ($value instanceof Reference) {
311305
$element->setAttribute('type', 'service');
312306
$element->setAttribute('id', (string) $value);

Dumper/YamlDumper.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\Yaml\Tag\TaggedValue;
1616
use Symfony\Component\DependencyInjection\Alias;
1717
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
18-
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
1918
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
2019
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
2120
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -256,8 +255,6 @@ private function dumpValue($value)
256255
if ($value instanceof ArgumentInterface) {
257256
if ($value instanceof IteratorArgument) {
258257
$tag = 'iterator';
259-
} elseif ($value instanceof ClosureProxyArgument) {
260-
$tag = 'closure_proxy';
261258
} else {
262259
throw new RuntimeException(sprintf('Unspecified Yaml tag for type "%s".', get_class($value)));
263260
}

LazyProxy/ProxyHelper.php

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,54 +18,6 @@
1818
*/
1919
class ProxyHelper
2020
{
21-
/**
22-
* @return string The signature of the passed function, return type and function/method name included if any
23-
*/
24-
public static function getSignature(\ReflectionFunctionAbstract $r, &$call = null)
25-
{
26-
$signature = array();
27-
$call = array();
28-
29-
foreach ($r->getParameters() as $i => $p) {
30-
$k = '$'.$p->name;
31-
if (method_exists($p, 'isVariadic') && $p->isVariadic()) {
32-
$k = '...'.$k;
33-
}
34-
$call[] = $k;
35-
36-
if ($p->isPassedByReference()) {
37-
$k = '&'.$k;
38-
}
39-
if ($type = self::getTypeHint($r, $p)) {
40-
$k = $type.' '.$k;
41-
}
42-
if ($type && $p->allowsNull()) {
43-
$k = '?'.$k;
44-
}
45-
46-
try {
47-
$k .= ' = '.self::export($p->getDefaultValue());
48-
if ($type && $p->allowsNull() && null === $p->getDefaultValue()) {
49-
$k = substr($k, 1);
50-
}
51-
} catch (\ReflectionException $e) {
52-
if ($type && $p->allowsNull() && !class_exists('ReflectionNamedType', false)) {
53-
$k .= ' = null';
54-
$k = substr($k, 1);
55-
}
56-
}
57-
58-
$signature[] = $k;
59-
}
60-
$call = ($r->isClosure() ? '' : $r->name).'('.implode(', ', $call).')';
61-
62-
if ($type = self::getTypeHint($r)) {
63-
$type = ': '.($r->getReturnType()->allowsNull() ? '?' : '').$type;
64-
}
65-
66-
return ($r->returnsReference() ? '&' : '').($r->isClosure() ? '' : $r->name).'('.implode(', ', $signature).')'.$type;
67-
}
68-
6921
/**
7022
* @return string|null The FQCN or builtin name of the type hint, or null when the type hint references an invalid self|parent context
7123
*/

Loader/XmlFileLoader.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\Config\Util\XmlUtils;
1515
use Symfony\Component\DependencyInjection\ContainerInterface;
1616
use Symfony\Component\DependencyInjection\Alias;
17-
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
1817
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1918
use Symfony\Component\DependencyInjection\Definition;
2019
use Symfony\Component\DependencyInjection\ChildDefinition;
@@ -493,15 +492,6 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase =
493492
case 'expression':
494493
$arguments[$key] = new Expression($arg->nodeValue);
495494
break;
496-
case 'closure-proxy':
497-
if (!$arg->getAttribute('id')) {
498-
throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="closure-proxy" has no or empty "id" attribute in "%s".', $name, $file));
499-
}
500-
if (!$arg->getAttribute('method')) {
501-
throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="closure-proxy" has no or empty "method" attribute in "%s".', $name, $file));
502-
}
503-
$arguments[$key] = new ClosureProxyArgument($arg->getAttribute('id'), $arg->getAttribute('method'), $invalidBehavior);
504-
break;
505495
case 'collection':
506496
$arguments[$key] = $this->getArgumentsAsPhp($arg, $name, $file, false);
507497
break;

Loader/YamlFileLoader.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\DependencyInjection\Alias;
1515
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
16-
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
1716
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1817
use Symfony\Component\DependencyInjection\ChildDefinition;
1918
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -679,21 +678,6 @@ private function resolveServices($value, $file, $isParameter = false)
679678
throw new InvalidArgumentException(sprintf('"!iterator" tag only accepts arrays of "@service" references in "%s".', $file));
680679
}
681680
}
682-
if ('closure_proxy' === $value->getTag()) {
683-
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], '@@')) {
684-
throw new InvalidArgumentException(sprintf('"!closure_proxy" tagged values must be arrays of [@service, method] in "%s".', $file));
685-
}
686-
687-
if (0 === strpos($argument[0], '@?')) {
688-
$argument[0] = substr($argument[0], 2);
689-
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
690-
} else {
691-
$argument[0] = substr($argument[0], 1);
692-
$invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
693-
}
694-
695-
return new ClosureProxyArgument($argument[0], $argument[1], $invalidBehavior);
696-
}
697681
if ('service' === $value->getTag()) {
698682
if ($isParameter) {
699683
throw new InvalidArgumentException(sprintf('Using an anonymous service in a parameter is not allowed in "%s".', $file));

Loader/schema/dic/services/services-1.0.xsd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@
218218
<xsd:attribute name="index" type="xsd:integer" />
219219
<xsd:attribute name="on-invalid" type="invalid_sequence" />
220220
<xsd:attribute name="strict" type="boolean" />
221-
<xsd:attribute name="method" type="xsd:string" />
222221
</xsd:complexType>
223222

224223
<xsd:complexType name="call">
@@ -244,7 +243,6 @@
244243
<xsd:enumeration value="string" />
245244
<xsd:enumeration value="constant" />
246245
<xsd:enumeration value="iterator" />
247-
<xsd:enumeration value="closure-proxy" />
248246
</xsd:restriction>
249247
</xsd:simpleType>
250248

Tests/Compiler/InlineServiceDefinitionsPassTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass;
1919
use Symfony\Component\DependencyInjection\Reference;
2020
use Symfony\Component\DependencyInjection\ContainerBuilder;
21-
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
21+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
2222
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
2323

2424
class InlineServiceDefinitionsPassTest extends TestCase
@@ -233,8 +233,8 @@ public function testProcessDoesNotSetLazyArgumentValuesAfterInlining()
233233
->setShared(false)
234234
;
235235
$container
236-
->register('closure-proxy')
237-
->setArguments(array(new ClosureProxyArgument('inline', 'method')))
236+
->register('service-closure')
237+
->setArguments(array(new ServiceClosureArgument(new Reference('inline'))))
238238
;
239239
$container
240240
->register('iterator')
@@ -243,7 +243,7 @@ public function testProcessDoesNotSetLazyArgumentValuesAfterInlining()
243243

244244
$this->process($container);
245245

246-
$values = $container->getDefinition('closure-proxy')->getArgument(0)->getValues();
246+
$values = $container->getDefinition('service-closure')->getArgument(0)->getValues();
247247
$this->assertInstanceOf(Reference::class, $values[0]);
248248
$this->assertSame('inline', (string) $values[0]);
249249

0 commit comments

Comments
 (0)