Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c885d23

Browse files
Merge branch '3.2'
* 3.2: [Security] Fix test [Validator] phpize default option values test for the Validator component to be present [Serializer] Fix MaxDepth annotation exceptions [DependencyInjection] Fix on-invalid attribute type in xsd [FrameworkBundle] Fix PHP form templates on translatable attributes [VarDumper] Fix dumping by-ref variadics [Validator] add Indonesian translation fixed CS [config] Fix issue when key removed and left value only [HttpFoundation] Fix cookie to string conversion for raw cookies Fix misresolved parameters in debug:config on 3.2 [Console] fixed BC issue with static closures [TwigBundle] Config is now a hard dependency [FrameworkBundle] framework.annotations default should be true only if doctrine/annotations is installed [Security] AbstractVoter method supportsAttribute gives false positive if attribute is zero (0)
2 parents 200516a + b9a74f3 commit c885d23

File tree

22 files changed

+331
-39
lines changed

22 files changed

+331
-39
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8383
$configs = $container->resolveEnvPlaceholders($container->getParameterBag()->resolveValue($configs));
8484

8585
$processor = new Processor();
86-
$config = $processor->processConfiguration($configuration, $configs);
86+
$config = $container->resolveEnvPlaceholders($container->getParameterBag()->resolveValue($processor->processConfiguration($configuration, $configs)));
8787

8888
if (null === $path = $input->getArgument('path')) {
8989
$io->title(
@@ -105,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
105105

106106
$io->title(sprintf('Current configuration for "%s.%s"', $extensionAlias, $path));
107107

108-
$io->writeln(Yaml::dump($container->getParameterBag()->resolveValue($config), 10));
108+
$io->writeln(Yaml::dump($config, 10));
109109
}
110110

111111
private function compileContainer()
@@ -130,7 +130,7 @@ private function compileContainer()
130130
*
131131
* @return mixed
132132
*/
133-
private function getConfigForPath(array $config = array(), $path, $alias)
133+
private function getConfigForPath(array $config, $path, $alias)
134134
{
135135
$steps = explode('.', $path);
136136

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
1313

14+
use Doctrine\Common\Annotations\Annotation;
1415
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1516
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1617
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -602,7 +603,7 @@ private function addAnnotationsSection(ArrayNodeDefinition $rootNode)
602603
->children()
603604
->arrayNode('annotations')
604605
->info('annotation configuration')
605-
->canBeDisabled()
606+
->{class_exists(Annotation::class) ? 'canBeDisabled' : 'canBeEnabled'}()
606607
->children()
607608
->scalarNode('cache')->defaultValue('php_array')->end()
608609
->scalarNode('file_cache_dir')->defaultValue('%kernel.cache_dir%/annotations')->end()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,10 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
914914
return;
915915
}
916916

917+
if (!class_exists('Symfony\Component\Validator\Validation')) {
918+
throw new LogicException('Validation support cannot be enabled as the Validator component is not installed.');
919+
}
920+
917921
$loader->load('validator.xml');
918922

919923
$validatorBuilder = $container->getDefinition('validator.builder');

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/button_attributes.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>" <?php if ($disabled): ?>disabled="disabled" <?php endif ?>
22
<?php foreach ($attr as $k => $v): ?>
3-
<?php if (in_array($v, array('placeholder', 'title'), true)): ?>
3+
<?php if (in_array($k, array('placeholder', 'title'), true)): ?>
44
<?php printf('%s="%s" ', $view->escape($k), $view->escape(false !== $translation_domain ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?>
55
<?php elseif ($v === true): ?>
66
<?php printf('%s="%s" ', $view->escape($k), $view->escape($k)) ?>

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/widget_container_attributes.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php if (!empty($id)): ?>id="<?php echo $view->escape($id) ?>" <?php endif ?>
22
<?php foreach ($attr as $k => $v): ?>
3-
<?php if (in_array($v, array('placeholder', 'title'), true)): ?>
3+
<?php if (in_array($k, array('placeholder', 'title'), true)): ?>
44
<?php printf('%s="%s" ', $view->escape($k), $view->escape(false !== $translation_domain ? $view['translator']->trans($v, array(), $translation_domain) : $v)) ?>
55
<?php elseif ($v === true): ?>
66
<?php printf('%s="%s" ', $view->escape($k), $view->escape($k)) ?>

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ public function testDumpBundleOption()
4848
$this->assertContains('foo', $tester->getDisplay());
4949
}
5050

51+
public function testParametersValuesAreResolved()
52+
{
53+
$tester = $this->createCommandTester();
54+
$ret = $tester->execute(array('name' => 'framework'));
55+
56+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
57+
$this->assertContains("locale: '%env(LOCALE)%'", $tester->getDisplay());
58+
$this->assertContains('secret: test', $tester->getDisplay());
59+
}
60+
5161
public function testDumpUndefinedBundleOption()
5262
{
5363
$tester = $this->createCommandTester();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
imports:
22
- { resource: ../config/default.yml }
3+
4+
framework:
5+
secret: '%secret%'
6+
default_locale: '%env(LOCALE)%'
7+
8+
parameters:
9+
env(LOCALE): en
10+
secret: test

src/Symfony/Bundle/TwigBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.5.9",
20+
"symfony/config": "~3.2",
2021
"symfony/twig-bridge": "^3.2.1",
2122
"symfony/http-foundation": "~2.8|~3.0",
2223
"symfony/http-kernel": "~2.8|~3.0",
@@ -27,7 +28,6 @@
2728
"symfony/stopwatch": "~2.8|~3.0",
2829
"symfony/dependency-injection": "~2.8|~3.0",
2930
"symfony/expression-language": "~2.8|~3.0",
30-
"symfony/config": "~3.2",
3131
"symfony/finder": "~2.8|~3.0",
3232
"symfony/routing": "~2.8|~3.0",
3333
"symfony/templating": "~2.8|~3.0",

src/Symfony/Component/Config/Definition/PrototypedArrayNode.php

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class PrototypedArrayNode extends ArrayNode
2929
protected $minNumberOfElements = 0;
3030
protected $defaultValue = array();
3131
protected $defaultChildren;
32+
/**
33+
* @var NodeInterface[] An array of the prototypes of the simplified value children
34+
*/
35+
private $valuePrototypes = array();
3236

3337
/**
3438
* Sets the minimum number of elements that a prototype based node must
@@ -194,9 +198,9 @@ protected function finalizeValue($value)
194198
}
195199

196200
foreach ($value as $k => $v) {
197-
$this->prototype->setName($k);
201+
$prototype = $this->getPrototypeForChild($k);
198202
try {
199-
$value[$k] = $this->prototype->finalize($v);
203+
$value[$k] = $prototype->finalize($v);
200204
} catch (UnsetKeyException $e) {
201205
unset($value[$k]);
202206
}
@@ -250,8 +254,18 @@ protected function normalizeValue($value)
250254
}
251255

252256
// if only "value" is left
253-
if (1 == count($v) && isset($v['value'])) {
257+
if (array_keys($v) === array('value')) {
254258
$v = $v['value'];
259+
if ($this->prototype instanceof ArrayNode && ($children = $this->prototype->getChildren()) && array_key_exists('value', $children)) {
260+
$valuePrototype = current($this->valuePrototypes) ?: clone $children['value'];
261+
$valuePrototype->parent = $this;
262+
$originalClosures = $this->prototype->normalizationClosures;
263+
if (is_array($originalClosures)) {
264+
$valuePrototypeClosures = $valuePrototype->normalizationClosures;
265+
$valuePrototype->normalizationClosures = is_array($valuePrototypeClosures) ? array_merge($originalClosures, $valuePrototypeClosures) : $originalClosures;
266+
}
267+
$this->valuePrototypes[$k] = $valuePrototype;
268+
}
255269
}
256270
}
257271

@@ -264,11 +278,11 @@ protected function normalizeValue($value)
264278
}
265279
}
266280

267-
$this->prototype->setName($k);
281+
$prototype = $this->getPrototypeForChild($k);
268282
if (null !== $this->keyAttribute || $isAssoc) {
269-
$normalized[$k] = $this->prototype->normalize($v);
283+
$normalized[$k] = $prototype->normalize($v);
270284
} else {
271-
$normalized[] = $this->prototype->normalize($v);
285+
$normalized[] = $prototype->normalize($v);
272286
}
273287
}
274288

@@ -322,10 +336,54 @@ protected function mergeValues($leftSide, $rightSide)
322336
continue;
323337
}
324338

325-
$this->prototype->setName($k);
326-
$leftSide[$k] = $this->prototype->merge($leftSide[$k], $v);
339+
$prototype = $this->getPrototypeForChild($k);
340+
$leftSide[$k] = $prototype->merge($leftSide[$k], $v);
327341
}
328342

329343
return $leftSide;
330344
}
345+
346+
/**
347+
* Returns a prototype for the child node that is associated to $key in the value array.
348+
* For general child nodes, this will be $this->prototype.
349+
* But if $this->removeKeyAttribute is true and there are only two keys in the child node:
350+
* one is same as this->keyAttribute and the other is 'value', then the prototype will be different.
351+
*
352+
* For example, assume $this->keyAttribute is 'name' and the value array is as follows:
353+
* array(
354+
* array(
355+
* 'name' => 'name001',
356+
* 'value' => 'value001'
357+
* )
358+
* )
359+
*
360+
* Now, the key is 0 and the child node is:
361+
* array(
362+
* 'name' => 'name001',
363+
* 'value' => 'value001'
364+
* )
365+
*
366+
* When normalizing the value array, the 'name' element will removed from the child node
367+
* and its value becomes the new key of the child node:
368+
* array(
369+
* 'name001' => array('value' => 'value001')
370+
* )
371+
*
372+
* Now only 'value' element is left in the child node which can be further simplified into a string:
373+
* array('name001' => 'value001')
374+
*
375+
* Now, the key becomes 'name001' and the child node becomes 'value001' and
376+
* the prototype of child node 'name001' should be a ScalarNode instead of an ArrayNode instance.
377+
*
378+
* @param string $key The key of the child node
379+
*
380+
* @return mixed The prototype instance
381+
*/
382+
private function getPrototypeForChild($key)
383+
{
384+
$prototype = isset($this->valuePrototypes[$key]) ? $this->valuePrototypes[$key] : $this->prototype;
385+
$prototype->setName($key);
386+
387+
return $prototype;
388+
}
331389
}

0 commit comments

Comments
 (0)