Skip to content

Commit 430f425

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [Routing] Fix XmlFileLoader exception message Sessions: configurable "use_strict_mode" option for NativeSessionStorage [FrameworkBundle] [Command] Clean bundle directory, fixes #23177 Reset redirectCount when throwing exception [TwigBundle] Remove template.xml services when templating is disabled add content-type header on exception response Embedding a response that combines expiration and validation, that should not defeat expiration on the combined response Fix two edge cases in ResponseCacheStrategy [Routing] Expose request in route conditions, if needed and possible [Routing] Expose request in route conditions, if needed and possible [Translation][FrameworkBundle] Fix resource loading order inconsistency reported in #23034 [Filesystem] added workaround in Filesystem::rename for PHP bug Add tests for ResponseCacheStrategy to document some more edge cases [HttpFoundation] added missing docs fixes #21606 [VarDumper] fixes [Security] fix switch user _exit without having current token
2 parents 784a0f9 + 3edff42 commit 430f425

File tree

6 files changed

+78
-8
lines changed

6 files changed

+78
-8
lines changed

Command/AssetsInstallCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
110110
$rows = array();
111111
$copyUsed = false;
112112
$exitCode = 0;
113+
$validAssetDirs = array();
113114
/** @var BundleInterface $bundle */
114115
foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) {
115116
if (!is_dir($originDir = $bundle->getPath().'/Resources/public')) {
@@ -148,6 +149,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
148149
$exitCode = 1;
149150
$rows[] = array(sprintf('<fg=red;options=bold>%s</>', '\\' === DIRECTORY_SEPARATOR ? 'ERROR' : "\xE2\x9C\x98" /* HEAVY BALLOT X (U+2718) */), $message, $e->getMessage());
150151
}
152+
$validAssetDirs[] = $targetDir;
153+
}
154+
// remove the assets of the bundles that no longer exist
155+
foreach (new \FilesystemIterator($bundlesDir) as $dir) {
156+
if (!in_array($dir, $validAssetDirs)) {
157+
$filesystem->remove($dir);
158+
}
151159
}
152160

153161
$io->table(array('', 'Bundle', 'Method / Error'), $rows);

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ private function addSessionSection(ArrayNodeDefinition $rootNode)
390390
->scalarNode('gc_divisor')->end()
391391
->scalarNode('gc_probability')->defaultValue(1)->end()
392392
->scalarNode('gc_maxlifetime')->end()
393+
->booleanNode('use_strict_mode')->end()
393394
->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end()
394395
->integerNode('metadata_update_threshold')
395396
->defaultValue('0')

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ private function registerSessionConfiguration(array $config, ContainerBuilder $c
406406
// session storage
407407
$container->setAlias('session.storage', $config['storage_id']);
408408
$options = array();
409-
foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'use_cookies', 'gc_maxlifetime', 'gc_probability', 'gc_divisor') as $key) {
409+
foreach (array('name', 'cookie_lifetime', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'use_cookies', 'gc_maxlifetime', 'gc_probability', 'gc_divisor', 'use_strict_mode') as $key) {
410410
if (isset($config[$key])) {
411411
$options[$key] = $config[$key];
412412
}

Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
<xsd:attribute name="gc-maxlifetime" type="xsd:string" />
114114
<xsd:attribute name="gc-divisor" type="xsd:string" />
115115
<xsd:attribute name="gc-probability" type="xsd:string" />
116+
<xsd:attribute name="use-strict-mode" type="xsd:boolean" />
116117
<xsd:attribute name="save-path" type="xsd:string" />
117118
</xsd:complexType>
118119

Tests/Translation/TranslatorTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,51 @@ public function testGetDefaultLocale()
135135
$this->assertSame('en', $translator->getLocale());
136136
}
137137

138+
/** @dataProvider getDebugModeAndCacheDirCombinations */
139+
public function testResourceFilesOptionLoadsBeforeOtherAddedResources($debug, $enableCache)
140+
{
141+
$someCatalogue = $this->getCatalogue('some_locale', array());
142+
143+
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
144+
145+
$loader->expects($this->at(0))
146+
->method('load')
147+
/* The "messages.some_locale.loader" is passed via the resource_file option and shall be loaded first */
148+
->with('messages.some_locale.loader', 'some_locale', 'messages')
149+
->willReturn($someCatalogue);
150+
151+
$loader->expects($this->at(1))
152+
->method('load')
153+
/* This resource is added by an addResource() call and shall be loaded after the resource_files */
154+
->with('second_resource.some_locale.loader', 'some_locale', 'messages')
155+
->willReturn($someCatalogue);
156+
157+
$options = array(
158+
'resource_files' => array('some_locale' => array('messages.some_locale.loader')),
159+
'debug' => $debug,
160+
);
161+
162+
if ($enableCache) {
163+
$options['cache_dir'] = $this->tmpDir;
164+
}
165+
166+
/** @var Translator $translator */
167+
$translator = $this->createTranslator($loader, $options);
168+
$translator->addResource('loader', 'second_resource.some_locale.loader', 'some_locale', 'messages');
169+
170+
$translator->trans('some_message', array(), null, 'some_locale');
171+
}
172+
173+
public function getDebugModeAndCacheDirCombinations()
174+
{
175+
return array(
176+
array(false, false),
177+
array(true, false),
178+
array(false, true),
179+
array(true, true),
180+
);
181+
}
182+
138183
protected function getCatalogue($locale, $messages, $resources = array())
139184
{
140185
$catalogue = new MessageCatalogue($locale);

Translation/Translator.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ class Translator extends BaseTranslator implements WarmableInterface
3737
*/
3838
private $resourceLocales;
3939

40+
/**
41+
* Holds parameters from addResource() calls so we can defer the actual
42+
* parent::addResource() calls until initialize() is executed.
43+
*
44+
* @var array
45+
*/
46+
private $resources = array();
47+
4048
/**
4149
* Constructor.
4250
*
@@ -65,9 +73,7 @@ public function __construct(ContainerInterface $container, MessageSelector $sele
6573

6674
$this->options = array_merge($this->options, $options);
6775
$this->resourceLocales = array_keys($this->options['resource_files']);
68-
if (null !== $this->options['cache_dir'] && $this->options['debug']) {
69-
$this->loadResources();
70-
}
76+
$this->addResourceFiles($this->options['resource_files']);
7177

7278
parent::__construct($container->getParameter('kernel.default_locale'), $selector, $this->options['cache_dir'], $this->options['debug']);
7379
}
@@ -93,6 +99,11 @@ public function warmUp($cacheDir)
9399
}
94100
}
95101

102+
public function addResource($format, $resource, $locale, $domain = null)
103+
{
104+
$this->resources[] = array($format, $resource, $locale, $domain);
105+
}
106+
96107
/**
97108
* {@inheritdoc}
98109
*/
@@ -104,22 +115,26 @@ protected function initializeCatalogue($locale)
104115

105116
protected function initialize()
106117
{
107-
$this->loadResources();
118+
foreach ($this->resources as $key => $params) {
119+
list($format, $resource, $locale, $domain) = $params;
120+
parent::addResource($format, $resource, $locale, $domain);
121+
}
122+
$this->resources = array();
123+
108124
foreach ($this->loaderIds as $id => $aliases) {
109125
foreach ($aliases as $alias) {
110126
$this->addLoader($alias, $this->container->get($id));
111127
}
112128
}
113129
}
114130

115-
private function loadResources()
131+
private function addResourceFiles($filesByLocale)
116132
{
117-
foreach ($this->options['resource_files'] as $locale => $files) {
133+
foreach ($filesByLocale as $locale => $files) {
118134
foreach ($files as $key => $file) {
119135
// filename is domain.locale.format
120136
list($domain, $locale, $format) = explode('.', basename($file), 3);
121137
$this->addResource($format, $file, $locale, $domain);
122-
unset($this->options['resource_files'][$locale][$key]);
123138
}
124139
}
125140
}

0 commit comments

Comments
 (0)