Skip to content

Commit 56873c7

Browse files
Merge branch '4.0'
* 4.0: (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 e237279 + 9f1cea6 commit 56873c7

File tree

4 files changed

+68
-60
lines changed

4 files changed

+68
-60
lines changed

Compiler/AutowirePass.php

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

361361
$message = sprintf('has type "%s" but this class %s.', $type, $parentMsg ? sprintf('is missing a parent class (%s)', $parentMsg) : 'was not found');
362362
} else {
363+
$alternatives = $this->createTypeAlternatives($reference);
363364
$message = $this->container->has($type) ? 'this service is abstract' : 'no such service exists';
364-
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $this->createTypeAlternatives($reference));
365+
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $alternatives);
365366

366-
if ($r->isInterface()) {
367+
if ($r->isInterface() && !$alternatives) {
367368
$message .= ' Did you create a class that implements this interface?';
368369
}
369370
}

Dumper/PhpDumper.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public function dump(array $options = array())
249249
'container.build_hash' => '$hash',
250250
'container.build_id' => '$id',
251251
'container.build_time' => $time,
252-
));
252+
), __DIR__.\\DIRECTORY_SEPARATOR.'Container{$hash}');
253253
254254
EOF;
255255
} else {
@@ -762,7 +762,7 @@ protected function {$methodName}($lazyInitialization)
762762
$code .= $this->addServiceInclude($id, $definition, $inlinedDefinitions);
763763

764764
if ($this->getProxyDumper()->isProxyCandidate($definition)) {
765-
$factoryCode = $asFile ? "\$this->load(__DIR__.'/%s.php', false)" : '$this->%s(false)';
765+
$factoryCode = $asFile ? "\$this->load('%s.php', false)" : '$this->%s(false)';
766766
$code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName));
767767
}
768768

@@ -925,7 +925,7 @@ public function __construct()
925925
926926
EOF;
927927
if (null !== $this->targetDirRegex) {
928-
$dir = $this->asFiles ? '$this->targetDirs[0] = \\dirname(__DIR__)' : '__DIR__';
928+
$dir = $this->asFiles ? '$this->targetDirs[0] = \\dirname($containerDir)' : '__DIR__';
929929
$code .= <<<EOF
930930
\$dir = {$dir};
931931
for (\$i = 1; \$i <= {$this->targetDirMaxMatches}; ++\$i) {
@@ -935,9 +935,10 @@ public function __construct()
935935
EOF;
936936
}
937937
if ($this->asFiles) {
938-
$code = str_replace('$parameters', "\$buildParameters;\n private \$parameters", $code);
939-
$code = str_replace('__construct()', '__construct(array $buildParameters = array())', $code);
938+
$code = str_replace('$parameters', "\$buildParameters;\n private \$containerDir;\n private \$parameters", $code);
939+
$code = str_replace('__construct()', '__construct(array $buildParameters = array(), $containerDir = __DIR__)', $code);
940940
$code .= " \$this->buildParameters = \$buildParameters;\n";
941+
$code .= " \$this->containerDir = \$containerDir;\n";
941942
}
942943

943944
if (Container::class !== $baseClassWithNamespace) {
@@ -989,7 +990,7 @@ public function isCompiled()
989990
990991
protected function load(\$file, \$lazyLoad = true)
991992
{
992-
return require \$file;
993+
return require \$this->containerDir.\\DIRECTORY_SEPARATOR.\$file;
993994
}
994995
995996
EOF;
@@ -1001,7 +1002,7 @@ protected function load(\$file, \$lazyLoad = true)
10011002
continue;
10021003
}
10031004
if ($this->asFiles) {
1004-
$proxyLoader = '$this->load(__DIR__."/{$class}.php")';
1005+
$proxyLoader = '$this->load("{$class}.php")';
10051006
} elseif ($this->namespace) {
10061007
$proxyLoader = 'class_alias("'.$this->namespace.'\\\\{$class}", $class, false)';
10071008
} else {
@@ -1050,7 +1051,7 @@ private function addRemovedIds(): string
10501051
return '';
10511052
}
10521053
if ($this->asFiles) {
1053-
$code = "require __DIR__.'/removed-ids.php'";
1054+
$code = "require \$this->containerDir.\\DIRECTORY_SEPARATOR.'removed-ids.php'";
10541055
} else {
10551056
$code = '';
10561057
$ids = array_keys($ids);
@@ -1093,7 +1094,7 @@ private function addFileMap(): string
10931094
ksort($definitions);
10941095
foreach ($definitions as $id => $definition) {
10951096
if (!$definition->isSynthetic() && $definition->isPublic() && !$this->isHotPath($definition)) {
1096-
$code .= sprintf(" %s => __DIR__.'/%s.php',\n", $this->doExport($id), $this->generateMethodName($id));
1097+
$code .= sprintf(" %s => '%s.php',\n", $this->doExport($id), $this->generateMethodName($id));
10971098
}
10981099
}
10991100

@@ -1665,7 +1666,7 @@ private function getServiceCall(string $id, Reference $reference = null): string
16651666
$code = sprintf('$this->%s[\'%s\'] = %s', $definition->isPublic() ? 'services' : 'privates', $id, $code);
16661667
}
16671668
} elseif ($this->asFiles && !$this->isHotPath($definition)) {
1668-
$code = sprintf("\$this->load(__DIR__.'/%s.php')", $this->generateMethodName($id));
1669+
$code = sprintf("\$this->load('%s.php')", $this->generateMethodName($id));
16691670
if (!$definition->isShared()) {
16701671
$factory = sprintf('$this->factories%s[\'%s\']', $definition->isPublic() ? '' : "['service_container']", $id);
16711672
$code = sprintf('(isset(%s) ? %1$s() : %s)', $factory, $code);
@@ -1803,7 +1804,7 @@ private function export($value)
18031804
$prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : '';
18041805
$suffix = $matches[0][1] + strlen($matches[0][0]);
18051806
$suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
1806-
$dirname = '__DIR__';
1807+
$dirname = $this->asFiles ? '$this->containerDir' : '__DIR__';
18071808
$offset = 1 + $this->targetDirMaxMatches - count($matches);
18081809

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

Tests/Compiler/AutowirePassTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass;
2222
use Symfony\Component\DependencyInjection\ContainerBuilder;
2323
use Symfony\Component\DependencyInjection\Definition;
24+
use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException;
2425
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
2526
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2627
use Symfony\Component\DependencyInjection\Reference;
@@ -580,10 +581,6 @@ public function testIgnoreServiceWithClassNotExisting()
580581
$this->assertTrue($container->hasDefinition('bar'));
581582
}
582583

583-
/**
584-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
585-
* @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".
586-
*/
587584
public function testSetterInjectionCollisionThrowsException()
588585
{
589586
$container = new ContainerBuilder();
@@ -596,7 +593,14 @@ public function testSetterInjectionCollisionThrowsException()
596593
(new AutowireRequiredMethodsPass())->process($container);
597594

598595
$pass = new AutowirePass();
599-
$pass->process($container);
596+
597+
try {
598+
$pass->process($container);
599+
} catch (AutowiringFailedException $e) {
600+
}
601+
602+
$this->assertNotNull($e);
603+
$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());
600604
}
601605

602606
/**

Tests/Fixtures/php/services9_as_files.txt

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
6060

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

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

6565
return $instance;
6666

@@ -75,7 +75,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
7575
$this->services['configured_service'] = $instance = new \stdClass();
7676

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

8080
$a->configureStdClass($instance);
8181

@@ -145,7 +145,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
145145
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
146146
// Returns the public 'factory_service' shared service.
147147

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

150150
[Container%s/getFactoryServiceSimpleService.php] => <?php
151151

@@ -155,7 +155,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
155155
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
156156
// Returns the public 'factory_service_simple' shared service.
157157

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

160160
[Container%s/getFactorySimpleService.php] => <?php
161161

@@ -177,7 +177,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
177177
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
178178
// Returns the public 'foo' shared service.
179179

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

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

@@ -214,7 +214,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
214214
$this->factories['foo_bar'] = function () {
215215
// Returns the public 'foo_bar' service.
216216

217-
return new \Bar\FooClass(($this->services['deprecated_service'] ?? $this->load(__DIR__.'/getDeprecatedServiceService.php')));
217+
return new \Bar\FooClass(($this->services['deprecated_service'] ?? $this->load('getDeprecatedServiceService.php')));
218218
};
219219

220220
return $this->factories['foo_bar']();
@@ -232,7 +232,7 @@ $this->services['foo_with_inline'] = $instance = new \Foo();
232232
$a = new \Bar();
233233

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

237237
$instance->setBar($a);
238238

@@ -247,7 +247,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
247247
// Returns the public 'lazy_context' shared service.
248248

249249
return $this->services['lazy_context'] = new \LazyContext(new RewindableGenerator(function () {
250-
yield 'k1' => ($this->services['foo.baz'] ?? $this->load(__DIR__.'/getFoo_BazService.php'));
250+
yield 'k1' => ($this->services['foo.baz'] ?? $this->load('getFoo_BazService.php'));
251251
yield 'k2' => $this;
252252
}, 2), new RewindableGenerator(function () {
253253
return new \EmptyIterator();
@@ -262,7 +262,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
262262
// Returns the public 'lazy_context_ignore_invalid_ref' shared service.
263263

264264
return $this->services['lazy_context_ignore_invalid_ref'] = new \LazyContext(new RewindableGenerator(function () {
265-
yield 0 => ($this->services['foo.baz'] ?? $this->load(__DIR__.'/getFoo_BazService.php'));
265+
yield 0 => ($this->services['foo.baz'] ?? $this->load('getFoo_BazService.php'));
266266
}, 1), new RewindableGenerator(function () {
267267
return new \EmptyIterator();
268268
}, 0));
@@ -279,9 +279,9 @@ include_once ($this->targetDirs[0].'/Fixtures/includes/foo.php');
279279

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

282-
$instance->setBar(($this->services['foo'] ?? $this->load(__DIR__.'/getFooService.php')));
282+
$instance->setBar(($this->services['foo'] ?? $this->load('getFooService.php')));
283283
$instance->setBar(NULL);
284-
$instance->setBar((($this->services['foo'] ?? $this->load(__DIR__.'/getFooService.php'))->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
284+
$instance->setBar((($this->services['foo'] ?? $this->load('getFooService.php'))->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
285285

286286
return $instance;
287287

@@ -326,7 +326,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
326326
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
327327
// Returns the public 'runtime_error' shared service.
328328

329-
return $this->services['runtime_error'] = new \stdClass(($this->privates['errored_definition'] ?? $this->load(__DIR__.'/getErroredDefinitionService.php')));
329+
return $this->services['runtime_error'] = new \stdClass(($this->privates['errored_definition'] ?? $this->load('getErroredDefinitionService.php')));
330330

331331
[Container%s/getServiceFromStaticMethodService.php] => <?php
332332

@@ -347,7 +347,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
347347
// Returns the public 'tagged_iterator' shared service.
348348

349349
return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () {
350-
yield 0 => ($this->services['foo'] ?? $this->load(__DIR__.'/getFooService.php'));
350+
yield 0 => ($this->services['foo'] ?? $this->load('getFooService.php'));
351351
yield 1 => ($this->privates['tagged_iterator_foo'] ?? $this->privates['tagged_iterator_foo'] = new \Bar());
352352
}, 2));
353353

@@ -382,6 +382,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
382382
class ProjectServiceContainer extends Container
383383
{
384384
private $buildParameters;
385+
private $containerDir;
385386
private $parameters;
386387
private $targetDirs = array();
387388

@@ -390,13 +391,14 @@ class ProjectServiceContainer extends Container
390391
*/
391392
protected $privates = array();
392393

393-
public function __construct(array $buildParameters = array())
394+
public function __construct(array $buildParameters = array(), $containerDir = __DIR__)
394395
{
395-
$dir = $this->targetDirs[0] = \dirname(__DIR__);
396+
$dir = $this->targetDirs[0] = \dirname($containerDir);
396397
for ($i = 1; $i <= 5; ++$i) {
397398
$this->targetDirs[$i] = $dir = \dirname($dir);
398399
}
399400
$this->buildParameters = $buildParameters;
401+
$this->containerDir = $containerDir;
400402
$this->parameters = $this->getDefaultParameters();
401403

402404
$this->services = $this->privates = array();
@@ -407,29 +409,29 @@ class ProjectServiceContainer extends Container
407409
'bar' => 'getBarService',
408410
);
409411
$this->fileMap = array(
410-
'BAR' => __DIR__.'/getBAR2Service.php',
411-
'BAR2' => __DIR__.'/getBAR22Service.php',
412-
'bar2' => __DIR__.'/getBar23Service.php',
413-
'baz' => __DIR__.'/getBazService.php',
414-
'configured_service' => __DIR__.'/getConfiguredServiceService.php',
415-
'configured_service_simple' => __DIR__.'/getConfiguredServiceSimpleService.php',
416-
'decorator_service' => __DIR__.'/getDecoratorServiceService.php',
417-
'decorator_service_with_name' => __DIR__.'/getDecoratorServiceWithNameService.php',
418-
'deprecated_service' => __DIR__.'/getDeprecatedServiceService.php',
419-
'factory_service' => __DIR__.'/getFactoryServiceService.php',
420-
'factory_service_simple' => __DIR__.'/getFactoryServiceSimpleService.php',
421-
'foo' => __DIR__.'/getFooService.php',
422-
'foo.baz' => __DIR__.'/getFoo_BazService.php',
423-
'foo_bar' => __DIR__.'/getFooBarService.php',
424-
'foo_with_inline' => __DIR__.'/getFooWithInlineService.php',
425-
'lazy_context' => __DIR__.'/getLazyContextService.php',
426-
'lazy_context_ignore_invalid_ref' => __DIR__.'/getLazyContextIgnoreInvalidRefService.php',
427-
'method_call1' => __DIR__.'/getMethodCall1Service.php',
428-
'new_factory_service' => __DIR__.'/getNewFactoryServiceService.php',
429-
'non_shared_foo' => __DIR__.'/getNonSharedFooService.php',
430-
'runtime_error' => __DIR__.'/getRuntimeErrorService.php',
431-
'service_from_static_method' => __DIR__.'/getServiceFromStaticMethodService.php',
432-
'tagged_iterator' => __DIR__.'/getTaggedIteratorService.php',
412+
'BAR' => 'getBAR2Service.php',
413+
'BAR2' => 'getBAR22Service.php',
414+
'bar2' => 'getBar23Service.php',
415+
'baz' => 'getBazService.php',
416+
'configured_service' => 'getConfiguredServiceService.php',
417+
'configured_service_simple' => 'getConfiguredServiceSimpleService.php',
418+
'decorator_service' => 'getDecoratorServiceService.php',
419+
'decorator_service_with_name' => 'getDecoratorServiceWithNameService.php',
420+
'deprecated_service' => 'getDeprecatedServiceService.php',
421+
'factory_service' => 'getFactoryServiceService.php',
422+
'factory_service_simple' => 'getFactoryServiceSimpleService.php',
423+
'foo' => 'getFooService.php',
424+
'foo.baz' => 'getFoo_BazService.php',
425+
'foo_bar' => 'getFooBarService.php',
426+
'foo_with_inline' => 'getFooWithInlineService.php',
427+
'lazy_context' => 'getLazyContextService.php',
428+
'lazy_context_ignore_invalid_ref' => 'getLazyContextIgnoreInvalidRefService.php',
429+
'method_call1' => 'getMethodCall1Service.php',
430+
'new_factory_service' => 'getNewFactoryServiceService.php',
431+
'non_shared_foo' => 'getNonSharedFooService.php',
432+
'runtime_error' => 'getRuntimeErrorService.php',
433+
'service_from_static_method' => 'getServiceFromStaticMethodService.php',
434+
'tagged_iterator' => 'getTaggedIteratorService.php',
433435
);
434436
$this->aliases = array(
435437
'alias_for_alias' => 'foo',
@@ -456,12 +458,12 @@ class ProjectServiceContainer extends Container
456458

457459
public function getRemovedIds()
458460
{
459-
return require __DIR__.'/removed-ids.php';
461+
return require $this->containerDir.\DIRECTORY_SEPARATOR.'removed-ids.php';
460462
}
461463

462464
protected function load($file, $lazyLoad = true)
463465
{
464-
return require $file;
466+
return require $this->containerDir.\DIRECTORY_SEPARATOR.$file;
465467
}
466468

467469
/**
@@ -471,7 +473,7 @@ class ProjectServiceContainer extends Container
471473
*/
472474
protected function getBarService()
473475
{
474-
$a = ($this->services['foo.baz'] ?? $this->load(__DIR__.'/getFoo_BazService.php'));
476+
$a = ($this->services['foo.baz'] ?? $this->load('getFoo_BazService.php'));
475477

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

@@ -580,6 +582,6 @@ return new \Container%s\ProjectServiceContainer(array(
580582
'container.build_hash' => '%s',
581583
'container.build_id' => '%s',
582584
'container.build_time' => %d,
583-
));
585+
), __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
584586

585587
)

0 commit comments

Comments
 (0)