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/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 06a9c2ea41..ea122cf803 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -226,6 +226,7 @@ EOT private function symlink(string $originDir, string $targetDir, bool $relative = false) { if ($relative) { + $this->filesystem->mkdir(dirname($targetDir)); $originDir = $this->filesystem->makePathRelative($originDir, realpath(dirname($targetDir))); } $this->filesystem->symlink($originDir, $targetDir); diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index fb5d2536f5..c9b9fefaf5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -221,9 +221,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; diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php index 4bcea10827..a444df3a5a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php @@ -46,14 +46,18 @@ class TranslationDebugCommand extends Command private $translator; private $reader; private $extractor; + private $defaultTransPath; + private $defaultViewsPath; - public function __construct(TranslatorInterface $translator, TranslationReaderInterface $reader, ExtractorInterface $extractor) + public function __construct(TranslatorInterface $translator, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultTransPath = null, string $defaultViewsPath = null) { parent::__construct(); $this->translator = $translator; $this->reader = $reader; $this->extractor = $extractor; + $this->defaultTransPath = $defaultTransPath; + $this->defaultViewsPath = $defaultViewsPath; } /** @@ -117,20 +121,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])); @@ -138,13 +156,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); @@ -268,7 +294,6 @@ EOF { $extractedCatalogue = new MessageCatalogue($locale); foreach ($transPaths as $path) { - $path = $path.'views'; if (is_dir($path)) { $this->extractor->extract($path, $extractedCatalogue); } @@ -281,7 +306,6 @@ EOF { $currentCatalogue = new MessageCatalogue($locale); foreach ($transPaths as $path) { - $path = $path.'translations'; if (is_dir($path)) { $this->reader->read($path, $currentCatalogue); } @@ -304,7 +328,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 c16c4dcf14..2404dbdba7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Command; use Symfony\Component\Console\Command\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; @@ -40,8 +41,10 @@ class TranslationUpdateCommand extends Command private $reader; private $extractor; private $defaultLocale; + private $defaultTransPath; + private $defaultViewsPath; - public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultLocale) + public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultLocale, string $defaultTransPath = null, string $defaultViewsPath = null) { parent::__construct(); @@ -49,6 +52,8 @@ class TranslationUpdateCommand extends Command $this->reader = $reader; $this->extractor = $extractor; $this->defaultLocale = $defaultLocale; + $this->defaultTransPath = $defaultTransPath; + $this->defaultViewsPath = $defaultViewsPath; } /** @@ -110,24 +115,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])) { @@ -143,8 +163,7 @@ EOF $extractedCatalogue = new MessageCatalogue($input->getArgument('locale')); $errorIo->comment('Parsing templates...'); $this->extractor->setPrefix($input->getOption('prefix')); - foreach ($transPaths as $path) { - $path .= 'views'; + foreach ($viewsPaths as $path) { if (is_dir($path)) { $this->extractor->extract($path, $extractedCatalogue); } @@ -154,7 +173,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); } @@ -222,14 +240,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/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/Tests/Command/TranslationDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php index 0d702a0aca..01e6df156a 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 a2a0c97e4a..9232b7b027 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/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 d4e6d0e771..e015e78a94 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -315,7 +315,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/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; } 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/DependencyInjection/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php index e8e3ee87e9..8f74d05f43 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php @@ -51,24 +51,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(5, $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 538bea8ef3..e5f9423ce5 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml @@ -13,7 +13,7 @@ %data_collector.templates% - null + %kernel.project_dir% @@ -54,7 +54,7 @@ %debug.file_link_format% - null + %kernel.project_dir% /_profiler/open?file=%%f&line=%%l#line%%l 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 6a86c951ef..ed940b770c 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 { diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php index e0df0459bf..4069cdd6c9 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php @@ -60,7 +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.root_dir', __DIR__); + $this->container->setParameter('kernel.project_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')); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php index a8a652c7a2..ba6356f4ac 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() && !$definition->isPrivate()) { + $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() && !$alias->isPrivate()) { + $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/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 94ac508c1b..3707b163d0 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -1262,7 +1262,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) { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 2a0fdcc289..baf9613d84 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -199,7 +199,7 @@ EOF; sort($ids); $c = "export($id)." => true,\n"; + $c .= ' '.$this->doExport($id)." => true,\n"; } $files['removed-ids.php'] = $c .= ");\n"; } @@ -820,6 +820,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) { @@ -835,7 +836,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]); @@ -845,24 +846,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}[%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}%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)); } private function startClass(string $class, string $baseClass): string @@ -986,7 +987,7 @@ EOF; ksort($definitions); foreach ($definitions as $id => $definition) { if ($definition->isSynthetic() && 'service_container' !== $id) { - $code .= ' '.$this->export($id)." => true,\n"; + $code .= ' '.$this->doExport($id)." => true,\n"; } } @@ -1011,7 +1012,7 @@ EOF; $ids = array_keys($ids); sort($ids); foreach ($ids as $id) { - $code .= ' '.$this->export($id)." => true,\n"; + $code .= ' '.$this->doExport($id)." => true,\n"; } $code = "array(\n{$code} )"; @@ -1034,7 +1035,7 @@ EOF; ksort($definitions); foreach ($definitions as $id => $definition) { if (!$definition->isSynthetic() && $definition->isPublic() && (!$this->asFiles || !$definition->isShared() || $this->isHotPath($definition))) { - $code .= ' '.$this->export($id).' => '.$this->export($this->generateMethodName($id)).",\n"; + $code .= ' '.$this->doExport($id).' => '.$this->doExport($this->generateMethodName($id)).",\n"; } } @@ -1048,7 +1049,7 @@ EOF; ksort($definitions); foreach ($definitions as $id => $definition) { if (!$definition->isSynthetic() && $definition->isPublic() && $definition->isShared() && !$this->isHotPath($definition)) { - $code .= sprintf(" %s => __DIR__.'/%s.php',\n", $this->export($id), $this->generateMethodName($id)); + $code .= sprintf(" %s => __DIR__.'/%s.php',\n", $this->doExport($id), $this->generateMethodName($id)); } } @@ -1068,7 +1069,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"; @@ -1743,9 +1744,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__'; $offset = 1 + $this->targetDirMaxMatches - count($matches); @@ -1760,10 +1761,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); @@ -1773,7 +1774,7 @@ EOF; $export = var_export($value, true); } - if ("'" === $export[0] && $export !== $resolvedExport = $this->container->resolveEnvPlaceholders($export, "'.\$this->getEnv('string:%s').'")) { + if ($resolveEnv && "'" === $export[0] && $export !== $resolvedExport = $this->container->resolveEnvPlaceholders($export, "'.\$this->getEnv('string:%s').'")) { $export = $resolvedExport; if (".''" === substr($export, -3)) { $export = substr($export, 0, -3); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php index 473d5667d4..f698ed02dc 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php @@ -79,11 +79,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 +91,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", 'class')->setPublic(true); $this->process($container); } + public function testDynamicPrivateName() + { + $container = new ContainerBuilder(); + $env = $container->getParameterBag()->get('env(BAR)'); + $container->register("foo.$env", 'class'); + $container->setAlias("bar.$env", 'class'); + + $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 936b13ea2a..5bcb915bc1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -716,6 +716,29 @@ class ContainerBuilderTest extends TestCase $this->assertNull($container->get('foo')->fake); } + 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())); + + $expected = array( + PsrContainerInterface::class => true, + ContainerInterface::class => true, + 'baz_%env(BAR)%' => true, + ); + $this->assertSame($expected, $container->getRemovedIds()); + + $this->assertSame(array('baz_bar'), array_keys($container->getDefinition('foo')->getArgument(1))); + } + /** * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException * @expectedExceptionMessage Circular reference detected for parameter "env(resolve:DUMMY_ENV_VAR)" ("env(resolve:DUMMY_ENV_VAR)" > "env(resolve:DUMMY_ENV_VAR)"). diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index 86c3eceb9b..e1a5a28f15 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -325,6 +325,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() { $rand = mt_rand(); 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..b6afb3cf15 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_env_in_id.php @@ -0,0 +1,149 @@ +parameters = $this->getDefaultParameters(); + + $this->services = $this->privates = array(); + $this->methodMap = array( + 'bar' => 'getBarService', + 'foo' => 'getFooService', + ); + + $this->aliases = array(); + } + + public function reset() + { + $this->privates = array(); + parent::reset(); + } + + public function compile() + { + throw new LogicException('You cannot compile a dumped container that was already compiled.'); + } + + public function isCompiled() + { + return true; + } + + public function getRemovedIds() + { + return array( + 'Psr\\Container\\ContainerInterface' => true, + 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, + 'bar_%env(BAR)%' => true, + 'baz_%env(BAR)%' => true, + ); + } + + /** + * Gets the public 'bar' shared service. + * + * @return \stdClass + */ + protected function getBarService() + { + return $this->services['bar'] = new \stdClass(($this->privates['bar_%env(BAR)%'] ?? $this->privates['bar_%env(BAR)%'] = new \stdClass())); + } + + /** + * Gets the public 'foo' shared service. + * + * @return \stdClass + */ + protected function getFooService() + { + return $this->services['foo'] = new \stdClass(($this->privates['bar_%env(BAR)%'] ?? $this->privates['bar_%env(BAR)%'] = new \stdClass()), array('baz_'.$this->getEnv('string:BAR') => new \stdClass())); + } + + public function getParameter($name) + { + $name = (string) $name; + + if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) { + 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]; + } + + public function hasParameter($name) + { + $name = (string) $name; + + return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters); + } + + public function setParameter($name, $value) + { + throw new LogicException('Impossible to call set() on a frozen ParameterBag.'); + } + + 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', + ); + } +} 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); } } 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))) diff --git a/src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php b/src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php index 199702b469..7ec06684f5 100644 --- a/src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php +++ b/src/Symfony/Component/Translation/DependencyInjection/TranslatorPass.php @@ -21,12 +21,16 @@ class TranslatorPass implements CompilerPassInterface private $translatorServiceId; private $readerServiceId; private $loaderTag; + private $debugCommandServiceId; + private $updateCommandServiceId; - public function __construct(string $translatorServiceId = 'translator.default', string $readerServiceId = 'translation.reader', string $loaderTag = 'translation.loader') + public function __construct(string $translatorServiceId = 'translator.default', string $readerServiceId = 'translation.reader', string $loaderTag = 'translation.loader', string $debugCommandServiceId = 'console.command.translation_debug', string $updateCommandServiceId = 'console.command.translation_update') { $this->translatorServiceId = $translatorServiceId; $this->readerServiceId = $readerServiceId; $this->loaderTag = $loaderTag; + $this->debugCommandServiceId = $debugCommandServiceId; + $this->updateCommandServiceId = $updateCommandServiceId; } public function process(ContainerBuilder $container) @@ -59,5 +63,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')); + } } }