From a84efa7058e12708d7f556f4afd776b285f8730b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 22 Nov 2017 18:21:48 +0100 Subject: [PATCH 01/12] [FrameworkBundle] Fix AssetsInstallCommand --- .../Bundle/FrameworkBundle/Command/AssetsInstallCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 0f5e072378..69fb057804 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -262,6 +262,7 @@ EOT private function symlink($originDir, $targetDir, $relative = false) { if ($relative) { + $this->filesystem->mkdir(dirname($targetDir)); $originDir = $this->filesystem->makePathRelative($originDir, realpath(dirname($targetDir))); } $this->filesystem->symlink($originDir, $targetDir); From dc7286625b715013a1790475190f49ba1a28fee5 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Tue, 21 Nov 2017 01:48:50 -0500 Subject: [PATCH 02/12] Update translation commands to work with default paths --- .../Command/TranslationDebugCommand.php | 53 ++++++++++++++----- .../Command/TranslationUpdateCommand.php | 45 +++++++++++----- .../Resources/config/console.xml | 4 ++ .../Command/TranslationDebugCommandTest.php | 19 ++++++- .../Command/TranslationUpdateCommandTest.php | 29 +++++++++- .../DependencyInjection/TranslatorPass.php | 11 +++- 6 files changed, 131 insertions(+), 30 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php index d80e2f4de9..bb0b02a81f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php @@ -45,13 +45,17 @@ class TranslationDebugCommand extends ContainerAwareCommand private $translator; private $reader; private $extractor; + private $defaultTransPath; + private $defaultViewsPath; /** * @param TranslatorInterface $translator * @param TranslationReaderInterface $reader * @param ExtractorInterface $extractor + * @param string $defaultTransPath + * @param string $defaultViewsPath */ - public function __construct($translator = null, TranslationReaderInterface $reader = null, ExtractorInterface $extractor = null) + public function __construct($translator = null, TranslationReaderInterface $reader = null, ExtractorInterface $extractor = null, $defaultTransPath = null, $defaultViewsPath = null) { if (!$translator instanceof TranslatorInterface) { @trigger_error(sprintf('%s() expects an instance of "%s" as first argument since version 3.4. Not passing it is deprecated and will throw a TypeError in 4.0.', __METHOD__, TranslatorInterface::class), E_USER_DEPRECATED); @@ -66,6 +70,8 @@ class TranslationDebugCommand extends ContainerAwareCommand $this->translator = $translator; $this->reader = $reader; $this->extractor = $extractor; + $this->defaultTransPath = $defaultTransPath; + $this->defaultViewsPath = $defaultViewsPath; } /** @@ -153,20 +159,34 @@ EOF /** @var KernelInterface $kernel */ $kernel = $this->getApplication()->getKernel(); - // Define Root Path to App folder - $transPaths = array($kernel->getRootDir().'/Resources/'); + // Define Root Paths + $transPaths = array($kernel->getRootDir().'/Resources/translations'); + if ($this->defaultTransPath) { + $transPaths[] = $this->defaultTransPath; + } + $viewsPaths = array($kernel->getRootDir().'/Resources/views'); + if ($this->defaultViewsPath) { + $viewsPaths[] = $this->defaultViewsPath; + } // Override with provided Bundle info if (null !== $input->getArgument('bundle')) { try { $bundle = $kernel->getBundle($input->getArgument('bundle')); - $transPaths = array( - $bundle->getPath().'/Resources/', - sprintf('%s/Resources/%s/', $kernel->getRootDir(), $bundle->getName()), - ); + $transPaths = array($bundle->getPath().'/Resources/translations'); + if ($this->defaultTransPath) { + $transPaths[] = $this->defaultTransPath.'/'.$bundle->getName(); + } + $transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(), $bundle->getName()); + $viewsPaths = array($bundle->getPath().'/Resources/views'); + if ($this->defaultViewsPath) { + $viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName(); + } + $viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(), $bundle->getName()); } catch (\InvalidArgumentException $e) { // such a bundle does not exist, so treat the argument as path - $transPaths = array($input->getArgument('bundle').'/Resources/'); + $transPaths = array($input->getArgument('bundle').'/Resources/translations'); + $viewsPaths = array($input->getArgument('bundle').'/Resources/views'); if (!is_dir($transPaths[0])) { throw new \InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0])); @@ -174,13 +194,21 @@ EOF } } elseif ($input->getOption('all')) { foreach ($kernel->getBundles() as $bundle) { - $transPaths[] = $bundle->getPath().'/Resources/'; - $transPaths[] = sprintf('%s/Resources/%s/', $kernel->getRootDir(), $bundle->getName()); + $transPaths[] = $bundle->getPath().'/Resources/translations'; + if ($this->defaultTransPath) { + $transPaths[] = $this->defaultTransPath.'/'.$bundle->getName(); + } + $transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(), $bundle->getName()); + $viewsPaths[] = $bundle->getPath().'/Resources/views'; + if ($this->defaultViewsPath) { + $viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName(); + } + $viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(), $bundle->getName()); } } // Extract used messages - $extractedCatalogue = $this->extractMessages($locale, $transPaths); + $extractedCatalogue = $this->extractMessages($locale, $viewsPaths); // Load defined messages $currentCatalogue = $this->loadCurrentMessages($locale, $transPaths); @@ -310,7 +338,6 @@ EOF { $extractedCatalogue = new MessageCatalogue($locale); foreach ($transPaths as $path) { - $path = $path.'views'; if (is_dir($path)) { $this->extractor->extract($path, $extractedCatalogue); } @@ -329,7 +356,6 @@ EOF { $currentCatalogue = new MessageCatalogue($locale); foreach ($transPaths as $path) { - $path = $path.'translations'; if (is_dir($path)) { $this->reader->read($path, $currentCatalogue); } @@ -355,7 +381,6 @@ EOF $fallbackCatalogue = new MessageCatalogue($fallbackLocale); foreach ($transPaths as $path) { - $path = $path.'translations'; if (is_dir($path)) { $this->reader->read($path, $fallbackCatalogue); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index 9813b82fcf..768617c826 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\FrameworkBundle\Command; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Translation\Catalogue\TargetOperation; use Symfony\Component\Translation\Catalogue\MergeOperation; use Symfony\Component\Console\Input\InputInterface; @@ -39,14 +40,18 @@ class TranslationUpdateCommand extends ContainerAwareCommand private $reader; private $extractor; private $defaultLocale; + private $defaultTransPath; + private $defaultViewsPath; /** * @param TranslationWriterInterface $writer * @param TranslationReaderInterface $reader * @param ExtractorInterface $extractor * @param string $defaultLocale + * @param string $defaultTransPath + * @param string $defaultViewsPath */ - public function __construct($writer = null, TranslationReaderInterface $reader = null, ExtractorInterface $extractor = null, $defaultLocale = null) + public function __construct($writer = null, TranslationReaderInterface $reader = null, ExtractorInterface $extractor = null, $defaultLocale = null, $defaultTransPath = null, $defaultViewsPath = null) { if (!$writer instanceof TranslationWriterInterface) { @trigger_error(sprintf('%s() expects an instance of "%s" as first argument since version 3.4. Not passing it is deprecated and will throw a TypeError in 4.0.', __METHOD__, TranslationWriterInterface::class), E_USER_DEPRECATED); @@ -62,6 +67,8 @@ class TranslationUpdateCommand extends ContainerAwareCommand $this->reader = $reader; $this->extractor = $extractor; $this->defaultLocale = $defaultLocale; + $this->defaultTransPath = $defaultTransPath; + $this->defaultViewsPath = $defaultViewsPath; } /** @@ -149,24 +156,39 @@ EOF return 1; } + /** @var KernelInterface $kernel */ $kernel = $this->getApplication()->getKernel(); - // Define Root Path to App folder - $transPaths = array($kernel->getRootDir().'/Resources/'); + // Define Root Paths + $transPaths = array($kernel->getRootDir().'/Resources/translations'); + if ($this->defaultTransPath) { + $transPaths[] = $this->defaultTransPath; + } + $viewsPaths = array($kernel->getRootDir().'/Resources/views'); + if ($this->defaultViewsPath) { + $viewsPaths[] = $this->defaultViewsPath; + } $currentName = 'app folder'; // Override with provided Bundle info if (null !== $input->getArgument('bundle')) { try { $foundBundle = $kernel->getBundle($input->getArgument('bundle')); - $transPaths = array( - $foundBundle->getPath().'/Resources/', - sprintf('%s/Resources/%s/', $kernel->getRootDir(), $foundBundle->getName()), - ); + $transPaths = array($foundBundle->getPath().'/Resources/translations'); + if ($this->defaultTransPath) { + $transPaths[] = $this->defaultTransPath.'/'.$foundBundle->getName(); + } + $transPaths[] = sprintf('%s/Resources/%s/translations', $kernel->getRootDir(), $foundBundle->getName()); + $viewsPaths = array($foundBundle->getPath().'/Resources/views'); + if ($this->defaultViewsPath) { + $viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$foundBundle->getName(); + } + $viewsPaths[] = sprintf('%s/Resources/%s/views', $kernel->getRootDir(), $foundBundle->getName()); $currentName = $foundBundle->getName(); } catch (\InvalidArgumentException $e) { // such a bundle does not exist, so treat the argument as path - $transPaths = array($input->getArgument('bundle').'/Resources/'); + $transPaths = array($input->getArgument('bundle').'/Resources/translations'); + $viewsPaths = array($input->getArgument('bundle').'/Resources/views'); $currentName = $transPaths[0]; if (!is_dir($transPaths[0])) { @@ -188,8 +210,7 @@ EOF $prefix = ''; } $this->extractor->setPrefix($prefix); - foreach ($transPaths as $path) { - $path .= 'views'; + foreach ($viewsPaths as $path) { if (is_dir($path)) { $this->extractor->extract($path, $extractedCatalogue); } @@ -199,7 +220,6 @@ EOF $currentCatalogue = new MessageCatalogue($input->getArgument('locale')); $errorIo->comment('Loading translation files...'); foreach ($transPaths as $path) { - $path .= 'translations'; if (is_dir($path)) { $this->reader->read($path, $currentCatalogue); } @@ -267,14 +287,13 @@ EOF $bundleTransPath = false; foreach ($transPaths as $path) { - $path .= 'translations'; if (is_dir($path)) { $bundleTransPath = $path; } } if (!$bundleTransPath) { - $bundleTransPath = end($transPaths).'translations'; + $bundleTransPath = end($transPaths); } $this->writer->write($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath, 'default_locale' => $this->defaultLocale)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml index 9484b985bf..34f47a0599 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml @@ -78,6 +78,8 @@ + %translator.default_path% + @@ -86,6 +88,8 @@ %kernel.default_locale% + %translator.default_path% + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php index 7e516c7cc5..a13d9a41e3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php @@ -64,6 +64,21 @@ class TranslationDebugCommandTest extends TestCase $this->assertRegExp('/unused/', $tester->getDisplay()); } + public function testDebugDefaultRootDirectory() + { + $this->fs->remove($this->translationDir); + $this->fs = new Filesystem(); + $this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true); + $this->fs->mkdir($this->translationDir.'/translations'); + $this->fs->mkdir($this->translationDir.'/templates'); + + $tester = $this->createCommandTester(array('foo' => 'foo'), array('bar' => 'bar')); + $tester->execute(array('locale' => 'en')); + + $this->assertRegExp('/missing/', $tester->getDisplay()); + $this->assertRegExp('/unused/', $tester->getDisplay()); + } + public function testDebugCustomDirectory() { $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); @@ -100,6 +115,8 @@ class TranslationDebugCommandTest extends TestCase $this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true); $this->fs->mkdir($this->translationDir.'/Resources/translations'); $this->fs->mkdir($this->translationDir.'/Resources/views'); + $this->fs->mkdir($this->translationDir.'/translations'); + $this->fs->mkdir($this->translationDir.'/templates'); } protected function tearDown() @@ -174,7 +191,7 @@ class TranslationDebugCommandTest extends TestCase ->method('getContainer') ->will($this->returnValue($this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock())); - $command = new TranslationDebugCommand($translator, $loader, $extractor); + $command = new TranslationDebugCommand($translator, $loader, $extractor, $this->translationDir.'/translations', $this->translationDir.'/templates'); $application = new Application($kernel); $application->add($command); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php index 2cb8e0e259..8a1b2b668e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php @@ -31,6 +31,19 @@ class TranslationUpdateCommandTest extends TestCase $this->assertRegExp('/1 message was successfully extracted/', $tester->getDisplay()); } + public function testDumpMessagesAndCleanInRootDirectory() + { + $this->fs->remove($this->translationDir); + $this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true); + $this->fs->mkdir($this->translationDir.'/translations'); + $this->fs->mkdir($this->translationDir.'/templates'); + + $tester = $this->createCommandTester(array('messages' => array('foo' => 'foo'))); + $tester->execute(array('command' => 'translation:update', 'locale' => 'en', '--dump-messages' => true, '--clean' => true)); + $this->assertRegExp('/foo/', $tester->getDisplay()); + $this->assertRegExp('/1 message was successfully extracted/', $tester->getDisplay()); + } + public function testDumpTwoMessagesAndClean() { $tester = $this->createCommandTester(array('messages' => array('foo' => 'foo', 'bar' => 'bar'))); @@ -55,6 +68,18 @@ class TranslationUpdateCommandTest extends TestCase $this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay()); } + public function testWriteMessagesInRootDirectory() + { + $this->fs->remove($this->translationDir); + $this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true); + $this->fs->mkdir($this->translationDir.'/translations'); + $this->fs->mkdir($this->translationDir.'/templates'); + + $tester = $this->createCommandTester(array('messages' => array('foo' => 'foo'))); + $tester->execute(array('command' => 'translation:update', 'locale' => 'en', '--force' => true)); + $this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay()); + } + public function testWriteMessagesForSpecificDomain() { $tester = $this->createCommandTester(array('messages' => array('foo' => 'foo'), 'mydomain' => array('bar' => 'bar'))); @@ -68,6 +93,8 @@ class TranslationUpdateCommandTest extends TestCase $this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true); $this->fs->mkdir($this->translationDir.'/Resources/translations'); $this->fs->mkdir($this->translationDir.'/Resources/views'); + $this->fs->mkdir($this->translationDir.'/translations'); + $this->fs->mkdir($this->translationDir.'/templates'); } protected function tearDown() @@ -152,7 +179,7 @@ class TranslationUpdateCommandTest extends TestCase ->method('getContainer') ->will($this->returnValue($this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock())); - $command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en'); + $command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en', $this->translationDir.'/translations', $this->translationDir.'/templates'); $application = new Application($kernel); $application->add($command); diff --git a/src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php b/src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php index 07fc9f68f0..a5e4097843 100644 --- a/src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php +++ b/src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php @@ -21,8 +21,10 @@ class TranslatorPass implements CompilerPassInterface private $translatorServiceId; private $readerServiceId; private $loaderTag; + private $debugCommandServiceId; + private $updateCommandServiceId; - public function __construct($translatorServiceId = 'translator.default', $readerServiceId = 'translation.loader', $loaderTag = 'translation.loader') + public function __construct($translatorServiceId = 'translator.default', $readerServiceId = 'translation.loader', $loaderTag = 'translation.loader', $debugCommandServiceId = 'console.command.translation_debug', $updateCommandServiceId = 'console.command.translation_update') { if ('translation.loader' === $readerServiceId && 2 > func_num_args()) { @trigger_error('The default value for $readerServiceId will change in 4.0 to "translation.reader".', E_USER_DEPRECATED); @@ -31,6 +33,8 @@ class TranslatorPass implements CompilerPassInterface $this->translatorServiceId = $translatorServiceId; $this->readerServiceId = $readerServiceId; $this->loaderTag = $loaderTag; + $this->debugCommandServiceId = $debugCommandServiceId; + $this->updateCommandServiceId = $updateCommandServiceId; } public function process(ContainerBuilder $container) @@ -75,5 +79,10 @@ class TranslatorPass implements CompilerPassInterface ->replaceArgument(0, ServiceLocatorTagPass::register($container, $loaderRefs)) ->replaceArgument(3, $loaders) ; + + if ($container->hasParameter('twig.default_path')) { + $container->getDefinition($this->debugCommandServiceId)->replaceArgument(4, $container->getParameter('twig.default_path')); + $container->getDefinition($this->updateCommandServiceId)->replaceArgument(5, $container->getParameter('twig.default_path')); + } } } From b34d5b77a4a44db4db704987fbda6caebed5858a Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Thu, 23 Nov 2017 12:03:37 +0000 Subject: [PATCH 03/12] `resolveEnvPlaceholders` will return a mixed value --- src/Symfony/Component/DependencyInjection/ContainerBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index de3e84823d..c3aee4e6fd 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -1286,7 +1286,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface * true to resolve to the actual values of the referenced env vars * @param array &$usedEnvs Env vars found while resolving are added to this array * - * @return string The string with env parameters resolved + * @return mixed The value with env parameters resolved if a string or an array is passed */ public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs = null) { From c429c3346a7c7dea1f00ca8fdcb5698d5c523a93 Mon Sep 17 00:00:00 2001 From: Jerzy Zawadzki Date: Wed, 22 Nov 2017 14:58:23 +0100 Subject: [PATCH 04/12] Make search in debug:container command case-insensitive --- .../Bundle/FrameworkBundle/Command/ContainerDebugCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 21d1e6d3c9..a9c5663eec 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -217,9 +217,8 @@ EOF { $serviceIds = $builder->getServiceIds(); $foundServiceIds = array(); - $name = strtolower($name); foreach ($serviceIds as $serviceId) { - if (false === strpos($serviceId, $name)) { + if (false === stripos($serviceId, $name)) { continue; } $foundServiceIds[] = $serviceId; From 5998e9d7b5b71b93f9f87e69fea336480c263ed0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 22 Nov 2017 15:32:31 +0100 Subject: [PATCH 05/12] [Routing] Fix "config-file-relative" annotation loader resources --- .../Routing/Loader/AnnotationDirectoryLoader.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php index 616d01ef4c..4574a0201c 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php @@ -34,7 +34,9 @@ class AnnotationDirectoryLoader extends AnnotationFileLoader */ public function load($path, $type = null) { - $dir = $this->locator->locate($path); + if (!is_dir($dir = $this->locator->locate($path))) { + return parent::supports($path, $type) ? parent::load($path, $type) : new RouteCollection(); + } $collection = new RouteCollection(); $collection->addResource(new DirectoryResource($dir, '/\.php$/')); @@ -74,16 +76,18 @@ class AnnotationDirectoryLoader extends AnnotationFileLoader */ public function supports($resource, $type = null) { - if (!is_string($resource)) { + if ('annotation' === $type) { + return true; + } + + if ($type || !is_string($resource)) { return false; } try { - $path = $this->locator->locate($resource); + return is_dir($this->locator->locate($resource)); } catch (\Exception $e) { return false; } - - return is_dir($path) && (!$type || 'annotation' === $type); } } From ceba2396620b7599eb85f6a1b3d3846c92e1770c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 23 Nov 2017 07:49:31 -0800 Subject: [PATCH 06/12] removed some phpdocs --- .../FrameworkBundle/Command/TranslationDebugCommand.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php index bb0b02a81f..2ea2b122ff 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php @@ -48,13 +48,6 @@ class TranslationDebugCommand extends ContainerAwareCommand private $defaultTransPath; private $defaultViewsPath; - /** - * @param TranslatorInterface $translator - * @param TranslationReaderInterface $reader - * @param ExtractorInterface $extractor - * @param string $defaultTransPath - * @param string $defaultViewsPath - */ public function __construct($translator = null, TranslationReaderInterface $reader = null, ExtractorInterface $extractor = null, $defaultTransPath = null, $defaultViewsPath = null) { if (!$translator instanceof TranslatorInterface) { From 4add28b51805305d0aeef3e3a17be2ec08fa7f81 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 22 Nov 2017 16:06:09 +0100 Subject: [PATCH 07/12] [*Bundle] Replace some kernel.root_dir by kernel.project_dir --- .../Resources/config/services.xml | 1 + .../Templating/Helper/CodeHelper.php | 2 +- .../WebProfilerExtension.php | 18 ------------------ .../Resources/config/profiler.xml | 4 ++-- .../WebProfilerExtensionTest.php | 1 + .../Bundle/WebProfilerBundle/composer.json | 2 +- 6 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml index f5c44432a3..6fbfe512d5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml @@ -56,6 +56,7 @@ %kernel.root_dir%/Resources %kernel.root_dir% + %kernel.project_dir% diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index fc17906330..e8871841d8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -31,7 +31,7 @@ class CodeHelper extends Helper public function __construct($fileLinkFormat, $rootDir, $charset) { $this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); - $this->rootDir = str_replace('\\', '/', $rootDir).'/'; + $this->rootDir = str_replace('\\', '/', dirname($rootDir)).'/'; $this->charset = $charset; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php index b0db2e3bc8..7a17e7fb10 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php @@ -53,24 +53,6 @@ class WebProfilerExtension extends Extension $container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']); $container->setParameter('web_profiler.debug_toolbar.mode', $config['toolbar'] ? WebDebugToolbarListener::ENABLED : WebDebugToolbarListener::DISABLED); } - - $baseDir = array(); - $rootDir = $container->getParameter('kernel.root_dir'); - $rootDir = explode(DIRECTORY_SEPARATOR, realpath($rootDir) ?: $rootDir); - $bundleDir = explode(DIRECTORY_SEPARATOR, __DIR__); - for ($i = 0; isset($rootDir[$i], $bundleDir[$i]); ++$i) { - if ($rootDir[$i] !== $bundleDir[$i]) { - break; - } - $baseDir[] = $rootDir[$i]; - } - $baseDir = implode(DIRECTORY_SEPARATOR, $baseDir); - - $profilerController = $container->getDefinition('web_profiler.controller.profiler'); - $profilerController->replaceArgument(6, $baseDir); - - $fileLinkFormatter = $container->getDefinition('debug.file_link_formatter'); - $fileLinkFormatter->replaceArgument(2, $baseDir); } /** diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml index 4c659b6281..85634882bd 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml @@ -14,7 +14,7 @@ %data_collector.templates% %web_profiler.debug_toolbar.position% - null + %kernel.project_dir% @@ -55,7 +55,7 @@ %debug.file_link_format% - null + %kernel.project_dir% /_profiler/open?file=%%f&line=%%l#line%%l diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php index fbb3ca0720..67726a0a13 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php @@ -60,6 +60,7 @@ class WebProfilerExtensionTest extends TestCase $this->container->setParameter('kernel.bundles', array()); $this->container->setParameter('kernel.cache_dir', __DIR__); $this->container->setParameter('kernel.debug', false); + $this->container->setParameter('kernel.project_dir', __DIR__); $this->container->setParameter('kernel.root_dir', __DIR__); $this->container->setParameter('kernel.charset', 'UTF-8'); $this->container->setParameter('debug.file_link_format', null); diff --git a/src/Symfony/Bundle/WebProfilerBundle/composer.json b/src/Symfony/Bundle/WebProfilerBundle/composer.json index dd2a4d728f..c1efe11a26 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/composer.json +++ b/src/Symfony/Bundle/WebProfilerBundle/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^5.5.9|>=7.0.8", - "symfony/http-kernel": "~3.2|~4.0", + "symfony/http-kernel": "~3.3|~4.0", "symfony/polyfill-php70": "~1.0", "symfony/routing": "~2.8|~3.0|~4.0", "symfony/twig-bridge": "~2.8|~3.0|~4.0", From 92fc2f724b503779c7b98abffe1ec6f727a16795 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 17 Nov 2017 12:27:24 +0100 Subject: [PATCH 08/12] remove more kernel.root_dir parameter refs --- .../Tests/DependencyInjection/DebugExtensionTest.php | 1 - .../Bundle/FrameworkBundle/Resources/config/services.xml | 1 - .../FrameworkBundle/Resources/config/templating_php.xml | 2 +- .../FrameworkBundle/Templating/Helper/CodeHelper.php | 2 +- .../Tests/DependencyInjection/Fixtures/php/full.php | 4 ++-- .../Fixtures/php/serializer_mapping.php | 6 +++--- .../Fixtures/php/validation_mapping.php | 6 +++--- .../Tests/DependencyInjection/Fixtures/xml/full.xml | 4 ++-- .../Fixtures/xml/serializer_mapping.xml | 6 +++--- .../Fixtures/xml/validation_mapping.xml | 6 +++--- .../Tests/DependencyInjection/Fixtures/yml/full.yml | 6 +++--- .../Fixtures/yml/serializer_mapping.yml | 6 +++--- .../Fixtures/yml/validation_mapping.yml | 6 +++--- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 2 +- .../DependencyInjection/Compiler/ExtensionPassTest.php | 1 - .../Tests/DependencyInjection/Fixtures/php/full.php | 2 +- .../Tests/DependencyInjection/Fixtures/xml/full.xml | 2 +- .../Tests/DependencyInjection/Fixtures/yml/full.yml | 2 +- .../TwigBundle/Tests/Functional/CacheWarmingTest.php | 7 ++++++- .../Tests/DependencyInjection/WebProfilerExtensionTest.php | 1 - 20 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/DebugExtensionTest.php b/src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/DebugExtensionTest.php index 9c03e99882..0c285a02ac 100644 --- a/src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/DebugExtensionTest.php +++ b/src/Symfony/Bundle/DebugBundle/Tests/DependencyInjection/DebugExtensionTest.php @@ -40,7 +40,6 @@ class DebugExtensionTest extends TestCase { $container = new ContainerBuilder(new ParameterBag(array( 'kernel.cache_dir' => __DIR__, - 'kernel.root_dir' => __DIR__.'/Fixtures', 'kernel.charset' => 'UTF-8', 'kernel.debug' => true, 'kernel.bundles' => array('DebugBundle' => 'Symfony\\Bundle\\DebugBundle\\DebugBundle'), diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml index 6fbfe512d5..f5c44432a3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml @@ -56,7 +56,6 @@ %kernel.root_dir%/Resources %kernel.root_dir% - %kernel.project_dir% diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml index 5d4aa8625e..82d5b4c662 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml @@ -52,7 +52,7 @@ - %kernel.root_dir% + %kernel.project_dir% %kernel.charset% diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index e8871841d8..fc17906330 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -31,7 +31,7 @@ class CodeHelper extends Helper public function __construct($fileLinkFormat, $rootDir, $charset) { $this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); - $this->rootDir = str_replace('\\', '/', dirname($rootDir)).'/'; + $this->rootDir = str_replace('\\', '/', $rootDir).'/'; $this->charset = $charset; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index 2b2b3f45f0..a97daeef1d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -21,7 +21,7 @@ $container->loadFromExtension('framework', array( 'enabled' => false, ), 'router' => array( - 'resource' => '%kernel.root_dir%/config/routing.xml', + 'resource' => '%kernel.project_dir%/config/routing.xml', 'type' => 'xml', ), 'session' => array( @@ -54,7 +54,7 @@ $container->loadFromExtension('framework', array( 'translator' => array( 'enabled' => true, 'fallback' => 'fr', - 'paths' => array('%kernel.root_dir%/Fixtures/translations'), + 'paths' => array('%kernel.project_dir%/Fixtures/translations'), ), 'validation' => array( 'enabled' => true, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_mapping.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_mapping.php index 4e437bf4e8..f2b928ff2d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_mapping.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_mapping.php @@ -6,9 +6,9 @@ $container->loadFromExtension('framework', array( 'enable_annotations' => true, 'mapping' => array( 'paths' => array( - '%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files', - '%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yml', - '%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yaml', + '%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files', + '%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yml', + '%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yaml', ), ), ), diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_mapping.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_mapping.php index 51bbb90ef4..5d44c6c215 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_mapping.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_mapping.php @@ -4,9 +4,9 @@ $container->loadFromExtension('framework', array( 'validation' => array( 'mapping' => array( 'paths' => array( - '%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/files', - '%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yml', - '%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yaml', + '%kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/files', + '%kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yml', + '%kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yaml', ), ), ), diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 81f7823eec..6920efebed 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -14,7 +14,7 @@ - + @@ -37,7 +37,7 @@ - %kernel.root_dir%/Fixtures/translations + %kernel.project_dir%/Fixtures/translations diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_mapping.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_mapping.xml index 9fec09f0db..1ae06c85e1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_mapping.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_mapping.xml @@ -8,9 +8,9 @@ - %kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files - %kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yml - %kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yaml + %kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files + %kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yml + %kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yaml diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_mapping.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_mapping.xml index c011269bd3..8d74ebb211 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_mapping.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_mapping.xml @@ -7,9 +7,9 @@ - %kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/files - %kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yml - %kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yaml + %kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/files + %kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yml + %kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yaml diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index 116062e136..3194a0fab2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -14,7 +14,7 @@ framework: only_exceptions: true enabled: false router: - resource: '%kernel.root_dir%/config/routing.xml' + resource: '%kernel.project_dir%/config/routing.xml' type: xml session: storage_id: session.storage.native @@ -42,8 +42,8 @@ framework: translator: enabled: true fallback: fr - default_path: '%kernel.root_dir%/translations' - paths: ['%kernel.root_dir%/Fixtures/translations'] + default_path: '%kernel.project_dir%/translations' + paths: ['%kernel.project_dir%/Fixtures/translations'] validation: enabled: true annotations: diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_mapping.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_mapping.yml index b977dc89be..77c9d517a3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_mapping.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_mapping.yml @@ -5,6 +5,6 @@ framework: enable_annotations: true mapping: paths: - - "%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files" - - "%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yml" - - "%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yaml" + - "%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files" + - "%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yml" + - "%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yaml" diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_mapping.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_mapping.yml index 7d79bc9a1c..f05e33bb6c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_mapping.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_mapping.yml @@ -2,6 +2,6 @@ framework: validation: mapping: paths: - - "%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/files" - - "%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yml" - - "%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yaml" + - "%kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/files" + - "%kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yml" + - "%kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yaml" diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index ae75b3727c..974a069443 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -322,7 +322,7 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertTrue($container->has('router'), '->registerRouterConfiguration() loads routing.xml'); $arguments = $container->findDefinition('router')->getArguments(); - $this->assertEquals($container->getParameter('kernel.root_dir').'/config/routing.xml', $container->getParameter('router.resource'), '->registerRouterConfiguration() sets routing resource'); + $this->assertEquals($container->getParameter('kernel.project_dir').'/config/routing.xml', $container->getParameter('router.resource'), '->registerRouterConfiguration() sets routing resource'); $this->assertEquals('%router.resource%', $arguments[1], '->registerRouterConfiguration() sets routing resource'); $this->assertEquals('xml', $arguments[2]['resource_type'], '->registerRouterConfiguration() sets routing resource type'); } diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php index 6ce77c5497..00c2217f07 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php @@ -22,7 +22,6 @@ class ExtensionPassTest extends TestCase { $container = new ContainerBuilder(); $container->setParameter('kernel.debug', false); - $container->setParameter('kernel.root_dir', __DIR__); $container->register('twig.app_variable', '\Symfony\Bridge\Twig\AppVariable'); $container->register('templating', '\Symfony\Bundle\TwigBundle\TwigEngine'); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php index 839d037fdc..47b9e5d835 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -17,7 +17,7 @@ $container->loadFromExtension('twig', array( 'charset' => 'ISO-8859-1', 'debug' => true, 'strict_variables' => true, - 'default_path' => '%kernel.root_dir%/templates', + 'default_path' => '%kernel.project_dir%/Fixtures/templates', 'paths' => array( 'path1', 'path2', diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 702e34617d..116b128fe6 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -6,7 +6,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd"> - + MyBundle::form.html.twig @@qux diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index 07d4abe767..24c10c23fe 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -13,7 +13,7 @@ twig: charset: ISO-8859-1 debug: true strict_variables: true - default_path: '%kernel.root_dir%/templates' + default_path: '%kernel.project_dir%/Fixtures/templates' paths: path1: '' path2: '' diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php index 83bedda677..a7a330859f 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php @@ -99,13 +99,18 @@ class CacheWarmingKernel extends Kernel $container->loadFromExtension('framework', array( 'secret' => '$ecret', 'templating' => array('engines' => array('twig')), - 'router' => array('resource' => '%kernel.root_dir%/Resources/config/empty_routing.yml'), + 'router' => array('resource' => '%kernel.project_dir%/Resources/config/empty_routing.yml'), 'form' => array('enabled' => false), )); }); } } + public function getProjectDir() + { + return __DIR__; + } + public function getCacheDir() { return sys_get_temp_dir().'/'.Kernel::VERSION.'/CacheWarmingKernel/cache/'.$this->environment; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php index 67726a0a13..316bd13f2f 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php @@ -61,7 +61,6 @@ class WebProfilerExtensionTest extends TestCase $this->container->setParameter('kernel.cache_dir', __DIR__); $this->container->setParameter('kernel.debug', false); $this->container->setParameter('kernel.project_dir', __DIR__); - $this->container->setParameter('kernel.root_dir', __DIR__); $this->container->setParameter('kernel.charset', 'UTF-8'); $this->container->setParameter('debug.file_link_format', null); $this->container->setParameter('profiler.class', array('Symfony\\Component\\HttpKernel\\Profiler\\Profiler')); From c7333b1c68bb735828eda0128d09da9353495af3 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Fri, 24 Nov 2017 00:05:16 +0100 Subject: [PATCH 09/12] Prefer overflow-wrap to word-break --- .../Bundle/TwigBundle/Resources/views/exception.css.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig index 87a60d4197..f0ca2f5b04 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/exception.css.twig @@ -22,7 +22,7 @@ table th { background-color: #E0E0E0; font-weight: bold; text-align: left; } .hidden { display: none; } .nowrap { white-space: nowrap; } .newline { display: block; } -.break-long-words { -ms-word-break: break-all; word-break: break-all; word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; } +.break-long-words { word-wrap: break-word; overflow-wrap: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; min-width: 0; } .text-small { font-size: 12px !important; } .text-muted { color: #999; } .text-bold { font-weight: bold; } From bef26187795fead355967c066acc41acd619d197 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Fri, 24 Nov 2017 09:32:53 +0100 Subject: [PATCH 10/12] [WebProfilerBundle] Reset letter-spacing in toolbar --- .../WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig index 3a65e1d053..5bfb109adb 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig @@ -40,6 +40,7 @@ -moz-box-sizing: content-box; box-sizing: content-box; vertical-align: baseline; + letter-spacing: normal; } .sf-toolbarreset { From f4999d8af0fe97ecc2992ba28afab0e404929478 Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Fri, 24 Nov 2017 10:32:00 +0000 Subject: [PATCH 11/12] Add tests proving it can load annotated files --- .../Loader/AnnotationDirectoryLoaderTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php index 78cec4be2a..1e8ee39401 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php @@ -69,6 +69,24 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest $this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified'); } + public function testItSupportsAnyAnnotation() + { + $this->assertTrue($this->loader->supports(__DIR__.'/../Fixtures/even-with-not-existing-folder', 'annotation')); + } + + public function testLoadFileIfLocatedResourceIsFile() + { + $this->reader->expects($this->exactly(1))->method('getClassAnnotation'); + + $this->reader + ->expects($this->any()) + ->method('getMethodAnnotations') + ->will($this->returnValue(array())) + ; + + $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php'); + } + private function expectAnnotationsToBeReadFrom(array $classes) { $this->reader->expects($this->exactly(count($classes))) From 7921255faf04be83b2b1e08500027e9514a0d286 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 24 Nov 2017 12:48:20 +0100 Subject: [PATCH 12/12] [DI] Dont resolve envs in service ids --- .../Compiler/CheckDefinitionValidityPass.php | 16 +- .../Compiler/ResolveEnvPlaceholdersPass.php | 2 +- .../DependencyInjection/Dumper/PhpDumper.php | 33 ++-- .../CheckDefinitionValidityPassTest.php | 21 ++- .../Tests/ContainerBuilderTest.php | 16 ++ .../Tests/Dumper/PhpDumperTest.php | 9 + .../containers/container_env_in_id.php | 22 +++ .../Tests/Fixtures/php/services_env_in_id.php | 177 ++++++++++++++++++ 8 files changed, 269 insertions(+), 27 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_env_in_id.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_env_in_id.php diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php index a8a652c7a2..435d97e3da 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php @@ -77,16 +77,20 @@ class CheckDefinitionValidityPass implements CompilerPassInterface } } - $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs); - if (null !== $usedEnvs) { - throw new EnvParameterException(array($resolvedId), null, 'A service name ("%s") cannot contain dynamic values.'); + if ($definition->isPublic()) { + $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs); + if (null !== $usedEnvs) { + throw new EnvParameterException(array($resolvedId), null, 'A service name ("%s") cannot contain dynamic values.'); + } } } foreach ($container->getAliases() as $id => $alias) { - $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs); - if (null !== $usedEnvs) { - throw new EnvParameterException(array($resolvedId), null, 'An alias name ("%s") cannot contain dynamic values.'); + if ($alias->isPublic()) { + $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs); + if (null !== $usedEnvs) { + throw new EnvParameterException(array($resolvedId), null, 'An alias name ("%s") cannot contain dynamic values.'); + } } } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveEnvPlaceholdersPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveEnvPlaceholdersPass.php index 8e44008317..f42107c6f7 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveEnvPlaceholdersPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveEnvPlaceholdersPass.php @@ -35,7 +35,7 @@ class ResolveEnvPlaceholdersPass extends AbstractRecursivePass $value = parent::processValue($value, $isRoot); - if ($value && is_array($value)) { + if ($value && is_array($value) && !$isRoot) { $value = array_combine($this->container->resolveEnvPlaceholders(array_keys($value), true), $value); } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index d60072b755..6c0cf4f1b6 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -680,6 +680,7 @@ EOF; private function addNewInstance(Definition $definition, $return, $instantiation, $id) { $class = $this->dumpValue($definition->getClass()); + $return = ' '.$return.$instantiation; $arguments = array(); foreach ($definition->getArguments() as $value) { @@ -695,7 +696,7 @@ EOF; if ($callable[0] instanceof Reference || ($callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0]))) { - return sprintf(" $return{$instantiation}%s->%s(%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? implode(', ', $arguments) : ''); + return $return.sprintf("%s->%s(%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? implode(', ', $arguments) : ''); } $class = $this->dumpValue($callable[0]); @@ -705,24 +706,24 @@ EOF; throw new RuntimeException(sprintf('Cannot dump definition: The "%s" service is defined to be created by a factory but is missing the service reference, did you forget to define the factory service id or class?', $id)); } - return sprintf(" $return{$instantiation}%s::%s(%s);\n", $this->dumpLiteralClass($class), $callable[1], $arguments ? implode(', ', $arguments) : ''); + return $return.sprintf("%s::%s(%s);\n", $this->dumpLiteralClass($class), $callable[1], $arguments ? implode(', ', $arguments) : ''); } if (0 === strpos($class, 'new ')) { - return sprintf(" $return{$instantiation}(%s)->%s(%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? implode(', ', $arguments) : ''); + return $return.sprintf("(%s)->%s(%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? implode(', ', $arguments) : ''); } - return sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? ', '.implode(', ', $arguments) : ''); + return $return.sprintf("call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? ', '.implode(', ', $arguments) : ''); } - return sprintf(" $return{$instantiation}%s(%s);\n", $this->dumpLiteralClass($this->dumpValue($callable)), $arguments ? implode(', ', $arguments) : ''); + return $return.sprintf("%s(%s);\n", $this->dumpLiteralClass($this->dumpValue($callable)), $arguments ? implode(', ', $arguments) : ''); } if (false !== strpos($class, '$')) { - return sprintf(" \$class = %s;\n\n $return{$instantiation}new \$class(%s);\n", $class, implode(', ', $arguments)); + return sprintf(" \$class = %s;\n\n%snew \$class(%s);\n", $class, $return, implode(', ', $arguments)); } - return sprintf(" $return{$instantiation}new %s(%s);\n", $this->dumpLiteralClass($class), implode(', ', $arguments)); + return $return.sprintf("new %s(%s);\n", $this->dumpLiteralClass($class), implode(', ', $arguments)); } /** @@ -890,7 +891,7 @@ EOF; ksort($normalizedIds); foreach ($normalizedIds as $id => $normalizedId) { if ($this->container->has($normalizedId)) { - $code .= ' '.$this->export($id).' => '.$this->export($normalizedId).",\n"; + $code .= ' '.$this->doExport($id).' => '.$this->doExport($normalizedId).",\n"; } } @@ -912,7 +913,7 @@ EOF; $code = " \$this->methodMap = array(\n"; ksort($definitions); foreach ($definitions as $id => $definition) { - $code .= ' '.$this->export($id).' => '.$this->export($this->generateMethodName($id)).",\n"; + $code .= ' '.$this->doExport($id).' => '.$this->doExport($this->generateMethodName($id)).",\n"; } return $code." );\n"; @@ -933,7 +934,7 @@ EOF; ksort($definitions); foreach ($definitions as $id => $definition) { if (!$definition->isPublic()) { - $code .= ' '.$this->export($id)." => true,\n"; + $code .= ' '.$this->doExport($id)." => true,\n"; } } @@ -966,7 +967,7 @@ EOF; while (isset($aliases[$id])) { $id = (string) $aliases[$id]; } - $code .= ' '.$this->export($alias).' => '.$this->export($id).",\n"; + $code .= ' '.$this->doExport($alias).' => '.$this->doExport($id).",\n"; } return $code." );\n"; @@ -1688,9 +1689,9 @@ EOF; private function export($value) { if (null !== $this->targetDirRegex && is_string($value) && preg_match($this->targetDirRegex, $value, $matches, PREG_OFFSET_CAPTURE)) { - $prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1])).'.' : ''; + $prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : ''; $suffix = $matches[0][1] + strlen($matches[0][0]); - $suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix)) : ''; + $suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : ''; $dirname = '__DIR__'; if (0 < $offset = 1 + $this->targetDirMaxMatches - count($matches)) { @@ -1704,10 +1705,10 @@ EOF; return $dirname; } - return $this->doExport($value); + return $this->doExport($value, true); } - private function doExport($value) + private function doExport($value, $resolveEnv = false) { if (is_string($value) && false !== strpos($value, "\n")) { $cleanParts = explode("\n", $value); @@ -1717,7 +1718,7 @@ EOF; $export = var_export($value, true); } - if ("'" === $export[0] && $export !== $resolvedExport = $this->container->resolveEnvPlaceholders($export, "'.\$this->getEnv('%s').'")) { + if ($resolveEnv && "'" === $export[0] && $export !== $resolvedExport = $this->container->resolveEnvPlaceholders($export, "'.\$this->getEnv('%s').'")) { $export = $resolvedExport; if ("'" === $export[1]) { $export = substr($export, 3); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php index 473d5667d4..d47303e851 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -79,11 +80,11 @@ class CheckDefinitionValidityPassTest extends TestCase /** * @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException */ - public function testDynamicServiceName() + public function testDynamicPublicServiceName() { $container = new ContainerBuilder(); $env = $container->getParameterBag()->get('env(BAR)'); - $container->register("foo.$env", 'class'); + $container->register("foo.$env", 'class')->setPublic(true); $this->process($container); } @@ -91,15 +92,27 @@ class CheckDefinitionValidityPassTest extends TestCase /** * @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException */ - public function testDynamicAliasName() + public function testDynamicPublicAliasName() { $container = new ContainerBuilder(); $env = $container->getParameterBag()->get('env(BAR)'); - $container->setAlias("foo.$env", 'class'); + $container->setAlias("foo.$env", new Alias('class', true)); $this->process($container); } + public function testDynamicPrivateName() + { + $container = new ContainerBuilder(); + $env = $container->getParameterBag()->get('env(BAR)'); + $container->register("foo.$env", 'class')->setPublic(false); + $container->setAlias("bar.$env", new Alias('class', false)); + + $this->process($container); + + $this->addToAssertionCount(1); + } + protected function process(ContainerBuilder $container) { $pass = new CheckDefinitionValidityPass(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 665a0b25d7..8b905746b2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -665,6 +665,22 @@ class ContainerBuilderTest extends TestCase $container->compile(true); } + public function testEnvInId() + { + $container = include __DIR__.'/Fixtures/containers/container_env_in_id.php'; + $container->compile(true); + + $expected = array( + 'service_container', + 'foo', + 'bar', + 'bar_%env(BAR)%', + ); + $this->assertSame($expected, array_keys($container->getDefinitions())); + + $this->assertSame(array('baz_bar'), array_keys($container->getDefinition('foo')->getArgument(1))); + } + /** * @expectedException \LogicException */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index 0d734cb4c2..44e172fed2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -327,6 +327,15 @@ class PhpDumperTest extends TestCase $this->assertStringEqualsFile(self::$fixturesPath.'/php/services24.php', $dumper->dump()); } + public function testEnvInId() + { + $container = include self::$fixturesPath.'/containers/container_env_in_id.php'; + $container->compile(); + $dumper = new PhpDumper($container); + + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_env_in_id.php', $dumper->dump()); + } + public function testEnvParameter() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_env_in_id.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_env_in_id.php new file mode 100644 index 0000000000..4699f41011 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_env_in_id.php @@ -0,0 +1,22 @@ +setParameter('env(BAR)', 'bar'); + +$container->register('foo', 'stdClass')->setPublic(true) + ->addArgument(new Reference('bar_%env(BAR)%')) + ->addArgument(array('baz_%env(BAR)%' => new Reference('baz_%env(BAR)%'))); + +$container->register('bar', 'stdClass')->setPublic(true) + ->addArgument(new Reference('bar_%env(BAR)%')); + +$container->register('bar_%env(BAR)%', 'stdClass')->setPublic(false); +$container->register('baz_%env(BAR)%', 'stdClass')->setPublic(false); + +return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_env_in_id.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_env_in_id.php new file mode 100644 index 0000000000..d7f2ea626a --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_env_in_id.php @@ -0,0 +1,177 @@ +parameters = $this->getDefaultParameters(); + + $this->services = array(); + $this->normalizedIds = array( + 'bar_%env(bar)%' => 'bar_%env(BAR)%', + ); + $this->methodMap = array( + 'bar' => 'getBarService', + 'bar_%env(BAR)%' => 'getBarenvBARService', + 'foo' => 'getFooService', + ); + $this->privates = array( + 'bar_%env(BAR)%' => true, + ); + + $this->aliases = array(); + } + + /** + * {@inheritdoc} + */ + public function compile() + { + throw new LogicException('You cannot compile a dumped container that was already compiled.'); + } + + /** + * {@inheritdoc} + */ + public function isCompiled() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function isFrozen() + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); + + return true; + } + + /** + * Gets the public 'bar' shared service. + * + * @return \stdClass + */ + protected function getBarService() + { + return $this->services['bar'] = new \stdClass(${($_ = isset($this->services['bar_%env(BAR)%']) ? $this->services['bar_%env(BAR)%'] : $this->getBarenvBARService()) && false ?: '_'}); + } + + /** + * Gets the public 'foo' shared service. + * + * @return \stdClass + */ + protected function getFooService() + { + return $this->services['foo'] = new \stdClass(${($_ = isset($this->services['bar_%env(BAR)%']) ? $this->services['bar_%env(BAR)%'] : $this->getBarenvBARService()) && false ?: '_'}, array('baz_'.$this->getEnv('BAR') => new \stdClass())); + } + + /** + * Gets the private 'bar_%env(BAR)%' shared service. + * + * @return \stdClass + */ + protected function getBarenvBARService() + { + return $this->services['bar_%env(BAR)%'] = new \stdClass(); + } + + /** + * {@inheritdoc} + */ + public function getParameter($name) + { + $name = strtolower($name); + + if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters) || isset($this->loadedDynamicParameters[$name]))) { + throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name)); + } + if (isset($this->loadedDynamicParameters[$name])) { + return $this->loadedDynamicParameters[$name] ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); + } + + return $this->parameters[$name]; + } + + /** + * {@inheritdoc} + */ + public function hasParameter($name) + { + $name = strtolower($name); + + return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters) || isset($this->loadedDynamicParameters[$name]); + } + + /** + * {@inheritdoc} + */ + public function setParameter($name, $value) + { + throw new LogicException('Impossible to call set() on a frozen ParameterBag.'); + } + + /** + * {@inheritdoc} + */ + public function getParameterBag() + { + if (null === $this->parameterBag) { + $parameters = $this->parameters; + foreach ($this->loadedDynamicParameters as $name => $loaded) { + $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); + } + $this->parameterBag = new FrozenParameterBag($parameters); + } + + return $this->parameterBag; + } + + private $loadedDynamicParameters = array(); + private $dynamicParameters = array(); + + /** + * Computes a dynamic parameter. + * + * @param string The name of the dynamic parameter to load + * + * @return mixed The value of the dynamic parameter + * + * @throws InvalidArgumentException When the dynamic parameter does not exist + */ + private function getDynamicParameter($name) + { + throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name)); + } + + /** + * Gets the default parameters. + * + * @return array An array of the default parameters + */ + protected function getDefaultParameters() + { + return array( + 'env(bar)' => 'bar', + ); + } +}