Skip to content

Commit 9f1cea6

Browse files
Merge branch '3.4' into 4.0
* 3.4: (24 commits) moved Twig runtime to proper class fixed deprecated messages in tests add PHP errors options to XML schema definition [HttpCache] Unlink tmp file on error Added LB translation for #26327 (Errors sign for people that do not see colors) [TwigBridge] Fix rendering of currency by MoneyType Import InvalidArgumentException in PdoAdapter [DI] Do not suggest writing an implementation when multiple exist [Intl] Update ICU data to 61.1 Use 3rd person verb form in command description [Validator] Add Japanese translation Support phpdbg SAPI in Debug::enable() [HttpKernel] DumpDataCollector: do not flush when a dumper is provided [DI] Fix hardcoded cache dir for warmups [Routing] fix tests [Routing] Fixed the importing of files using glob patterns that match multiple resources [Ldap] cast to string when checking empty passwords [Validator] sync validator translation id [WebProfilerBundle] use the router to resolve file links no type errors with invalid submitted data types ...
2 parents 2dd7973 + 24a6871 commit 9f1cea6

File tree

4 files changed

+64
-56
lines changed

4 files changed

+64
-56
lines changed

Compiler/AutowirePass.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,11 @@ private function createTypeNotFoundMessage(TypedReference $reference, $label)
310310

311311
$message = sprintf('has type "%s" but this class %s.', $type, $parentMsg ? sprintf('is missing a parent class (%s)', $parentMsg) : 'was not found');
312312
} else {
313+
$alternatives = $this->createTypeAlternatives($reference);
313314
$message = $this->container->has($type) ? 'this service is abstract' : 'no such service exists';
314-
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $this->createTypeAlternatives($reference));
315+
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $alternatives);
315316

316-
if ($r->isInterface()) {
317+
if ($r->isInterface() && !$alternatives) {
317318
$message .= ' Did you create a class that implements this interface?';
318319
}
319320
}

Dumper/PhpDumper.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function dump(array $options = array())
248248
'container.build_hash' => '$hash',
249249
'container.build_id' => '$id',
250250
'container.build_time' => $time,
251-
));
251+
), __DIR__.\\DIRECTORY_SEPARATOR.'Container{$hash}');
252252
253253
EOF;
254254
} else {
@@ -739,7 +739,7 @@ protected function {$methodName}($lazyInitialization)
739739
}
740740

741741
if ($this->getProxyDumper()->isProxyCandidate($definition)) {
742-
$factoryCode = $asFile ? "\$this->load(__DIR__.'/%s.php', false)" : '$this->%s(false)';
742+
$factoryCode = $asFile ? "\$this->load('%s.php', false)" : '$this->%s(false)';
743743
$code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName));
744744
}
745745

@@ -903,7 +903,7 @@ public function __construct()
903903
904904
EOF;
905905
if (null !== $this->targetDirRegex) {
906-
$dir = $this->asFiles ? '$this->targetDirs[0] = \\dirname(__DIR__)' : '__DIR__';
906+
$dir = $this->asFiles ? '$this->targetDirs[0] = \\dirname($containerDir)' : '__DIR__';
907907
$code .= <<<EOF
908908
\$dir = {$dir};
909909
for (\$i = 1; \$i <= {$this->targetDirMaxMatches}; ++\$i) {
@@ -913,9 +913,10 @@ public function __construct()
913913
EOF;
914914
}
915915
if ($this->asFiles) {
916-
$code = str_replace('$parameters', "\$buildParameters;\n private \$parameters", $code);
917-
$code = str_replace('__construct()', '__construct(array $buildParameters = array())', $code);
916+
$code = str_replace('$parameters', "\$buildParameters;\n private \$containerDir;\n private \$parameters", $code);
917+
$code = str_replace('__construct()', '__construct(array $buildParameters = array(), $containerDir = __DIR__)', $code);
918918
$code .= " \$this->buildParameters = \$buildParameters;\n";
919+
$code .= " \$this->containerDir = \$containerDir;\n";
919920
}
920921

921922
if (Container::class !== $baseClassWithNamespace) {
@@ -967,7 +968,7 @@ public function isCompiled()
967968
968969
protected function load(\$file, \$lazyLoad = true)
969970
{
970-
return require \$file;
971+
return require \$this->containerDir.\\DIRECTORY_SEPARATOR.\$file;
971972
}
972973
973974
EOF;
@@ -979,7 +980,7 @@ protected function load(\$file, \$lazyLoad = true)
979980
continue;
980981
}
981982
if ($this->asFiles) {
982-
$proxyLoader = '$this->load(__DIR__."/{$class}.php")';
983+
$proxyLoader = '$this->load("{$class}.php")';
983984
} elseif ($this->namespace) {
984985
$proxyLoader = 'class_alias("'.$this->namespace.'\\\\{$class}", $class, false)';
985986
} else {
@@ -1028,7 +1029,7 @@ private function addRemovedIds(): string
10281029
return '';
10291030
}
10301031
if ($this->asFiles) {
1031-
$code = "require __DIR__.'/removed-ids.php'";
1032+
$code = "require \$this->containerDir.\\DIRECTORY_SEPARATOR.'removed-ids.php'";
10321033
} else {
10331034
$code = '';
10341035
$ids = array_keys($ids);
@@ -1071,7 +1072,7 @@ private function addFileMap(): string
10711072
ksort($definitions);
10721073
foreach ($definitions as $id => $definition) {
10731074
if (!$definition->isSynthetic() && $definition->isPublic() && $definition->isShared() && !$this->isHotPath($definition)) {
1074-
$code .= sprintf(" %s => __DIR__.'/%s.php',\n", $this->doExport($id), $this->generateMethodName($id));
1075+
$code .= sprintf(" %s => '%s.php',\n", $this->doExport($id), $this->generateMethodName($id));
10751076
}
10761077
}
10771078

@@ -1643,7 +1644,7 @@ private function getServiceCall(string $id, Reference $reference = null): string
16431644
$code = sprintf('$this->%s[\'%s\'] = %s', $definition->isPublic() ? 'services' : 'privates', $id, $code);
16441645
}
16451646
} elseif ($this->asFiles && $definition->isShared() && !$this->isHotPath($definition)) {
1646-
$code = sprintf("\$this->load(__DIR__.'/%s.php')", $this->generateMethodName($id));
1647+
$code = sprintf("\$this->load('%s.php')", $this->generateMethodName($id));
16471648
} else {
16481649
$code = sprintf('$this->%s()', $this->generateMethodName($id));
16491650
}
@@ -1777,7 +1778,7 @@ private function export($value)
17771778
$prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : '';
17781779
$suffix = $matches[0][1] + strlen($matches[0][0]);
17791780
$suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
1780-
$dirname = '__DIR__';
1781+
$dirname = $this->asFiles ? '$this->containerDir' : '__DIR__';
17811782
$offset = 1 + $this->targetDirMaxMatches - count($matches);
17821783

17831784
if ($this->asFiles || 0 < $offset) {

Tests/Compiler/AutowirePassTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
1818
use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass;
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
20+
use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException;
2021
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
2122
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2223
use Symfony\Component\DependencyInjection\Reference;
@@ -576,10 +577,6 @@ public function testIgnoreServiceWithClassNotExisting()
576577
$this->assertTrue($container->hasDefinition('bar'));
577578
}
578579

579-
/**
580-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
581-
* @expectedExceptionMessage Cannot autowire service "setter_injection_collision": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\SetterInjectionCollision::setMultipleInstancesForOneArg()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2".
582-
*/
583580
public function testSetterInjectionCollisionThrowsException()
584581
{
585582
$container = new ContainerBuilder();
@@ -592,7 +589,14 @@ public function testSetterInjectionCollisionThrowsException()
592589
(new AutowireRequiredMethodsPass())->process($container);
593590

594591
$pass = new AutowirePass();
595-
$pass->process($container);
592+
593+
try {
594+
$pass->process($container);
595+
} catch (AutowiringFailedException $e) {
596+
}
597+
598+
$this->assertNotNull($e);
599+
$this->assertSame('Cannot autowire service "setter_injection_collision": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\SetterInjectionCollision::setMultipleInstancesForOneArg()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2".', $e->getMessage());
596600
}
597601

598602
/**

Tests/Fixtures/php/services9_as_files.txt

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
5555

5656
$this->services['baz'] = $instance = new \Baz();
5757

58-
$instance->setFoo(($this->services['foo_with_inline'] ?? $this->load(__DIR__.'/getFooWithInlineService.php')));
58+
$instance->setFoo(($this->services['foo_with_inline'] ?? $this->load('getFooWithInlineService.php')));
5959

6060
return $instance;
6161

@@ -69,7 +69,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
6969
$this->services['configured_service'] = $instance = new \stdClass();
7070

7171
$a = new \ConfClass();
72-
$a->setFoo(($this->services['baz'] ?? $this->load(__DIR__.'/getBazService.php')));
72+
$a->setFoo(($this->services['baz'] ?? $this->load('getBazService.php')));
7373

7474
$a->configureStdClass($instance);
7575

@@ -124,7 +124,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
124124
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
125125
// Returns the public 'factory_service' shared service.
126126

127-
return $this->services['factory_service'] = ($this->services['foo.baz'] ?? $this->load(__DIR__.'/getFoo_BazService.php'))->getInstance();
127+
return $this->services['factory_service'] = ($this->services['foo.baz'] ?? $this->load('getFoo_BazService.php'))->getInstance();
128128

129129
[Container%s/getFactoryServiceSimpleService.php] => <?php
130130

@@ -133,7 +133,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
133133
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
134134
// Returns the public 'factory_service_simple' shared service.
135135

136-
return $this->services['factory_service_simple'] = ($this->privates['factory_simple'] ?? $this->load(__DIR__.'/getFactorySimpleService.php'))->getInstance();
136+
return $this->services['factory_service_simple'] = ($this->privates['factory_simple'] ?? $this->load('getFactorySimpleService.php'))->getInstance();
137137

138138
[Container%s/getFactorySimpleService.php] => <?php
139139

@@ -153,7 +153,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
153153
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
154154
// Returns the public 'foo' shared service.
155155

156-
$a = ($this->services['foo.baz'] ?? $this->load(__DIR__.'/getFoo_BazService.php'));
156+
$a = ($this->services['foo.baz'] ?? $this->load('getFoo_BazService.php'));
157157

158158
$this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, array('bar' => 'foo is bar', 'foobar' => 'bar'), true, $this);
159159

@@ -191,7 +191,7 @@ $this->services['foo_with_inline'] = $instance = new \Foo();
191191
$a = new \Bar();
192192

193193
$a->pub = 'pub';
194-
$a->setBaz(($this->services['baz'] ?? $this->load(__DIR__.'/getBazService.php')));
194+
$a->setBaz(($this->services['baz'] ?? $this->load('getBazService.php')));
195195

196196
$instance->setBar($a);
197197

@@ -205,7 +205,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
205205
// Returns the public 'lazy_context' shared service.
206206

207207
return $this->services['lazy_context'] = new \LazyContext(new RewindableGenerator(function () {
208-
yield 'k1' => ($this->services['foo.baz'] ?? $this->load(__DIR__.'/getFoo_BazService.php'));
208+
yield 'k1' => ($this->services['foo.baz'] ?? $this->load('getFoo_BazService.php'));
209209
yield 'k2' => $this;
210210
}, 2), new RewindableGenerator(function () {
211211
return new \EmptyIterator();
@@ -219,7 +219,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
219219
// Returns the public 'lazy_context_ignore_invalid_ref' shared service.
220220

221221
return $this->services['lazy_context_ignore_invalid_ref'] = new \LazyContext(new RewindableGenerator(function () {
222-
yield 0 => ($this->services['foo.baz'] ?? $this->load(__DIR__.'/getFoo_BazService.php'));
222+
yield 0 => ($this->services['foo.baz'] ?? $this->load('getFoo_BazService.php'));
223223
}, 1), new RewindableGenerator(function () {
224224
return new \EmptyIterator();
225225
}, 0));
@@ -235,9 +235,9 @@ include_once ($this->targetDirs[0].'/Fixtures/includes/foo.php');
235235

236236
$this->services['method_call1'] = $instance = new \Bar\FooClass();
237237

238-
$instance->setBar(($this->services['foo'] ?? $this->load(__DIR__.'/getFooService.php')));
238+
$instance->setBar(($this->services['foo'] ?? $this->load('getFooService.php')));
239239
$instance->setBar(NULL);
240-
$instance->setBar((($this->services['foo'] ?? $this->load(__DIR__.'/getFooService.php'))->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
240+
$instance->setBar((($this->services['foo'] ?? $this->load('getFooService.php'))->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
241241

242242
return $instance;
243243

@@ -274,7 +274,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
274274
// Returns the public 'tagged_iterator' shared service.
275275

276276
return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () {
277-
yield 0 => ($this->services['foo'] ?? $this->load(__DIR__.'/getFooService.php'));
277+
yield 0 => ($this->services['foo'] ?? $this->load('getFooService.php'));
278278
yield 1 => ($this->privates['tagged_iterator_foo'] ?? $this->privates['tagged_iterator_foo'] = new \Bar());
279279
}, 2));
280280

@@ -308,6 +308,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
308308
class ProjectServiceContainer extends Container
309309
{
310310
private $buildParameters;
311+
private $containerDir;
311312
private $parameters;
312313
private $targetDirs = array();
313314

@@ -316,13 +317,14 @@ class ProjectServiceContainer extends Container
316317
*/
317318
protected $privates = array();
318319

319-
public function __construct(array $buildParameters = array())
320+
public function __construct(array $buildParameters = array(), $containerDir = __DIR__)
320321
{
321-
$dir = $this->targetDirs[0] = \dirname(__DIR__);
322+
$dir = $this->targetDirs[0] = \dirname($containerDir);
322323
for ($i = 1; $i <= 5; ++$i) {
323324
$this->targetDirs[$i] = $dir = \dirname($dir);
324325
}
325326
$this->buildParameters = $buildParameters;
327+
$this->containerDir = $containerDir;
326328
$this->parameters = $this->getDefaultParameters();
327329

328330
$this->services = $this->privates = array();
@@ -334,26 +336,26 @@ class ProjectServiceContainer extends Container
334336
'foo_bar' => 'getFooBarService',
335337
);
336338
$this->fileMap = array(
337-
'BAR' => __DIR__.'/getBAR2Service.php',
338-
'BAR2' => __DIR__.'/getBAR22Service.php',
339-
'bar2' => __DIR__.'/getBar23Service.php',
340-
'baz' => __DIR__.'/getBazService.php',
341-
'configured_service' => __DIR__.'/getConfiguredServiceService.php',
342-
'configured_service_simple' => __DIR__.'/getConfiguredServiceSimpleService.php',
343-
'decorator_service' => __DIR__.'/getDecoratorServiceService.php',
344-
'decorator_service_with_name' => __DIR__.'/getDecoratorServiceWithNameService.php',
345-
'deprecated_service' => __DIR__.'/getDeprecatedServiceService.php',
346-
'factory_service' => __DIR__.'/getFactoryServiceService.php',
347-
'factory_service_simple' => __DIR__.'/getFactoryServiceSimpleService.php',
348-
'foo' => __DIR__.'/getFooService.php',
349-
'foo.baz' => __DIR__.'/getFoo_BazService.php',
350-
'foo_with_inline' => __DIR__.'/getFooWithInlineService.php',
351-
'lazy_context' => __DIR__.'/getLazyContextService.php',
352-
'lazy_context_ignore_invalid_ref' => __DIR__.'/getLazyContextIgnoreInvalidRefService.php',
353-
'method_call1' => __DIR__.'/getMethodCall1Service.php',
354-
'new_factory_service' => __DIR__.'/getNewFactoryServiceService.php',
355-
'service_from_static_method' => __DIR__.'/getServiceFromStaticMethodService.php',
356-
'tagged_iterator' => __DIR__.'/getTaggedIteratorService.php',
339+
'BAR' => 'getBAR2Service.php',
340+
'BAR2' => 'getBAR22Service.php',
341+
'bar2' => 'getBar23Service.php',
342+
'baz' => 'getBazService.php',
343+
'configured_service' => 'getConfiguredServiceService.php',
344+
'configured_service_simple' => 'getConfiguredServiceSimpleService.php',
345+
'decorator_service' => 'getDecoratorServiceService.php',
346+
'decorator_service_with_name' => 'getDecoratorServiceWithNameService.php',
347+
'deprecated_service' => 'getDeprecatedServiceService.php',
348+
'factory_service' => 'getFactoryServiceService.php',
349+
'factory_service_simple' => 'getFactoryServiceSimpleService.php',
350+
'foo' => 'getFooService.php',
351+
'foo.baz' => 'getFoo_BazService.php',
352+
'foo_with_inline' => 'getFooWithInlineService.php',
353+
'lazy_context' => 'getLazyContextService.php',
354+
'lazy_context_ignore_invalid_ref' => 'getLazyContextIgnoreInvalidRefService.php',
355+
'method_call1' => 'getMethodCall1Service.php',
356+
'new_factory_service' => 'getNewFactoryServiceService.php',
357+
'service_from_static_method' => 'getServiceFromStaticMethodService.php',
358+
'tagged_iterator' => 'getTaggedIteratorService.php',
357359
);
358360
$this->aliases = array(
359361
'alias_for_alias' => 'foo',
@@ -380,12 +382,12 @@ class ProjectServiceContainer extends Container
380382

381383
public function getRemovedIds()
382384
{
383-
return require __DIR__.'/removed-ids.php';
385+
return require $this->containerDir.\DIRECTORY_SEPARATOR.'removed-ids.php';
384386
}
385387

386388
protected function load($file, $lazyLoad = true)
387389
{
388-
return require $file;
390+
return require $this->containerDir.\DIRECTORY_SEPARATOR.$file;
389391
}
390392

391393
/**
@@ -395,7 +397,7 @@ class ProjectServiceContainer extends Container
395397
*/
396398
protected function getBarService()
397399
{
398-
$a = ($this->services['foo.baz'] ?? $this->load(__DIR__.'/getFoo_BazService.php'));
400+
$a = ($this->services['foo.baz'] ?? $this->load('getFoo_BazService.php'));
399401

400402
$this->services['bar'] = $instance = new \Bar\FooClass('foo', $a, $this->getParameter('foo_bar'));
401403

@@ -411,7 +413,7 @@ class ProjectServiceContainer extends Container
411413
*/
412414
protected function getFooBarService()
413415
{
414-
return new \Bar\FooClass(($this->services['deprecated_service'] ?? $this->load(__DIR__.'/getDeprecatedServiceService.php')));
416+
return new \Bar\FooClass(($this->services['deprecated_service'] ?? $this->load('getDeprecatedServiceService.php')));
415417
}
416418

417419
public function getParameter($name)
@@ -514,6 +516,6 @@ return new \Container%s\ProjectServiceContainer(array(
514516
'container.build_hash' => '%s',
515517
'container.build_id' => '%s',
516518
'container.build_time' => %d,
517-
));
519+
), __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
518520

519521
)

0 commit comments

Comments
 (0)