Skip to content

Commit e4d7c74

Browse files
Merge branch '4.1'
* 4.1: [appveyor] fix [DI] Fix dumping some complex service graphs Revert "minor #28321 [Routing] Fixed the interface description of the url generator interface (Toflar)" Fixed caching of templates in default path on cache warmup added missing LICENSE file remove cache warmers when Twig cache is disabled [Workflow] Make sure we do not run the next transition on an updated state change baseUrl to basePath to fix wrong profiler url [HttpKernel][FrameworkBundle] Fix escaping of serialized payloads passed to test clients chore: rename Appveyor filename Fixed the interface description of the url generator interface Format file size in validation message according to binaryFormat option
2 parents 545c360 + 432487f commit e4d7c74

File tree

24 files changed

+252
-45
lines changed

24 files changed

+252
-45
lines changed

appveyor.yml renamed to .appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ install:
4545
- php composer.phar self-update
4646
- copy /Y .composer\* %APPDATA%\Composer\
4747
- php composer.phar global require --no-progress --no-scripts --no-plugins symfony/flex dev-master
48-
- php .github/build-packages.php %APPVEYOR_REPO_COMMIT%^^ src\Symfony\Bridge\PhpUnit src\Symfony\Contracts
48+
- php .github/build-packages.php "HEAD^" src\Symfony\Bridge\PhpUnit src\Symfony\Contracts
4949
- IF %APPVEYOR_REPO_BRANCH%==master (SET COMPOSER_ROOT_VERSION=dev-master) ELSE (SET COMPOSER_ROOT_VERSION=%APPVEYOR_REPO_BRANCH%.x-dev)
5050
- php composer.phar update --no-progress --no-suggest --ansi
5151
- php phpunit install

.github/build-packages.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
}
77
chdir(dirname(__DIR__));
88

9+
$json = ltrim(file_get_contents('composer.json'));
10+
if ($json !== $package = preg_replace('/\n "repositories": \[\n.*?\n \],/s', '', $json)) {
11+
file_put_contents('composer.json', $package);
12+
}
13+
914
$dirs = $_SERVER['argv'];
1015
array_shift($dirs);
11-
$mergeBase = trim(shell_exec(sprintf('git merge-base %s HEAD', array_shift($dirs))));
16+
$mergeBase = trim(shell_exec(sprintf('git merge-base "%s" HEAD', array_shift($dirs))));
1217

1318
$packages = array();
1419
$flags = \PHP_VERSION_ID >= 50400 ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE : 0;
1520

1621
foreach ($dirs as $k => $dir) {
17-
if (!system("git diff --name-only \"$mergeBase\" -- $dir", $exitStatus)) {
22+
if (!system("git diff --name-only $mergeBase -- $dir", $exitStatus)) {
1823
if ($exitStatus) {
1924
exit($exitStatus);
2025
}
@@ -74,7 +79,6 @@
7479
'type' => 'composer',
7580
'url' => 'file://'.str_replace(DIRECTORY_SEPARATOR, '/', dirname(__DIR__)).'/',
7681
));
77-
$json = preg_replace('/\n "repositories": \[\n.*?\n \],/s', '', $json);
7882
$json = rtrim(json_encode(array('repositories' => $package->repositories), $flags), "\n}").','.substr($json, 1);
7983
file_put_contents('composer.json', $json);
8084
}

src/Symfony/Bundle/FrameworkBundle/Client.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ protected function doRequestInProcess($request)
161161
*/
162162
protected function getScript($request)
163163
{
164-
$kernel = str_replace("'", "\\'", serialize($this->kernel));
165-
$request = str_replace("'", "\\'", serialize($request));
164+
$kernel = var_export(serialize($this->kernel), true);
165+
$request = var_export(serialize($request), true);
166166
$errorReporting = error_reporting();
167167

168168
$requires = '';
@@ -171,7 +171,7 @@ protected function getScript($request)
171171
$r = new \ReflectionClass($class);
172172
$file = \dirname(\dirname($r->getFileName())).'/autoload.php';
173173
if (file_exists($file)) {
174-
$requires .= "require_once '".str_replace("'", "\\'", $file)."';\n";
174+
$requires .= 'require_once '.var_export($file, true).";\n";
175175
}
176176
}
177177
}
@@ -180,7 +180,7 @@ protected function getScript($request)
180180
throw new \RuntimeException('Composer autoloader not found.');
181181
}
182182

183-
$requires .= "require_once '".str_replace("'", "\\'", (new \ReflectionObject($this->kernel))->getFileName())."';\n";
183+
$requires .= 'require_once '.var_export((new \ReflectionObject($this->kernel))->getFileName(), true).";\n";
184184

185185
$profilerCode = '';
186186
if ($this->profiler) {
@@ -194,11 +194,11 @@ protected function getScript($request)
194194
195195
$requires
196196
197-
\$kernel = unserialize('$kernel');
197+
\$kernel = unserialize($kernel);
198198
\$kernel->boot();
199199
$profilerCode
200200
201-
\$request = unserialize('$request');
201+
\$request = unserialize($request);
202202
EOF;
203203

204204
return $code.$this->getHandleScript();

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,15 @@ public function process(ContainerBuilder $container)
4747
$coreThemePath = \dirname(\dirname($reflClass->getFileName())).'/Resources/views/Form';
4848
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', array($coreThemePath));
4949

50-
$paths = $container->getDefinition('twig.cache_warmer')->getArgument(2);
50+
$paths = $container->getDefinition('twig.template_iterator')->getArgument(2);
5151
$paths[$coreThemePath] = null;
52-
$container->getDefinition('twig.cache_warmer')->replaceArgument(2, $paths);
5352
$container->getDefinition('twig.template_iterator')->replaceArgument(2, $paths);
53+
54+
if ($container->hasDefinition('twig.cache_warmer')) {
55+
$paths = $container->getDefinition('twig.cache_warmer')->getArgument(2);
56+
$paths[$coreThemePath] = null;
57+
$container->getDefinition('twig.cache_warmer')->replaceArgument(2, $paths);
58+
}
5459
}
5560

5661
if ($container->has('router')) {

src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

+5
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ public function load(array $configs, ContainerBuilder $container)
153153
$container->registerForAutoconfiguration(ExtensionInterface::class)->addTag('twig.extension');
154154
$container->registerForAutoconfiguration(LoaderInterface::class)->addTag('twig.loader');
155155
$container->registerForAutoconfiguration(RuntimeExtensionInterface::class)->addTag('twig.runtime');
156+
157+
if (false === $config['cache']) {
158+
$container->removeDefinition('twig.cache_warmer');
159+
$container->removeDefinition('twig.template_cache_warmer');
160+
}
156161
}
157162

158163
private function getBundleTemplatePaths(ContainerBuilder $container, array $config)

src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<argument type="service" id="kernel" />
4242
<argument>%kernel.root_dir%</argument>
4343
<argument type="collection" /> <!-- Twig paths -->
44+
<argument>%twig.default_path%</argument>
4445
</service>
4546

4647
<service id="twig.template_cache_warmer" class="Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheWarmer">

src/Symfony/Bundle/TwigBundle/TemplateIterator.php

+15-8
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ class TemplateIterator implements \IteratorAggregate
2525
private $rootDir;
2626
private $templates;
2727
private $paths;
28+
private $defaultPath;
2829

2930
/**
30-
* @param KernelInterface $kernel A KernelInterface instance
31-
* @param string $rootDir The directory where global templates can be stored
32-
* @param array $paths Additional Twig paths to warm
31+
* @param KernelInterface $kernel A KernelInterface instance
32+
* @param string $rootDir The directory where global templates can be stored
33+
* @param array $paths Additional Twig paths to warm
34+
* @param string $defaultPath The directory where global templates can be stored
3335
*/
34-
public function __construct(KernelInterface $kernel, string $rootDir, array $paths = array())
36+
public function __construct(KernelInterface $kernel, string $rootDir, array $paths = array(), string $defaultPath = null)
3537
{
3638
$this->kernel = $kernel;
3739
$this->rootDir = $rootDir;
3840
$this->paths = $paths;
41+
$this->defaultPath = $defaultPath;
3942
}
4043

4144
/**
@@ -47,7 +50,10 @@ public function getIterator()
4750
return $this->templates;
4851
}
4952

50-
$this->templates = $this->findTemplatesInDirectory($this->rootDir.'/Resources/views');
53+
$this->templates = array_merge(
54+
$this->findTemplatesInDirectory($this->rootDir.'/Resources/views'),
55+
$this->findTemplatesInDirectory($this->defaultPath, null, array('bundles'))
56+
);
5157
foreach ($this->kernel->getBundles() as $bundle) {
5258
$name = $bundle->getName();
5359
if ('Bundle' === substr($name, -6)) {
@@ -57,7 +63,8 @@ public function getIterator()
5763
$this->templates = array_merge(
5864
$this->templates,
5965
$this->findTemplatesInDirectory($bundle->getPath().'/Resources/views', $name),
60-
$this->findTemplatesInDirectory($this->rootDir.'/'.$bundle->getName().'/views', $name)
66+
$this->findTemplatesInDirectory($this->rootDir.'/'.$bundle->getName().'/views', $name),
67+
$this->findTemplatesInDirectory($this->defaultPath.'/bundles/'.$bundle->getName(), $name)
6168
);
6269
}
6370

@@ -76,14 +83,14 @@ public function getIterator()
7683
*
7784
* @return array
7885
*/
79-
private function findTemplatesInDirectory($dir, $namespace = null)
86+
private function findTemplatesInDirectory($dir, $namespace = null, array $excludeDirs = array())
8087
{
8188
if (!is_dir($dir)) {
8289
return array();
8390
}
8491

8592
$templates = array();
86-
foreach (Finder::create()->files()->followLinks()->in($dir) as $file) {
93+
foreach (Finder::create()->files()->followLinks()->in($dir)->exclude($excludeDirs) as $file) {
8794
$templates[] = (null !== $namespace ? '@'.$namespace.'/' : '').str_replace('\\', '/', $file->getRelativePathname());
8895
}
8996

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a layout

src/Symfony/Bundle/TwigBundle/Tests/TemplateIteratorTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ public function testGetIterator()
2525
$kernel->expects($this->any())->method('getBundles')->will($this->returnValue(array(
2626
$bundle,
2727
)));
28-
$iterator = new TemplateIterator($kernel, __DIR__.'/Fixtures/templates', array(__DIR__.'/Fixtures/templates/Foo' => 'Foo'));
28+
$iterator = new TemplateIterator($kernel, __DIR__.'/Fixtures/templates', array(__DIR__.'/Fixtures/templates/Foo' => 'Foo'), __DIR__.'/DependencyInjection/Fixtures/templates');
2929

3030
$sorted = iterator_to_array($iterator);
3131
sort($sorted);
3232
$this->assertEquals(
3333
array(
3434
'@Bar/index.html.twig',
35+
'@Bar/layout.html.twig',
3536
'@Foo/index.html.twig',
3637
'layout.html.twig',
3738
'sub/sub.html.twig',

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ private function addServiceInlinedDefinitions(string $id, Definition $definition
528528

529529
$code .= $this->addNewInstance($def, ' $'.$name.' = ', $id);
530530

531-
if (!$this->hasReference($id, array($def->getProperties(), $def->getMethodCalls(), $def->getConfigurator()), true)) {
531+
if (!$this->hasReference($id, array($def->getProperties(), $def->getMethodCalls(), $def->getConfigurator()), true, $inlinedDefinitions)) {
532532
$code .= $this->addServiceProperties($def, $name);
533533
$code .= $this->addServiceMethodCalls($def, $name);
534534
$code .= $this->addServiceConfigurator($def, $name);
@@ -657,7 +657,7 @@ private function addServiceInlinedDefinitionsSetup(string $id, Definition $defin
657657
{
658658
$code = '';
659659
foreach ($inlinedDefinitions as $def) {
660-
if ($definition === $def || !$this->hasReference($id, array($def->getProperties(), $def->getMethodCalls(), $def->getConfigurator()), true)) {
660+
if ($definition === $def || !$this->hasReference($id, array($def->getProperties(), $def->getMethodCalls(), $def->getConfigurator()), true, $inlinedDefinitions)) {
661661
continue;
662662
}
663663

@@ -775,6 +775,7 @@ protected function {$methodName}($lazyInitialization)
775775

776776
$inlinedDefinitions = $this->getDefinitionsFromArguments(array($definition));
777777
$constructorDefinitions = $this->getDefinitionsFromArguments(array($definition->getArguments(), $definition->getFactory()));
778+
unset($constructorDefinitions[$definition]); // ensures $definition will be last
778779
$otherDefinitions = new \SplObjectStorage();
779780
$serviceCalls = array();
780781

@@ -1091,6 +1092,9 @@ private function addRemovedIds(): string
10911092
$ids = array_keys($ids);
10921093
sort($ids);
10931094
foreach ($ids as $id) {
1095+
if (preg_match('/^\.\d+_[^~]++~[._a-zA-Z\d]{7}$/', $id)) {
1096+
continue;
1097+
}
10941098
$code .= ' '.$this->doExport($id)." => true,\n";
10951099
}
10961100

@@ -1450,15 +1454,15 @@ private function getDefinitionsFromArguments(array $arguments, bool $isConstruct
14501454
return $definitions;
14511455
}
14521456

1453-
private function hasReference(string $id, array $arguments, bool $deep = false, array &$visited = array()): bool
1457+
private function hasReference(string $id, array $arguments, bool $deep = false, \SplObjectStorage $inlinedDefinitions = null, array &$visited = array()): bool
14541458
{
14551459
if (!isset($this->circularReferences[$id])) {
14561460
return false;
14571461
}
14581462

14591463
foreach ($arguments as $argument) {
14601464
if (\is_array($argument)) {
1461-
if ($this->hasReference($id, $argument, $deep, $visited)) {
1465+
if ($this->hasReference($id, $argument, $deep, $inlinedDefinitions, $visited)) {
14621466
return true;
14631467
}
14641468

@@ -1477,6 +1481,9 @@ private function hasReference(string $id, array $arguments, bool $deep = false,
14771481

14781482
$service = $this->container->getDefinition($argumentId);
14791483
} elseif ($argument instanceof Definition) {
1484+
if (isset($inlinedDefinitions[$argument])) {
1485+
return true;
1486+
}
14801487
$service = $argument;
14811488
} else {
14821489
continue;
@@ -1488,7 +1495,7 @@ private function hasReference(string $id, array $arguments, bool $deep = false,
14881495
continue;
14891496
}
14901497

1491-
if ($this->hasReference($id, array($service->getArguments(), $service->getFactory(), $service->getProperties(), $service->getMethodCalls(), $service->getConfigurator()), $deep, $visited)) {
1498+
if ($this->hasReference($id, array($service->getArguments(), $service->getFactory(), $service->getProperties(), $service->getMethodCalls(), $service->getConfigurator()), $deep, $inlinedDefinitions, $visited)) {
14921499
return true;
14931500
}
14941501
}

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults)
414414
{
415415
$definitions = array();
416416
$count = 0;
417-
$suffix = ContainerBuilder::hash($file);
417+
$suffix = '~'.ContainerBuilder::hash($file);
418418

419419
$xpath = new \DOMXPath($xml);
420420
$xpath->registerNamespace('container', self::NS);
@@ -424,7 +424,7 @@ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults)
424424
foreach ($nodes as $node) {
425425
if ($services = $this->getChildren($node, 'service')) {
426426
// give it a unique name
427-
$id = sprintf('.%d_%s', ++$count, preg_replace('/^.*\\\\/', '', $services[0]->getAttribute('class')).'~'.$suffix);
427+
$id = sprintf('.%d_%s', ++$count, preg_replace('/^.*\\\\/', '', $services[0]->getAttribute('class')).$suffix);
428428
$node->setAttribute('id', $id);
429429
$node->setAttribute('service', $id);
430430

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function load($resource, $type = null)
144144

145145
// services
146146
$this->anonymousServicesCount = 0;
147-
$this->anonymousServicesSuffix = ContainerBuilder::hash($path);
147+
$this->anonymousServicesSuffix = '~'.ContainerBuilder::hash($path);
148148
$this->setCurrentDir(\dirname($path));
149149
try {
150150
$this->parseDefinitions($content, $path);

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,21 @@ public function provideAlmostCircular()
885885
yield array('private');
886886
}
887887

888+
public function testDeepServiceGraph()
889+
{
890+
$container = new ContainerBuilder();
891+
892+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
893+
$loader->load('services_deep_graph.yml');
894+
895+
$container->compile();
896+
897+
$dumper = new PhpDumper($container);
898+
$dumper->dump();
899+
900+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_deep_graph.php', $dumper->dump());
901+
}
902+
888903
public function testHotPathOptimizations()
889904
{
890905
$container = include self::$fixturesPath.'/containers/container_inline_requires.php';

0 commit comments

Comments
 (0)