Skip to content

Commit 9e9b41d

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [FrameworkBundle] Fix Incorrect line break in exception message (500 debug page) Minor cleanups and improvements [form] lazy trans `post_max_size_message`. [DI] Fix setting synthetic services on ContainerBuilder [ClassLoader] Fix ClassCollectionLoader inlining with declare(strict_types=1)
2 parents 2ce310f + 993b405 commit 9e9b41d

File tree

19 files changed

+114
-67
lines changed

19 files changed

+114
-67
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/public/css/body.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ build: 56
3939
font-family: Georgia, "Times New Roman", Times, serif;
4040
font-size: 20px;
4141
color: #313131;
42-
word-break: break-all;
42+
word-wrap: break-word;
4343
}
4444
.sf-reset li {
4545
padding-bottom: 10px;

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
5858

5959
$classes = array_unique($classes);
6060

61-
$cache = $cacheDir.'/'.$name.$extension;
61+
// cache the core classes
62+
if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
63+
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
64+
}
65+
$cacheDir = rtrim(realpath($cacheDir), '/'.DIRECTORY_SEPARATOR);
66+
$cache = $cacheDir.DIRECTORY_SEPARATOR.$name.$extension;
6267

6368
// auto-reload
6469
$reload = false;
@@ -99,31 +104,50 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
99104
}
100105
}
101106

107+
$c = '(?:\s*+(?:(?:#|//)[^\n]*+\n|/\*(?:(?<!\*/).)++)?+)*+';
108+
$strictTypesRegex = str_replace('.', $c, "'^<\?php\s.declare.\(.strict_types.=.1.\).;'is");
109+
110+
$cacheDir = explode(DIRECTORY_SEPARATOR, $cacheDir);
102111
$files = array();
103112
$content = '';
104113
foreach (self::getOrderedClasses($classes) as $class) {
105114
if (in_array($class->getName(), $declared)) {
106115
continue;
107116
}
108117

109-
$files[] = $class->getFileName();
118+
$files[] = $file = $class->getFileName();
119+
$c = file_get_contents($file);
110120

111-
$c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($class->getFileName()));
121+
if (preg_match($strictTypesRegex, $c)) {
122+
$file = explode(DIRECTORY_SEPARATOR, $file);
112123

113-
// fakes namespace declaration for global code
114-
if (!$class->inNamespace()) {
115-
$c = "\nnamespace\n{\n".$c."\n}\n";
116-
}
124+
for ($i = 0; isset($file[$i], $cacheDir[$i]); ++$i) {
125+
if ($file[$i] !== $cacheDir[$i]) {
126+
break;
127+
}
128+
}
129+
if (1 >= $i) {
130+
$file = var_export(implode(DIRECTORY_SEPARATOR, $file), true);
131+
} else {
132+
$file = array_slice($file, $i);
133+
$file = str_repeat('..'.DIRECTORY_SEPARATOR, count($cacheDir) - $i).implode(DIRECTORY_SEPARATOR, $file);
134+
$file = '__DIR__.'.var_export(DIRECTORY_SEPARATOR.$file, true);
135+
}
117136

118-
$c = self::fixNamespaceDeclarations('<?php '.$c);
119-
$c = preg_replace('/^\s*<\?php/', '', $c);
137+
$c = "\nnamespace {require $file;}";
138+
} else {
139+
$c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', $c);
120140

121-
$content .= $c;
122-
}
141+
// fakes namespace declaration for global code
142+
if (!$class->inNamespace()) {
143+
$c = "\nnamespace\n{\n".$c."\n}\n";
144+
}
123145

124-
// cache the core classes
125-
if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
126-
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
146+
$c = self::fixNamespaceDeclarations('<?php '.$c);
147+
$c = preg_replace('/^\s*<\?php/', '', $c);
148+
}
149+
150+
$content .= $c;
127151
}
128152
self::writeCacheFile($cache, '<?php '.$content);
129153

src/Symfony/Component/ClassLoader/Tests/ClassCollectionLoaderTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,20 @@ public function testUnableToLoadClassException()
223223

224224
public function testCommentStripping()
225225
{
226-
if (is_file($file = sys_get_temp_dir().'/bar.php')) {
226+
if (is_file($file = __DIR__.'/bar.php')) {
227227
unlink($file);
228228
}
229229
spl_autoload_register($r = function ($class) {
230230
if (0 === strpos($class, 'Namespaced') || 0 === strpos($class, 'Pearlike_')) {
231-
require_once __DIR__.'/Fixtures/'.str_replace(array('\\', '_'), '/', $class).'.php';
231+
@require_once __DIR__.'/Fixtures/'.str_replace(array('\\', '_'), '/', $class).'.php';
232232
}
233233
});
234234

235+
$strictTypes = defined('HHVM_VERSION') ? '' : "\nnamespace {require __DIR__.'/Fixtures/Namespaced/WithStrictTypes.php';}";
236+
235237
ClassCollectionLoader::load(
236-
array('Namespaced\\WithComments', 'Pearlike_WithComments'),
237-
sys_get_temp_dir(),
238+
array('Namespaced\\WithComments', 'Pearlike_WithComments', $strictTypes ? 'Namespaced\\WithStrictTypes' : 'Namespaced\\WithComments'),
239+
__DIR__,
238240
'bar',
239241
false
240242
);
@@ -274,7 +276,9 @@ class Pearlike_WithComments
274276
}
275277
}
276278
EOF
277-
, str_replace("<?php \n", '', file_get_contents($file)));
279+
.$strictTypes,
280+
str_replace(array("<?php \n", '\\\\'), array('', '/'), file_get_contents($file))
281+
);
278282

279283
unlink($file);
280284
}

src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function getTestCreateMapTests()
7676
'Namespaced\\Foo' => realpath(__DIR__).'/Fixtures/Namespaced/Foo.php',
7777
'Namespaced\\Baz' => realpath(__DIR__).'/Fixtures/Namespaced/Baz.php',
7878
'Namespaced\\WithComments' => realpath(__DIR__).'/Fixtures/Namespaced/WithComments.php',
79+
'Namespaced\WithStrictTypes' => realpath(__DIR__).'/Fixtures/Namespaced/WithStrictTypes.php',
7980
),
8081
),
8182
array(__DIR__.'/Fixtures/beta/NamespaceCollision', array(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/*
4+
* foo
5+
*/
6+
7+
declare (strict_types = 1);
8+
9+
namespace Namespaced;
10+
11+
class WithStrictTypes
12+
{
13+
}

src/Symfony/Component/DependencyInjection/Compiler/RepeatedPass.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,12 @@ public function __construct(array $passes)
5656
*/
5757
public function process(ContainerBuilder $container)
5858
{
59-
$this->repeat = false;
60-
foreach ($this->passes as $pass) {
61-
$pass->process($container);
62-
}
63-
64-
if ($this->repeat) {
65-
$this->process($container);
66-
}
59+
do {
60+
$this->repeat = false;
61+
foreach ($this->passes as $pass) {
62+
$pass->process($container);
63+
}
64+
} while ($this->repeat);
6765
}
6866

6967
/**

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -381,21 +381,14 @@ public function getScopeChildren($triggerDeprecationError = true)
381381
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
382382
{
383383
$id = strtolower($id);
384+
$set = isset($this->definitions[$id]);
384385

385-
if ($this->isFrozen()) {
386+
if ($this->isFrozen() && ($set || isset($this->obsoleteDefinitions[$id])) && !$this->{$set ? 'definitions' : 'obsoleteDefinitions'}[$id]->isSynthetic()) {
386387
// setting a synthetic service on a frozen container is alright
387-
if (
388-
(!isset($this->definitions[$id]) && !isset($this->obsoleteDefinitions[$id]))
389-
||
390-
(isset($this->definitions[$id]) && !$this->definitions[$id]->isSynthetic())
391-
||
392-
(isset($this->obsoleteDefinitions[$id]) && !$this->obsoleteDefinitions[$id]->isSynthetic())
393-
) {
394-
throw new BadMethodCallException(sprintf('Setting service "%s" on a frozen container is not allowed.', $id));
395-
}
388+
throw new BadMethodCallException(sprintf('Setting service "%s" on a frozen container is not allowed.', $id));
396389
}
397390

398-
if (isset($this->definitions[$id])) {
391+
if ($set) {
399392
$this->obsoleteDefinitions[$id] = $this->definitions[$id];
400393
}
401394

src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function addEdges()
130130
*
131131
* @return array An array of edges
132132
*/
133-
private function findEdges($id, $arguments, $required, $name)
133+
private function findEdges($id, array $arguments, $required, $name)
134134
{
135135
$edges = array();
136136
foreach ($arguments as $argument) {
@@ -246,7 +246,7 @@ private function endDot()
246246
*
247247
* @return string A comma separated list of attributes
248248
*/
249-
private function addAttributes($attributes)
249+
private function addAttributes(array $attributes)
250250
{
251251
$code = array();
252252
foreach ($attributes as $k => $v) {
@@ -263,7 +263,7 @@ private function addAttributes($attributes)
263263
*
264264
* @return string A space separated list of options
265265
*/
266-
private function addOptions($options)
266+
private function addOptions(array $options)
267267
{
268268
$code = array();
269269
foreach ($options as $k => $v) {

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ private function addServiceReturn($id, $definition)
375375
* @throws InvalidArgumentException
376376
* @throws RuntimeException
377377
*/
378-
private function addServiceInstance($id, $definition)
378+
private function addServiceInstance($id, Definition $definition)
379379
{
380380
$class = $definition->getClass();
381381

@@ -425,7 +425,7 @@ private function addServiceInstance($id, $definition)
425425
*
426426
* @return bool
427427
*/
428-
private function isSimpleInstance($id, $definition)
428+
private function isSimpleInstance($id, Definition $definition)
429429
{
430430
foreach (array_merge(array($definition), $this->getInlinedDefinitions($definition)) as $sDefinition) {
431431
if ($definition !== $sDefinition && !$this->hasReference($id, $sDefinition->getMethodCalls())) {
@@ -449,7 +449,7 @@ private function isSimpleInstance($id, $definition)
449449
*
450450
* @return string
451451
*/
452-
private function addServiceMethodCalls($id, $definition, $variableName = 'instance')
452+
private function addServiceMethodCalls($id, Definition $definition, $variableName = 'instance')
453453
{
454454
$calls = '';
455455
foreach ($definition->getMethodCalls() as $call) {
@@ -464,7 +464,7 @@ private function addServiceMethodCalls($id, $definition, $variableName = 'instan
464464
return $calls;
465465
}
466466

467-
private function addServiceProperties($id, $definition, $variableName = 'instance')
467+
private function addServiceProperties($id, Definition $definition, $variableName = 'instance')
468468
{
469469
$code = '';
470470
foreach ($definition->getProperties() as $name => $value) {
@@ -484,7 +484,7 @@ private function addServiceProperties($id, $definition, $variableName = 'instanc
484484
*
485485
* @throws ServiceCircularReferenceException when the container contains a circular reference
486486
*/
487-
private function addServiceInlinedDefinitionsSetup($id, $definition)
487+
private function addServiceInlinedDefinitionsSetup($id, Definition $definition)
488488
{
489489
$this->referenceVariables[$id] = new Variable('instance');
490490

@@ -528,7 +528,7 @@ private function addServiceInlinedDefinitionsSetup($id, $definition)
528528
*
529529
* @return string
530530
*/
531-
private function addServiceConfigurator($id, $definition, $variableName = 'instance')
531+
private function addServiceConfigurator($id, Definition $definition, $variableName = 'instance')
532532
{
533533
if (!$callable = $definition->getConfigurator()) {
534534
return '';
@@ -560,7 +560,7 @@ private function addServiceConfigurator($id, $definition, $variableName = 'insta
560560
*
561561
* @return string
562562
*/
563-
private function addService($id, $definition)
563+
private function addService($id, Definition $definition)
564564
{
565565
$this->definitionVariables = new \SplObjectStorage();
566566
$this->referenceVariables = array();
@@ -1144,7 +1144,7 @@ protected function getDefaultParameters()
11441144
*
11451145
* @throws InvalidArgumentException
11461146
*/
1147-
private function exportParameters($parameters, $path = '', $indent = 12)
1147+
private function exportParameters(array $parameters, $path = '', $indent = 12)
11481148
{
11491149
$php = array();
11501150
foreach ($parameters as $key => $value) {

src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private function addServices(\DOMElement $parent)
286286
* @param \DOMElement $parent
287287
* @param string $keyAttribute
288288
*/
289-
private function convertParameters($parameters, $type, \DOMElement $parent, $keyAttribute = 'key')
289+
private function convertParameters(array $parameters, $type, \DOMElement $parent, $keyAttribute = 'key')
290290
{
291291
$withKeys = array_keys($parameters) !== range(0, count($parameters) - 1);
292292
foreach ($parameters as $key => $value) {
@@ -335,7 +335,7 @@ private function convertParameters($parameters, $type, \DOMElement $parent, $key
335335
*
336336
* @return array
337337
*/
338-
private function escape($arguments)
338+
private function escape(array $arguments)
339339
{
340340
$args = array();
341341
foreach ($arguments as $k => $v) {

src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ private function getExpressionCall($expression)
327327
*
328328
* @return array
329329
*/
330-
private function prepareParameters($parameters, $escape = true)
330+
private function prepareParameters(array $parameters, $escape = true)
331331
{
332332
$filtered = array();
333333
foreach ($parameters as $key => $value) {
@@ -350,7 +350,7 @@ private function prepareParameters($parameters, $escape = true)
350350
*
351351
* @return array
352352
*/
353-
private function escape($arguments)
353+
private function escape(array $arguments)
354354
{
355355
$args = array();
356356
foreach ($arguments as $k => $v) {

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,9 @@ private function resolveServices($value)
420420
{
421421
if (is_array($value)) {
422422
$value = array_map(array($this, 'resolveServices'), $value);
423-
} elseif (is_string($value) && 0 === strpos($value, '@=')) {
423+
} elseif (is_string($value) && 0 === strpos($value, '@=')) {
424424
return new Expression(substr($value, 2));
425-
} elseif (is_string($value) && 0 === strpos($value, '@')) {
425+
} elseif (is_string($value) && 0 === strpos($value, '@')) {
426426
if (0 === strpos($value, '@@')) {
427427
$value = substr($value, 1);
428428
$invalidBehavior = null;

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,14 +677,12 @@ public function testThrowsExceptionWhenSetServiceOnAFrozenContainer()
677677
$container->set('a', new \stdClass());
678678
}
679679

680-
/**
681-
* @expectedException \BadMethodCallException
682-
*/
683680
public function testThrowsExceptionWhenAddServiceOnAFrozenContainer()
684681
{
685682
$container = new ContainerBuilder();
686683
$container->compile();
687-
$container->set('a', new \stdClass());
684+
$container->set('a', $foo = new \stdClass());
685+
$this->assertSame($foo, $container->get('a'));
688686
}
689687

690688
public function testNoExceptionWhenSetSyntheticServiceOnAFrozenContainer()

src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function testGetReturnsNullOnInactiveScope()
269269

270270
/**
271271
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
272-
* @expectedExcepionMessage You have requested a synthetic service ("request"). The DIC does not know how to construct this service.
272+
* @expectedExceptionMessage You have requested a synthetic service ("request"). The DIC does not know how to construct this service.
273273
*/
274274
public function testGetSyntheticServiceAlwaysThrows()
275275
{

src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ public function configureOptions(OptionsResolver $resolver)
145145
};
146146
};
147147

148+
// Wrap "post_max_size_message" in a closure to translate it lazily
149+
$uploadMaxSizeMessage = function (Options $options) {
150+
return function () use ($options) {
151+
return $options['post_max_size_message'];
152+
};
153+
};
154+
148155
// For any form that is not represented by a single HTML control,
149156
// errors should bubble up by default
150157
$errorBubbling = function (Options $options) {
@@ -225,12 +232,14 @@ public function configureOptions(OptionsResolver $resolver)
225232
'action' => '',
226233
'attr' => $defaultAttr,
227234
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
235+
'upload_max_size_message' => $uploadMaxSizeMessage, // internal
228236
));
229237

230238
$resolver->setNormalizer('attr', $attrNormalizer);
231239
$resolver->setNormalizer('read_only', $readOnlyNormalizer);
232240

233241
$resolver->setAllowedTypes('label_attr', 'array');
242+
$resolver->setAllowedTypes('upload_max_size_message', array('callable'));
234243
}
235244

236245
/**

0 commit comments

Comments
 (0)