Skip to content

Commit 5d6b49b

Browse files
Merge branch '4.1' into 4.2
* 4.1: Fix typos in doc blocks [Debug] ignore underscore vs backslash namespaces in DebugClassLoader [TwigBridge][Form] Prevent multiple rendering of form collection prototypes [FrameworkBundle] fix describing routes with no controllers [DI] move RegisterServiceSubscribersPass before DecoratorServicePass Update ValidationListener.php [Yaml] ensures that the mb_internal_encoding is reset to its initial value [WebLink] Fixed documentation link [Security] getTargetPath of TargetPathTrait must return string or null [Hackday][Serializer] Deserialization ignores argument type hint from phpdoc for array in constructor argument Optimize perf by replacing call_user_func with dynamic vars [Routing] fix dumping same-path routes with placeholders [Security] defer log message in guard authenticator [Validator] Added IBAN format for Vatican City State merge conflicts filter out invalid Intl values filter out invalid language values [Validator] Fixed grouped composite constraints [Form] Filter arrays out of scalar form types Fix HeaderBag::get phpdoc
2 parents c9e0ce1 + dde60b2 commit 5d6b49b

File tree

7 files changed

+55
-12
lines changed

7 files changed

+55
-12
lines changed

Compiler/PassConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public function __construct()
5252
new ValidateEnvPlaceholdersPass(),
5353
new ResolveChildDefinitionsPass(),
5454
new ServiceLocatorTagPass(),
55+
new RegisterServiceSubscribersPass(),
5556
new DecoratorServicePass(),
5657
new ResolveParameterPlaceHoldersPass(false),
5758
new ResolveFactoryClassPass(),
5859
new CheckDefinitionValidityPass(),
59-
new RegisterServiceSubscribersPass(),
6060
new ResolveNamedArgumentsPass(),
6161
new AutowireRequiredMethodsPass(),
6262
new ResolveBindingsPass(),

ContainerBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ private function createService(Definition $definition, array &$inlineServices, $
11621162
throw new InvalidArgumentException(sprintf('The configure callable for class "%s" is not a callable.', \get_class($service)));
11631163
}
11641164

1165-
\call_user_func($callable, $service);
1165+
$callable($service);
11661166
}
11671167

11681168
return $service;

LazyProxy/Instantiator/RealServiceInstantiator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ class RealServiceInstantiator implements InstantiatorInterface
2828
*/
2929
public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator)
3030
{
31-
return \call_user_func($realInstantiator);
31+
return $realInstantiator();
3232
}
3333
}

Loader/ClosureLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(ContainerBuilder $container)
3535
*/
3636
public function load($resource, $type = null)
3737
{
38-
\call_user_func($resource, $this->container);
38+
$resource($this->container);
3939
}
4040

4141
/**

ServiceLocator.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,39 +86,40 @@ private function createNotFoundException(string $id): NotFoundExceptionInterface
8686
$class = isset($class[3]['object']) ? \get_class($class[3]['object']) : null;
8787
$externalId = $this->externalId ?: $class;
8888

89-
$msg = sprintf('Service "%s" not found: ', $id);
89+
$msg = array();
90+
$msg[] = sprintf('Service "%s" not found:', $id);
9091

9192
if (!$this->container) {
9293
$class = null;
9394
} elseif ($this->container->has($id) || isset($this->container->getRemovedIds()[$id])) {
94-
$msg .= 'even though it exists in the app\'s container, ';
95+
$msg[] = 'even though it exists in the app\'s container,';
9596
} else {
9697
try {
9798
$this->container->get($id);
9899
$class = null;
99100
} catch (ServiceNotFoundException $e) {
100101
if ($e->getAlternatives()) {
101-
$msg .= sprintf(' did you mean %s? Anyway, ', $this->formatAlternatives($e->getAlternatives(), 'or'));
102+
$msg[] = sprintf('did you mean %s? Anyway,', $this->formatAlternatives($e->getAlternatives(), 'or'));
102103
} else {
103104
$class = null;
104105
}
105106
}
106107
}
107108
if ($externalId) {
108-
$msg .= sprintf('the container inside "%s" is a smaller service locator that %s', $externalId, $this->formatAlternatives());
109+
$msg[] = sprintf('the container inside "%s" is a smaller service locator that %s', $externalId, $this->formatAlternatives());
109110
} else {
110-
$msg .= sprintf('the current service locator %s', $this->formatAlternatives());
111+
$msg[] = sprintf('the current service locator %s', $this->formatAlternatives());
111112
}
112113

113114
if (!$class) {
114115
// no-op
115116
} elseif (is_subclass_of($class, ServiceSubscriberInterface::class)) {
116-
$msg .= sprintf(' Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "%s::getSubscribedServices()".', preg_replace('/([^\\\\]++\\\\)++/', '', $class));
117+
$msg[] = sprintf('Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "%s::getSubscribedServices()".', preg_replace('/([^\\\\]++\\\\)++/', '', $class));
117118
} else {
118-
$msg .= 'Try using dependency injection instead.';
119+
$msg[] = 'Try using dependency injection instead.';
119120
}
120121

121-
return new ServiceNotFoundException($id, end($this->loading) ?: null, null, array(), $msg);
122+
return new ServiceNotFoundException($id, end($this->loading) ?: null, null, array(), implode(' ', $msg));
122123
}
123124

124125
private function createCircularReferenceException(string $id, array $path): ContainerExceptionInterface

Tests/Compiler/IntegrationTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
1818
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
1919
use Symfony\Component\DependencyInjection\Reference;
20+
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
2021

2122
/**
2223
* This class tests the integration of the different compiler passes.
@@ -120,6 +121,21 @@ public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDe
120121
$this->assertFalse($container->hasDefinition('c'), 'Service C was not inlined.');
121122
}
122123

124+
public function testCanDecorateServiceSubscriber()
125+
{
126+
$container = new ContainerBuilder();
127+
$container->register(ServiceSubscriberStub::class)
128+
->addTag('container.service_subscriber')
129+
->setPublic(true);
130+
131+
$container->register(DecoratedServiceSubscriber::class)
132+
->setDecoratedService(ServiceSubscriberStub::class);
133+
134+
$container->compile();
135+
136+
$this->assertInstanceOf(DecoratedServiceSubscriber::class, $container->get(ServiceSubscriberStub::class));
137+
}
138+
123139
/**
124140
* @dataProvider getYamlCompileTests
125141
*/
@@ -220,6 +236,18 @@ public function getYamlCompileTests()
220236
}
221237
}
222238

239+
class ServiceSubscriberStub implements ServiceSubscriberInterface
240+
{
241+
public static function getSubscribedServices()
242+
{
243+
return array();
244+
}
245+
}
246+
247+
class DecoratedServiceSubscriber
248+
{
249+
}
250+
223251
class IntegrationTestStub extends IntegrationTestStubParent
224252
{
225253
}

Tests/ServiceLocatorTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ public function testThrowsInServiceSubscriber()
6161
$subscriber->getFoo();
6262
}
6363

64+
/**
65+
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
66+
* @expectedExceptionMessage Service "foo" not found: even though it exists in the app's container, the container inside "foo" is a smaller service locator that is empty... Try using dependency injection instead.
67+
*/
68+
public function testGetThrowsServiceNotFoundException()
69+
{
70+
$container = new Container();
71+
$container->set('foo', new \stdClass());
72+
73+
$locator = new ServiceLocator(array());
74+
$locator = $locator->withContext('foo', $container);
75+
$locator->get('foo');
76+
}
77+
6478
public function testInvoke()
6579
{
6680
$locator = $this->getServiceLocator(array(

0 commit comments

Comments
 (0)