8000 Merge branch '2.7' into 2.8 · symfony/symfony@be6af2e · GitHub
[go: up one dir, main page]

Skip to content

Commit be6af2e

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 46994a1 + 6e75cee commit be6af2e

File tree

23 files changed

+318
-34
lines changed

23 files changed

+318
-34
lines changed

src/Symfony/Bundle/FrameworkBundle/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);

src/Symfony/Bundle/FrameworkBundle/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')

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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

src/Symfony/Bundle/FrameworkBundle/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);

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function showAction(Request $request, FlattenException $exception, DebugL
7272
'logger' => $logger,
7373
'currentContent' => $currentContent,
7474
)
75-
));
75+
), 200, array('Content-Type' => $request->getMimeType($request->getRequestFormat()) ?: 'text/html'));
7676
}
7777

7878
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public function process(ContainerBuilder $container)
9696
$twigLoader->clearTag('twig.loader');
9797
} else {
9898
$container->setAlias('twig.loader.filesystem', new Alias('twig.loader.native_filesystem', false));
99+
$container->removeDefinition('templating.engine.twig');
99100
}
100101

101102
if ($container->has('assets.packages')) {

src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,57 @@ class ExceptionControllerTest extends TestCase
2222
{
2323
public function testShowActionCanBeForcedToShowErrorPage()
2424
{
25-
$twig = new Environment(
26-
new ArrayLoader(array(
27-
'@Twig/Exception/error404.html.twig' => 'ok',
28-
))
29-
);
25+
$twig = $this->createTwigEnv(array('@Twig/Exception/error404.html.twig' => '<html>not found</html>'));
3026

31-
$request = Request::create('whatever', 'GET');
32-
$request->headers->set('X-Php-Ob-Level', 1);
27+
$request = $this->createRequest('html');
3328
$request->attributes->set('showException', false);
3429
$exception = FlattenException::create(new \Exception(), 404);
3530
$controller = new ExceptionController($twig, /* "showException" defaults to --> */ true);
3631

3732
$response = $controller->showAction($request, $exception, null);
3833

3934
$this->assertEquals(200, $response->getStatusCode()); // successful request
40-
$this->assertEquals('ok', $response->getContent()); // content of the error404.html template
35+
$this->assertEquals('<html>not found</html>', $response->getContent());
4136
}
4237

4338
public function testFallbackToHtmlIfNoTemplateForRequestedFormat()
4439
{
45-
$twig = new Environment(
46-
new ArrayLoader(array(
47-
'@Twig/Exception/error.html.twig' => 'html',
48-
))
49-
);
40+
$twig = $this->createTwigEnv(array('@Twig/Exception/error.html.twig' => '<html></html>'));
5041

51-
$request = Request::create('whatever');
52-
$request->headers->set('X-Php-Ob-Level', 1);
53-
$request->setRequestFormat('txt');
42+
$request = $this->createRequest('txt');
5443
$exception = FlattenException::create(new \Exception());
5544
$controller = new ExceptionController($twig, false);
5645

57-
$response = $controller->showAction($request, $exception);
46+
$controller->showAction($request, $exception);
5847

5948
$this->assertEquals('html', $request->getRequestFormat());
6049
}
50+
51+
public function testResponseHasRequestedMimeType()
52+
{
53+
$twig = $this->createTwigEnv(array('@Twig/Exception/error.json.twig' => '{}'));
54+
55+
$request = $this->createRequest('json');
56+
$exception = FlattenException::create(new \Exception());
57+
$controller = new ExceptionController($twig, false);
58+
59+
$response = $controller->showAction($request, $exception);
60+
61+
$this->assertEquals('json', $request->getRequestFormat());
62+
$this->assertEquals($request->getMimeType('json'), $response->headers->get('Content-Type'));
63+
}
64+
65+
private function createRequest($requestFormat)
66+
{
67+
$request = Request::create('whatever');
68+
$request->headers->set('X-Php-Ob-Level', 1);
69+
$request->setRequestFormat($requestFormat);
70+
71+
return $request;
72+
}
73+
74+
private function createTwigEnv(array $templates)
75+
{
76+
return new Environment(new ArrayLoader($templates));
77+
}
6178
}

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ public function followRedirect()
468468

469469
if (-1 !== $this->maxRedirects) {
470470
if ($this->redirectCount > $this->maxRedirects) {
471+
$this->redirectCount = 0;
471472
throw new \LogicException(sprintf('The maximum number (%d) of redirections was reached.', $this->maxRedirects));
472473
}
473474
}

0 commit comments

Comments
 (0)
0