Merge branch '3.4' into 4.0

* 3.4:
  [DI] Dont resolve envs in service ids
  Add tests proving it can load annotated files
  [WebProfilerBundle] Reset letter-spacing in toolbar
  Prefer overflow-wrap to word-break
  remove more kernel.root_dir parameter refs
  [*Bundle] Replace some kernel.root_dir by kernel.project_dir
  removed some phpdocs
  [Routing] Fix "config-file-relative" annotation loader resources
  Make search in debug:container command case-insensitive
  `resolveEnvPlaceholders` will return a mixed value
  Update translation commands to work with default paths
  [FrameworkBundle] Fix AssetsInstallCommand
This commit is contained in:
Nicolas Grekas 2017-11-24 15:34:08 +01:00
commit 8b98282821
41 changed files with 447 additions and 122 deletions

View File

@ -40,7 +40,6 @@ class DebugExtensionTest extends TestCase
{ {
$container = new ContainerBuilder(new ParameterBag(array( $container = new ContainerBuilder(new ParameterBag(array(
'kernel.cache_dir' => __DIR__, 'kernel.cache_dir' => __DIR__,
'kernel.root_dir' => __DIR__.'/Fixtures',
'kernel.charset' => 'UTF-8', 'kernel.charset' => 'UTF-8',
'kernel.debug' => true, 'kernel.debug' => true,
'kernel.bundles' => array('DebugBundle' => 'Symfony\\Bundle\\DebugBundle\\DebugBundle'), 'kernel.bundles' => array('DebugBundle' => 'Symfony\\Bundle\\DebugBundle\\DebugBundle'),

View File

@ -226,6 +226,7 @@ EOT
private function symlink(string $originDir, string $targetDir, bool $relative = false) private function symlink(string $originDir, string $targetDir, bool $relative = false)
{ {
if ($relative) { if ($relative) {
$this->filesystem->mkdir(dirname($targetDir));
$originDir = $this->filesystem->makePathRelative($originDir, realpath(dirname($targetDir))); $originDir = $this->filesystem->makePathRelative($originDir, realpath(dirname($targetDir)));
} }
$this->filesystem->symlink($originDir, $targetDir); $this->filesystem->symlink($originDir, $targetDir);

View File

@ -221,9 +221,8 @@ EOF
{ {
$serviceIds = $builder->getServiceIds(); $serviceIds = $builder->getServiceIds();
$foundServiceIds = array(); $foundServiceIds = array();
$name = strtolower($name);
foreach ($serviceIds as $serviceId) { foreach ($serviceIds as $serviceId) {
if (false === strpos($serviceId, $name)) { if (false === stripos($serviceId, $name)) {
continue; continue;
} }
$foundServiceIds[] = $serviceId; $foundServiceIds[] = $serviceId;

View File

@ -46,14 +46,18 @@ class TranslationDebugCommand extends Command
private $translator; private $translator;
private $reader; private $reader;
private $extractor; 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(); parent::__construct();
$this->translator = $translator; $this->translator = $translator;
$this->reader = $reader; $this->reader = $reader;
$this->extractor = $extractor; $this->extractor = $extractor;
$this->defaultTransPath = $defaultTransPath;
$this->defaultViewsPath = $defaultViewsPath;
} }
/** /**
@ -117,20 +121,34 @@ EOF
/** @var KernelInterface $kernel */ /** @var KernelInterface $kernel */
$kernel = $this->getApplication()->getKernel(); $kernel = $this->getApplication()->getKernel();
// Define Root Path to App folder // Define Root Paths
$transPaths = array($kernel->getRootDir().'/Resources/'); $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 // Override with provided Bundle info
if (null !== $input->getArgument('bundle')) { if (null !== $input->getArgument('bundle')) {
try { try {
$bundle = $kernel->getBundle($input->getArgument('bundle')); $bundle = $kernel->getBundle($input->getArgument('bundle'));
$transPaths = array( $transPaths = array($bundle->getPath().'/Resources/translations');
$bundle->getPath().'/Resources/', if ($this->defaultTransPath) {
sprintf('%s/Resources/%s/', $kernel->getRootDir(), $bundle->getName()), $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) { } catch (\InvalidArgumentException $e) {
// such a bundle does not exist, so treat the argument as path // 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])) { if (!is_dir($transPaths[0])) {
throw new \InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $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')) { } elseif ($input->getOption('all')) {
foreach ($kernel->getBundles() as $bundle) { foreach ($kernel->getBundles() as $bundle) {
$transPaths[] = $bundle->getPath().'/Resources/'; $transPaths[] = $bundle->getPath().'/Resources/translations';
$transPaths[] = sprintf('%s/Resources/%s/', $kernel->getRootDir(), $bundle->getName()); 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 // Extract used messages
$extractedCatalogue = $this->extractMessages($locale, $transPaths); $extractedCatalogue = $this->extractMessages($locale, $viewsPaths);
// Load defined messages // Load defined messages
$currentCatalogue = $this->loadCurrentMessages($locale, $transPaths); $currentCatalogue = $this->loadCurrentMessages($locale, $transPaths);
@ -268,7 +294,6 @@ EOF
{ {
$extractedCatalogue = new MessageCatalogue($locale); $extractedCatalogue = new MessageCatalogue($locale);
foreach ($transPaths as $path) { foreach ($transPaths as $path) {
$path = $path.'views';
if (is_dir($path)) { if (is_dir($path)) {
$this->extractor->extract($path, $extractedCatalogue); $this->extractor->extract($path, $extractedCatalogue);
} }
@ -281,7 +306,6 @@ EOF
{ {
$currentCatalogue = new MessageCatalogue($locale); $currentCatalogue = new MessageCatalogue($locale);
foreach ($transPaths as $path) { foreach ($transPaths as $path) {
$path = $path.'translations';
if (is_dir($path)) { if (is_dir($path)) {
$this->reader->read($path, $currentCatalogue); $this->reader->read($path, $currentCatalogue);
} }
@ -304,7 +328,6 @@ EOF
$fallbackCatalogue = new MessageCatalogue($fallbackLocale); $fallbackCatalogue = new MessageCatalogue($fallbackLocale);
foreach ($transPaths as $path) { foreach ($transPaths as $path) {
$path = $path.'translations';
if (is_dir($path)) { if (is_dir($path)) {
$this->reader->read($path, $fallbackCatalogue); $this->reader->read($path, $fallbackCatalogue);
} }

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Command;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Translation\Catalogue\TargetOperation; use Symfony\Component\Translation\Catalogue\TargetOperation;
use Symfony\Component\Translation\Catalogue\MergeOperation; use Symfony\Component\Translation\Catalogue\MergeOperation;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
@ -40,8 +41,10 @@ class TranslationUpdateCommand extends Command
private $reader; private $reader;
private $extractor; private $extractor;
private $defaultLocale; 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(); parent::__construct();
@ -49,6 +52,8 @@ class TranslationUpdateCommand extends Command
$this->reader = $reader; $this->reader = $reader;
$this->extractor = $extractor; $this->extractor = $extractor;
$this->defaultLocale = $defaultLocale; $this->defaultLocale = $defaultLocale;
$this->defaultTransPath = $defaultTransPath;
$this->defaultViewsPath = $defaultViewsPath;
} }
/** /**
@ -110,24 +115,39 @@ EOF
return 1; return 1;
} }
/** @var KernelInterface $kernel */
$kernel = $this->getApplication()->getKernel(); $kernel = $this->getApplication()->getKernel();
// Define Root Path to App folder // Define Root Paths
$transPaths = array($kernel->getRootDir().'/Resources/'); $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'; $currentName = 'app folder';
// Override with provided Bundle info // Override with provided Bundle info
if (null !== $input->getArgument('bundle')) { if (null !== $input->getArgument('bundle')) {
try { try {
$foundBundle = $kernel->getBundle($input->getArgument('bundle')); $foundBundle = $kernel->getBundle($input->getArgument('bundle'));
$transPaths = array( $transPaths = array($foundBundle->getPath().'/Resources/translations');
$foundBundle->getPath().'/Resources/', if ($this->defaultTransPath) {
sprintf('%s/Resources/%s/', $kernel->getRootDir(), $foundBundle->getName()), $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(); $currentName = $foundBundle->getName();
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
// such a bundle does not exist, so treat the argument as path // 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]; $currentName = $transPaths[0];
if (!is_dir($transPaths[0])) { if (!is_dir($transPaths[0])) {
@ -143,8 +163,7 @@ EOF
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale')); $extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
$errorIo->comment('Parsing templates...'); $errorIo->comment('Parsing templates...');
$this->extractor->setPrefix($input->getOption('prefix')); $this->extractor->setPrefix($input->getOption('prefix'));
foreach ($transPaths as $path) { foreach ($viewsPaths as $path) {
$path .= 'views';
if (is_dir($path)) { if (is_dir($path)) {
$this->extractor->extract($path, $extractedCatalogue); $this->extractor->extract($path, $extractedCatalogue);
} }
@ -154,7 +173,6 @@ EOF
$currentCatalogue = new MessageCatalogue($input->getArgument('locale')); $currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
$errorIo->comment('Loading translation files...'); $errorIo->comment('Loading translation files...');
foreach ($transPaths as $path) { foreach ($transPaths as $path) {
$path .= 'translations';
if (is_dir($path)) { if (is_dir($path)) {
$this->reader->read($path, $currentCatalogue); $this->reader->read($path, $currentCatalogue);
} }
@ -222,14 +240,13 @@ EOF
$bundleTransPath = false; $bundleTransPath = false;
foreach ($transPaths as $path) { foreach ($transPaths as $path) {
$path .= 'translations';
if (is_dir($path)) { if (is_dir($path)) {
$bundleTransPath = $path; $bundleTransPath = $path;
} }
} }
if (!$bundleTransPath) { 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)); $this->writer->write($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath, 'default_locale' => $this->defaultLocale));

View File

@ -78,6 +78,8 @@
<argument type="service" id="translator" /> <argument type="service" id="translator" />
<argument type="service" id="translation.reader" /> <argument type="service" id="translation.reader" />
<argument type="service" id="translation.extractor" /> <argument type="service" id="translation.extractor" />
<argument>%translator.default_path%</argument>
<argument /> <!-- %twig.default_path% -->
<tag name="console.command" command="debug:translation" /> <tag name="console.command" command="debug:translation" />
</service> </service>
@ -86,6 +88,8 @@
<argument type="service" id="translation.reader" /> <argument type="service" id="translation.reader" />
<argument type="service" id="translation.extractor" /> <argument type="service" id="translation.extractor" />
<argument>%kernel.default_locale%</argument> <argument>%kernel.default_locale%</argument>
<argument>%translator.default_path%</argument>
<argument /> <!-- %twig.default_path% -->
<tag name="console.command" command="translation:update" /> <tag name="console.command" command="translation:update" />
</service> </service>

View File

@ -52,7 +52,7 @@
<service id="templating.helper.code" class="Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper"> <service id="templating.helper.code" class="Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper">
<tag name="templating.helper" alias="code" /> <tag name="templating.helper" alias="code" />
<argument type="service" id="debug.file_link_formatter"></argument> <argument type="service" id="debug.file_link_formatter"></argument>
<argument>%kernel.root_dir%</argument> <argument>%kernel.project_dir%</argument>
<argument>%kernel.charset%</argument> <argument>%kernel.charset%</argument>
</service> </service>

View File

@ -64,6 +64,21 @@ class TranslationDebugCommandTest extends TestCase
$this->assertRegExp('/unused/', $tester->getDisplay()); $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() public function testDebugCustomDirectory()
{ {
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); $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->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true);
$this->fs->mkdir($this->translationDir.'/Resources/translations'); $this->fs->mkdir($this->translationDir.'/Resources/translations');
$this->fs->mkdir($this->translationDir.'/Resources/views'); $this->fs->mkdir($this->translationDir.'/Resources/views');
$this->fs->mkdir($this->translationDir.'/translations');
$this->fs->mkdir($this->translationDir.'/templates');
} }
protected function tearDown() protected function tearDown()
@ -174,7 +191,7 @@ class TranslationDebugCommandTest extends TestCase
->method('getContainer') ->method('getContainer')
->will($this->returnValue($this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock())); ->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 = new Application($kernel);
$application->add($command); $application->add($command);

View File

@ -31,6 +31,19 @@ class TranslationUpdateCommandTest extends TestCase
$this->assertRegExp('/1 message was successfully extracted/', $tester->getDisplay()); $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() public function testDumpTwoMessagesAndClean()
{ {
$tester = $this->createCommandTester(array('messages' => array('foo' => 'foo', 'bar' => 'bar'))); $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()); $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() public function testWriteMessagesForSpecificDomain()
{ {
$tester = $this->createCommandTester(array('messages' => array('foo' => 'foo'), 'mydomain' => array('bar' => 'bar'))); $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->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation', true);
$this->fs->mkdir($this->translationDir.'/Resources/translations'); $this->fs->mkdir($this->translationDir.'/Resources/translations');
$this->fs->mkdir($this->translationDir.'/Resources/views'); $this->fs->mkdir($this->translationDir.'/Resources/views');
$this->fs->mkdir($this->translationDir.'/translations');
$this->fs->mkdir($this->translationDir.'/templates');
} }
protected function tearDown() protected function tearDown()
@ -152,7 +179,7 @@ class TranslationUpdateCommandTest extends TestCase
->method('getContainer') ->method('getContainer')
->will($this->returnValue($this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock())); ->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 = new Application($kernel);
$application->add($command); $application->add($command);

View File

@ -21,7 +21,7 @@ $container->loadFromExtension('framework', array(
'enabled' => false, 'enabled' => false,
), ),
'router' => array( 'router' => array(
'resource' => '%kernel.root_dir%/config/routing.xml', 'resource' => '%kernel.project_dir%/config/routing.xml',
'type' => 'xml', 'type' => 'xml',
), ),
'session' => array( 'session' => array(
@ -54,7 +54,7 @@ $container->loadFromExtension('framework', array(
'translator' => array( 'translator' => array(
'enabled' => true, 'enabled' => true,
'fallback' => 'fr', 'fallback' => 'fr',
'paths' => array('%kernel.root_dir%/Fixtures/translations'), 'paths' => array('%kernel.project_dir%/Fixtures/translations'),
), ),
'validation' => array( 'validation' => array(
'enabled' => true, 'enabled' => true,

View File

@ -6,9 +6,9 @@ $container->loadFromExtension('framework', array(
'enable_annotations' => true, 'enable_annotations' => true,
'mapping' => array( 'mapping' => array(
'paths' => array( 'paths' => array(
'%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files', '%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files',
'%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yml', '%kernel.project_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/serialization.yaml',
), ),
), ),
), ),

View File

@ -4,9 +4,9 @@ $container->loadFromExtension('framework', array(
'validation' => array( 'validation' => array(
'mapping' => array( 'mapping' => array(
'paths' => array( 'paths' => array(
'%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/files', '%kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/files',
'%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yml', '%kernel.project_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/validation.yaml',
), ),
), ),
), ),

View File

@ -14,7 +14,7 @@
<framework:esi enabled="true" /> <framework:esi enabled="true" />
<framework:ssi enabled="true" /> <framework:ssi enabled="true" />
<framework:profiler only-exceptions="true" enabled="false" /> <framework:profiler only-exceptions="true" enabled="false" />
<framework:router resource="%kernel.root_dir%/config/routing.xml" type="xml" /> <framework:router resource="%kernel.project_dir%/config/routing.xml" type="xml" />
<framework:session gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="false" use-cookies="true" save-path="/path/to/sessions" /> <framework:session gc-maxlifetime="90000" gc-probability="1" gc-divisor="108" storage-id="session.storage.native" handler-id="session.handler.native_file" name="_SYMFONY" cookie-lifetime="86400" cookie-path="/" cookie-domain="example.com" cookie-secure="true" cookie-httponly="false" use-cookies="true" save-path="/path/to/sessions" />
<framework:request> <framework:request>
<framework:format name="csv"> <framework:format name="csv">
@ -37,7 +37,7 @@
</framework:templating> </framework:templating>
<framework:assets version="v1" /> <framework:assets version="v1" />
<framework:translator enabled="true" fallback="fr" logging="true"> <framework:translator enabled="true" fallback="fr" logging="true">
<framework:path>%kernel.root_dir%/Fixtures/translations</framework:path> <framework:path>%kernel.project_dir%/Fixtures/translations</framework:path>
</framework:translator> </framework:translator>
<framework:validation enabled="true" /> <framework:validation enabled="true" />
<framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" /> <framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" />

View File

@ -8,9 +8,9 @@
<framework:annotations enabled="true" /> <framework:annotations enabled="true" />
<framework:serializer enable-annotations="true"> <framework:serializer enable-annotations="true">
<framework:mapping> <framework:mapping>
<framework:path>%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files</framework:path> <framework:path>%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files</framework:path>
<framework:path>%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yml</framework:path> <framework:path>%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yml</framework:path>
<framework:path>%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yaml</framework:path> <framework:path>%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yaml</framework:path>
</framework:mapping> </framework:mapping>
</framework:serializer> </framework:serializer>
</framework:config> </framework:config>

View File

@ -7,9 +7,9 @@
<framework:config> <framework:config>
<framework:validation> <framework:validation>
<framework:mapping> <framework:mapping>
<framework:path>%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/files</framework:path> <framework:path>%kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/files</framework:path>
<framework:path>%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yml</framework:path> <framework:path>%kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yml</framework:path>
<framework:path>%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yaml</framework:path> <framework:path>%kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yaml</framework:path>
</framework:mapping> </framework:mapping>
</framework:validation> </framework:validation>
</framework:config> </framework:config>

View File

@ -14,7 +14,7 @@ framework:
only_exceptions: true only_exceptions: true
enabled: false enabled: false
router: router:
resource: '%kernel.root_dir%/config/routing.xml' resource: '%kernel.project_dir%/config/routing.xml'
type: xml type: xml
session: session:
storage_id: session.storage.native storage_id: session.storage.native
@ -42,8 +42,8 @@ framework:
translator: translator:
enabled: true enabled: true
fallback: fr fallback: fr
default_path: '%kernel.root_dir%/translations' default_path: '%kernel.project_dir%/translations'
paths: ['%kernel.root_dir%/Fixtures/translations'] paths: ['%kernel.project_dir%/Fixtures/translations']
validation: validation:
enabled: true enabled: true
annotations: annotations:

View File

@ -5,6 +5,6 @@ framework:
enable_annotations: true enable_annotations: true
mapping: mapping:
paths: paths:
- "%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files" - "%kernel.project_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/files"
- "%kernel.root_dir%/Fixtures/TestBundle/Resources/config/serializer_mapping/serialization.yml" - "%kernel.project_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/serialization.yaml"

View File

@ -2,6 +2,6 @@ framework:
validation: validation:
mapping: mapping:
paths: paths:
- "%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/files" - "%kernel.project_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/files"
- "%kernel.root_dir%/Fixtures/TestBundle/Resources/config/validation_mapping/validation.yml" - "%kernel.project_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/validation.yaml"

View File

@ -315,7 +315,7 @@ abstract class FrameworkExtensionTest extends TestCase
$this->assertTrue($container->has('router'), '->registerRouterConfiguration() loads routing.xml'); $this->assertTrue($container->has('router'), '->registerRouterConfiguration() loads routing.xml');
$arguments = $container->findDefinition('router')->getArguments(); $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('%router.resource%', $arguments[1], '->registerRouterConfiguration() sets routing resource');
$this->assertEquals('xml', $arguments[2]['resource_type'], '->registerRouterConfiguration() sets routing resource type'); $this->assertEquals('xml', $arguments[2]['resource_type'], '->registerRouterConfiguration() sets routing resource type');
} }

View File

@ -22,7 +22,7 @@ table th { background-color: #E0E0E0; font-weight: bold; text-align: left; }
.hidden { display: none; } .hidden { display: none; }
.nowrap { white-space: nowrap; } .nowrap { white-space: nowrap; }
.newline { display: block; } .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-small { font-size: 12px !important; }
.text-muted { color: #999; } .text-muted { color: #999; }
.text-bold { font-weight: bold; } .text-bold { font-weight: bold; }

View File

@ -22,7 +22,6 @@ class ExtensionPassTest extends TestCase
{ {
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$container->setParameter('kernel.debug', false); $container->setParameter('kernel.debug', false);
$container->setParameter('kernel.root_dir', __DIR__);
$container->register('twig.app_variable', '\Symfony\Bridge\Twig\AppVariable'); $container->register('twig.app_variable', '\Symfony\Bridge\Twig\AppVariable');
$container->register('templating', '\Symfony\Bundle\TwigBundle\TwigEngine'); $container->register('templating', '\Symfony\Bundle\TwigBundle\TwigEngine');

View File

@ -17,7 +17,7 @@ $container->loadFromExtension('twig', array(
'charset' => 'ISO-8859-1', 'charset' => 'ISO-8859-1',
'debug' => true, 'debug' => true,
'strict_variables' => true, 'strict_variables' => true,
'default_path' => '%kernel.root_dir%/templates', 'default_path' => '%kernel.project_dir%/Fixtures/templates',
'paths' => array( 'paths' => array(
'path1', 'path1',
'path2', 'path2',

View File

@ -6,7 +6,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd 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"> http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd">
<twig:config auto-reload="true" autoescape="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true" default-path="%kernel.root_dir%/templates"> <twig:config auto-reload="true" autoescape="true" base-template-class="stdClass" cache="/tmp" charset="ISO-8859-1" debug="true" strict-variables="true" default-path="%kernel.project_dir%/Fixtures/templates">
<twig:form-theme>MyBundle::form.html.twig</twig:form-theme> <twig:form-theme>MyBundle::form.html.twig</twig:form-theme>
<twig:global key="foo" id="bar" type="service" /> <twig:global key="foo" id="bar" type="service" />
<twig:global key="baz">@@qux</twig:global> <twig:global key="baz">@@qux</twig:global>

View File

@ -13,7 +13,7 @@ twig:
charset: ISO-8859-1 charset: ISO-8859-1
debug: true debug: true
strict_variables: true strict_variables: true
default_path: '%kernel.root_dir%/templates' default_path: '%kernel.project_dir%/Fixtures/templates'
paths: paths:
path1: '' path1: ''
path2: '' path2: ''

View File

@ -99,13 +99,18 @@ class CacheWarmingKernel extends Kernel
$container->loadFromExtension('framework', array( $container->loadFromExtension('framework', array(
'secret' => '$ecret', 'secret' => '$ecret',
'templating' => array('engines' => array('twig')), '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), 'form' => array('enabled' => false),
)); ));
}); });
} }
} }
public function getProjectDir()
{
return __DIR__;
}
public function getCacheDir() public function getCacheDir()
{ {
return sys_get_temp_dir().'/'.Kernel::VERSION.'/CacheWarmingKernel/cache/'.$this->environment; return sys_get_temp_dir().'/'.Kernel::VERSION.'/CacheWarmingKernel/cache/'.$this->environment;

View File

@ -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.intercept_redirects', $config['intercept_redirects']);
$container->setParameter('web_profiler.debug_toolbar.mode', $config['toolbar'] ? WebDebugToolbarListener::ENABLED : WebDebugToolbarListener::DISABLED); $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);
} }
/** /**

View File

@ -13,7 +13,7 @@
<argument type="service" id="twig" /> <argument type="service" id="twig" />
<argument>%data_collector.templates%</argument> <argument>%data_collector.templates%</argument>
<argument type="service" id="web_profiler.csp.handler" /> <argument type="service" id="web_profiler.csp.handler" />
<argument>null</argument> <argument>%kernel.project_dir%</argument>
</service> </service>
<service id="web_profiler.controller.router" class="Symfony\Bundle\WebProfilerBundle\Controller\RouterController" public="true"> <service id="web_profiler.controller.router" class="Symfony\Bundle\WebProfilerBundle\Controller\RouterController" public="true">
@ -54,7 +54,7 @@
<service id="debug.file_link_formatter" class="Symfony\Component\HttpKernel\Debug\FileLinkFormatter"> <service id="debug.file_link_formatter" class="Symfony\Component\HttpKernel\Debug\FileLinkFormatter">
<argument>%debug.file_link_format%</argument> <argument>%debug.file_link_format%</argument>
<argument type="service" id="request_stack" on-invalid="ignore" /> <argument type="service" id="request_stack" on-invalid="ignore" />
<argument>null</argument> <argument>%kernel.project_dir%</argument>
<argument>/_profiler/open?file=%%f&amp;line=%%l#line%%l</argument> <argument>/_profiler/open?file=%%f&amp;line=%%l#line%%l</argument>
</service> </service>
</services> </services>

View File

@ -40,6 +40,7 @@
-moz-box-sizing: content-box; -moz-box-sizing: content-box;
box-sizing: content-box; box-sizing: content-box;
vertical-align: baseline; vertical-align: baseline;
letter-spacing: normal;
} }
.sf-toolbarreset { .sf-toolbarreset {

View File

@ -60,7 +60,7 @@ class WebProfilerExtensionTest extends TestCase
$this->container->setParameter('kernel.bundles', array()); $this->container->setParameter('kernel.bundles', array());
$this->container->setParameter('kernel.cache_dir', __DIR__); $this->container->setParameter('kernel.cache_dir', __DIR__);
$this->container->setParameter('kernel.debug', false); $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('kernel.charset', 'UTF-8');
$this->container->setParameter('debug.file_link_format', null); $this->container->setParameter('debug.file_link_format', null);
$this->container->setParameter('profiler.class', array('Symfony\\Component\\HttpKernel\\Profiler\\Profiler')); $this->container->setParameter('profiler.class', array('Symfony\\Component\\HttpKernel\\Profiler\\Profiler'));

View File

@ -77,16 +77,20 @@ class CheckDefinitionValidityPass implements CompilerPassInterface
} }
} }
$resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs); if ($definition->isPublic() && !$definition->isPrivate()) {
if (null !== $usedEnvs) { $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
throw new EnvParameterException(array($resolvedId), null, 'A service name ("%s") cannot contain dynamic values.'); if (null !== $usedEnvs) {
throw new EnvParameterException(array($resolvedId), null, 'A service name ("%s") cannot contain dynamic values.');
}
} }
} }
foreach ($container->getAliases() as $id => $alias) { foreach ($container->getAliases() as $id => $alias) {
$resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs); if ($alias->isPublic() && !$alias->isPrivate()) {
if (null !== $usedEnvs) { $resolvedId = $container->resolveEnvPlaceholders($id, null, $usedEnvs);
throw new EnvParameterException(array($resolvedId), null, 'An alias name ("%s") cannot contain dynamic values.'); if (null !== $usedEnvs) {
throw new EnvParameterException(array($resolvedId), null, 'An alias name ("%s") cannot contain dynamic values.');
}
} }
} }
} }

View File

@ -35,7 +35,7 @@ class ResolveEnvPlaceholdersPass extends AbstractRecursivePass
$value = parent::processValue($value, $isRoot); $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); $value = array_combine($this->container->resolveEnvPlaceholders(array_keys($value), true), $value);
} }

View File

@ -1262,7 +1262,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
* true to resolve to the actual values of the referenced env vars * 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 * @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) public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs = null)
{ {

View File

@ -199,7 +199,7 @@ EOF;
sort($ids); sort($ids);
$c = "<?php\n\nreturn array(\n"; $c = "<?php\n\nreturn array(\n";
foreach ($ids as $id) { foreach ($ids as $id) {
$c .= ' '.$this->export($id)." => true,\n"; $c .= ' '.$this->doExport($id)." => true,\n";
} }
$files['removed-ids.php'] = $c .= ");\n"; $files['removed-ids.php'] = $c .= ");\n";
} }
@ -820,6 +820,7 @@ EOF;
private function addNewInstance(Definition $definition, $return, $instantiation, $id) private function addNewInstance(Definition $definition, $return, $instantiation, $id)
{ {
$class = $this->dumpValue($definition->getClass()); $class = $this->dumpValue($definition->getClass());
$return = ' '.$return.$instantiation;
$arguments = array(); $arguments = array();
foreach ($definition->getArguments() as $value) { foreach ($definition->getArguments() as $value) {
@ -835,7 +836,7 @@ EOF;
if ($callable[0] instanceof Reference if ($callable[0] instanceof Reference
|| ($callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0]))) { || ($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]); $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)); 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 ')) { 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, '$')) { 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 private function startClass(string $class, string $baseClass): string
@ -986,7 +987,7 @@ EOF;
ksort($definitions); ksort($definitions);
foreach ($definitions as $id => $definition) { foreach ($definitions as $id => $definition) {
if ($definition->isSynthetic() && 'service_container' !== $id) { 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); $ids = array_keys($ids);
sort($ids); sort($ids);
foreach ($ids as $id) { foreach ($ids as $id) {
$code .= ' '.$this->export($id)." => true,\n"; $code .= ' '.$this->doExport($id)." => true,\n";
} }
$code = "array(\n{$code} )"; $code = "array(\n{$code} )";
@ -1034,7 +1035,7 @@ EOF;
ksort($definitions); ksort($definitions);
foreach ($definitions as $id => $definition) { foreach ($definitions as $id => $definition) {
if (!$definition->isSynthetic() && $definition->isPublic() && (!$this->asFiles || !$definition->isShared() || $this->isHotPath($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); ksort($definitions);
foreach ($definitions as $id => $definition) { foreach ($definitions as $id => $definition) {
if (!$definition->isSynthetic() && $definition->isPublic() && $definition->isShared() && !$this->isHotPath($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])) { while (isset($aliases[$id])) {
$id = (string) $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"; return $code." );\n";
@ -1743,9 +1744,9 @@ EOF;
private function export($value) private function export($value)
{ {
if (null !== $this->targetDirRegex && is_string($value) && preg_match($this->targetDirRegex, $value, $matches, PREG_OFFSET_CAPTURE)) { 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 = $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__'; $dirname = '__DIR__';
$offset = 1 + $this->targetDirMaxMatches - count($matches); $offset = 1 + $this->targetDirMaxMatches - count($matches);
@ -1760,10 +1761,10 @@ EOF;
return $dirname; 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")) { if (is_string($value) && false !== strpos($value, "\n")) {
$cleanParts = explode("\n", $value); $cleanParts = explode("\n", $value);
@ -1773,7 +1774,7 @@ EOF;
$export = var_export($value, true); $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; $export = $resolvedExport;
if (".''" === substr($export, -3)) { if (".''" === substr($export, -3)) {
$export = substr($export, 0, -3); $export = substr($export, 0, -3);

View File

@ -79,11 +79,11 @@ class CheckDefinitionValidityPassTest extends TestCase
/** /**
* @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException * @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException
*/ */
public function testDynamicServiceName() public function testDynamicPublicServiceName()
{ {
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$env = $container->getParameterBag()->get('env(BAR)'); $env = $container->getParameterBag()->get('env(BAR)');
$container->register("foo.$env", 'class'); $container->register("foo.$env", 'class')->setPublic(true);
$this->process($container); $this->process($container);
} }
@ -91,15 +91,27 @@ class CheckDefinitionValidityPassTest extends TestCase
/** /**
* @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException * @expectedException \Symfony\Component\DependencyInjection\Exception\EnvParameterException
*/ */
public function testDynamicAliasName() public function testDynamicPublicAliasName()
{ {
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$env = $container->getParameterBag()->get('env(BAR)'); $env = $container->getParameterBag()->get('env(BAR)');
$container->setAlias("foo.$env", 'class'); $container->setAlias("foo.$env", 'class')->setPublic(true);
$this->process($container); $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) protected function process(ContainerBuilder $container)
{ {
$pass = new CheckDefinitionValidityPass(); $pass = new CheckDefinitionValidityPass();

View File

@ -716,6 +716,29 @@ class ContainerBuilderTest extends TestCase
$this->assertNull($container->get('foo')->fake); $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 * @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)"). * @expectedExceptionMessage Circular reference detected for parameter "env(resolve:DUMMY_ENV_VAR)" ("env(resolve:DUMMY_ENV_VAR)" > "env(resolve:DUMMY_ENV_VAR)").

View File

@ -325,6 +325,15 @@ class PhpDumperTest extends TestCase
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services24.php', $dumper->dump()); $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() public function testEnvParameter()
{ {
$rand = mt_rand(); $rand = mt_rand();

View File

@ -0,0 +1,22 @@
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Reference;
$container = new ContainerBuilder();
$container->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;

View File

@ -0,0 +1,149 @@
<?php
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
/**
* This class has been auto-generated
* by the Symfony Dependency Injection Component.
*
* @final since Symfony 3.3
*/
class ProjectServiceContainer extends Container
{
private $parameters;
private $targetDirs = array();
private $privates = array();
public function __construct()
{
$this->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',
);
}
}

View File

@ -34,7 +34,9 @@ class AnnotationDirectoryLoader extends AnnotationFileLoader
*/ */
public function load($path, $type = null) 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 = new RouteCollection();
$collection->addResource(new DirectoryResource($dir, '/\.php$/')); $collection->addResource(new DirectoryResource($dir, '/\.php$/'));
@ -74,16 +76,18 @@ class AnnotationDirectoryLoader extends AnnotationFileLoader
*/ */
public function supports($resource, $type = null) public function supports($resource, $type = null)
{ {
if (!is_string($resource)) { if ('annotation' === $type) {
return true;
}
if ($type || !is_string($resource)) {
return false; return false;
} }
try { try {
$path = $this->locator->locate($resource); return is_dir($this->locator->locate($resource));
} catch (\Exception $e) { } catch (\Exception $e) {
return false; return false;
} }
return is_dir($path) && (!$type || 'annotation' === $type);
} }
} }

View File

@ -69,6 +69,24 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
$this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified'); $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) private function expectAnnotationsToBeReadFrom(array $classes)
{ {
$this->reader->expects($this->exactly(count($classes))) $this->reader->expects($this->exactly(count($classes)))

View File

@ -21,12 +21,16 @@ class TranslatorPass implements CompilerPassInterface
private $translatorServiceId; private $translatorServiceId;
private $readerServiceId; private $readerServiceId;
private $loaderTag; 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->translatorServiceId = $translatorServiceId;
$this->readerServiceId = $readerServiceId; $this->readerServiceId = $readerServiceId;
$this->loaderTag = $loaderTag; $this->loaderTag = $loaderTag;
$this->debugCommandServiceId = $debugCommandServiceId;
$this->updateCommandServiceId = $updateCommandServiceId;
} }
public function process(ContainerBuilder $container) public function process(ContainerBuilder $container)
@ -59,5 +63,10 @@ class TranslatorPass implements CompilerPassInterface
->replaceArgument(0, ServiceLocatorTagPass::register($container, $loaderRefs)) ->replaceArgument(0, ServiceLocatorTagPass::register($container, $loaderRefs))
->replaceArgument(3, $loaders) ->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'));
}
} }
} }