8000 Merge branch '3.3' into 3.4 · symfony/symfony@f74eced · GitHub
[go: up one dir, main page]

Skip to content

Commit f74eced

Browse files
committed
Merge branch '3.3' into 3.4
* 3.3: [DI] Fix infinite loop in InlineServiceDefinitionsPass Do not cache cache attributes if `attributes` is in the context Test that it do not remove the new flashes when displaying the existing ones [HttpFoundation] AutExpireFlashBag should not clear new flashes [FrameworkBundle][Serializer] Remove YamlEncoder definition if Yaml component isn't installed [DI] Fix tracking of env vars in exceptions [Form] Don't rely on if http-foundation isn't in FileType Fix merge substitute aliases in inline mappings added ability for substitute aliases when mapping in YAML is on single line [Console] Fix global console flag when used in chain
2 parents 1f14f4d + b4afeb2 commit f74eced

File tree

15 files changed

+195
-35
lines changed

15 files changed

+195
-35
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
use Symfony\Component\WebLink\HttpHeaderSerializer;
7777
use Symfony\Component\Workflow;
7878
use Symfony\Component\Yaml\Command\LintCommand as BaseYamlLintCommand;
79+
use Symfony\Component\Yaml\Yaml;
7980

8081
/**
8182
* FrameworkExtension.
@@ -1442,6 +1443,10 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
14421443
$container->removeDefinition('serializer.normalizer.object');
14431444
}
14441445

1446+
if (!class_exists(Yaml::class)) {
1447+
$container->removeDefinition('serializer.encoder.yaml');
1448+
}
1449+
14451450
$serializerLoaders = array();
14461451
if (isset($config['enable_annotations']) && $config['enable_annotations']) {
14471452
if (!$this->annotationsConfigEnabled) {

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ public function hasParameterOption($values, $onlyParams = false)
285285
if ($token === $value || 0 === strpos($token, $value.'=')) {
286286
return true;
287287
}
288+
289+
if (0 === strpos($token, '-') && 0 !== strpos($token, '--')) {
290+
$searchableToken = str_replace('-', '', $token);
291+
$searchableValue = str_replace('-', '', $value);
292+
if ('' !== $searchableToken && '' !== $searchableValue && false !== strpos($searchableToken, $searchableValue)) {
293+
return true;
294+
}
295+
}
288296
}
289297
}
290298

src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ public function testHasParameterOption()
314314
$input = new ArgvInput(array('cli.php', '-f', 'foo'));
315315
$this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input');
316316

317+
$input = new ArgvInput(array('cli.php', '-fh'));
318+
$this->assertTrue($input->hasParameterOption('-fh'), '->hasParameterOption() returns true if the given short option is in the raw input');
319+
317320
$input = new ArgvInput(array('cli.php', '--foo', 'foo'));
318321
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given short option is in the raw input');
319322

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ protected function processValue($value, $isRoot = false)
6565
$this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId));
6666
$this->inlinedServiceIds[$id][] = $this->currentId;
6767

68-
if ($definition->isShared()) {
69-
return $definition;
70-
}
71-
$value = clone $definition;
68+
return $definition->isShared() ? $definition : clone $definition;
7269
}
7370
}
7471

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,26 @@ public function process(ContainerBuilder $container)
5656
}
5757
$config = $resolvingBag->resolveValue($config);
5858

59-
$tmpContainer = new MergeExtensionConfigurationContainerBuilder($extension, $resolvingBag);
60-
$tmpContainer->setResourceTracking($container->isTrackingResources());
61-
$tmpContainer->addObjectResource($extension);
62-
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
63-
$tmpContainer->addObjectResource($configuration);
64-
}
59+
try {
60+
$tmpContainer = new MergeExtensionConfigurationContainerBuilder($extension, $resolvingBag);
61+
$tmpContainer->setResourceTracking($container->isTrackingResources());
62+
$tmpContainer->addObjectResource($extension);
63+
if ($extension instanceof ConfigurationExtensionInterface && null !== $configuration = $extension->getConfiguration($config, $tmpContainer)) {
64+
$tmpContainer->addObjectResource($configuration);
65+
}
6566

66-
foreach ($exprLangProviders as $provider) {
67-
$tmpContainer->addExpressionLanguageProvider($provider);
68-
}
67+
foreach ($exprLangProviders as $provider) {
68+
$tmpContainer->addExpressionLanguageProvider($provider);
69+
}
6970

70-
$extension->load($config, $tmpContainer);
71+
$extension->load($config, $tmpContainer);
72+
} catch (\Exception $e) {
73+
if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
74+
$container->getParameterBag()->mergeEnvPlaceholders($resolvingBag);
75+
}
76+
77+
throw $e;
78+
}
7179

7280
if ($resolvingBag instanceof MergeExtensionConfigurationParameterBag) {
7381
// don't keep track of env vars that are *overridden* when configs are merged

src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ public function testProcessDoesInlineNonSharedService()
9292
$this->assertNotSame($container->getDefinition('bar'), $arguments[2]);
9393
}
9494

95+
public function testProcessInlinesMixedServicesLoop()
96+
{
97+
$container = new ContainerBuilder();
98+
$container
99+
->register('foo')
100+
->addArgument(new Reference('bar'))
101+
->setShared(false)
102+
;
103+
$container
104+
->register('bar')
105+
->setPublic(false)
106+
->addMethodCall('setFoo', array(new Reference('foo')))
107+
;
108+
109+
$this->process($container);
110+
111+
$this->assertEquals($container->getDefinition('foo')->getArgument(0), $container->getDefinition('bar'));
112+
}
113+
95114
public function testProcessInlinesIfMultipleReferencesButAllFromTheSa 2851 meDefinition()
96115
{
97116
$container = new ContainerBuilder();

src/Symfony/Component/DependencyInjection/Tests/Compiler/MergeExtensionConfigurationPassTest.php

Lines changed: 35 additions & 1 deletion
Original file F438 line numberDiff line numberDiff line change
@@ -110,10 +110,26 @@ public function testProcessedEnvsAreIncompatibleWithResolve()
110110
{
111111
$container = new ContainerBuilder();
112112
$container->registerExtension(new BarExtension());
113-
$container->prependExtensionConfig('bar', array());
113+
$container->prependExtensionConfig('bar', []);
114114

115115
(new MergeExtensionConfigurationPass())->process($container);
116116
}
117+
118+
public function testThrowingExtensionsGetMergedBag()
119+
{
120+
$container = new ContainerBuilder();
121+
$container->registerExtension(new ThrowingExtension());
122+
$container->prependExtensionConfig('throwing', array('bar' => '%env(FOO)%'));
123+
124+
try {
125+
$pass = new MergeExtensionConfigurationPass();
126+
$pass->process($container);
127+
$this->fail('An exception should have been thrown.');
128+
} catch (\Exception $e) {
129+
}
130+
131+
$this->assertSame(array('FOO'), array_keys($container->getParameterBag()->getEnvPlaceholders()));
132+
}
117133
}
118134

119135
class FooConfiguration implements ConfigurationInterface
@@ -163,3 +179,21 @@ public function load(array $configs, ContainerBuilder $container)
163179
$container->resolveEnvPlaceholders('%env(int:FOO)%', true);
164180
}
165181
}
182+
183+
class ThrowingExtension extends Extension
184+
{
185+
public function getAlias()
186+
{
187+
return 'throwing';
188+
}
189+
190+
public function getConfiguration(array $config, ContainerBuilder $container)
191+
{
192+
return new FooConfiguration();
193+
}
194+
195+
public function load(array $configs, ContainerBuilder $container)
196+
{
197+
throw new \Exception();
198+
}
199+
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ public function finishView(FormView $view, FormInterface $form, array $options)
9292
*/
9393
public function configureOptions(OptionsResolver $resolver)
9494
{
95-
$dataClass = function (Options $options) {
96-
return $options['multiple'] ? null : 'Symfony\Component\HttpFoundation\File\File';
97-
};
95+
$dataClass = null;
96+
if (class_exists('Symfony\Component\HttpFoundation\File\File')) {
97+
$dataClass = function (Options $options) {
98+
return $options['multiple'] ? null : 'Symfony\Component\HttpFoundation\File\File';
99+
};
100+
}
98101

99102
$emptyData = function (Options $options) {
100103
return $options['multiple'] ? array() : null;

src/Symfony/Component/HttpFoundation/Session/Flash/AutoExpireFlashBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function get($type, array $default = array())
106106
public function all()
107107
{
108108
$return = $this->flashes['display'];
109-
$this->flashes = array('new' => array(), 'display' => array());
109+
$this->flashes['display'] = array();
110110

111111
return $return;
112112
}

src/Symfony/Component/HttpFoundation/Tests/Session/Flash/AutoExpireFlashBagTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,12 @@ public function testClear()
150150
{
151151
$this->assertEquals(array('notice' => array('A previous flash message')), $this->bag->clear());
152152
}
153+
154+
public function testDoNotRemoveTheNewFlashesWhenDisplayingTheExistingOnes()
155+
{
156+
$this->bag->add('success', 'Something');
157+
$this->bag->all();
158+
159+
$this->assertEquals(array('new' => array('success' => array('Something')), 'display' => array()), $this->array);
160+
}
153161
}

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ protected function getAttributes($object, $format = null, array $context)
129129
return $allowedAttributes;
130130
}
131131

132+
if (isset($context['attributes'])) {
133+
return $this->extractAttributes($object, $format, $context);
134+
}
135+
132136
if (isset($this->attributesCache[$class])) {
133137
return $this->attributesCache[$class];
134138
}

src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,37 @@ public function testAttributesContextDenormalizeConstructor()
723723
'inner' => array('foo' => 'foo', 'bar' => 'bar'),
724724
), DummyWithConstructorObjectAndDefaultValue::class, null, $context));
725725
}
726+
727+
public function testNormalizeSameObjectWithDifferentAttributes()
728+
{
729+
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
730+
$this->normalizer = new ObjectNormalizer($classMetadataFactory);
731+
$serializer = new Serializer(array($this->normalizer));
732+
$this->normalizer->setSerializer($serializer);
733+
734+
$dummy = new ObjectOuter();
735+
$dummy->foo = new ObjectInner();
736+
$dummy->foo->foo = 'foo.foo';
737+
$dummy->foo->bar = 'foo.bar';
738+
739+
$dummy->bar = new ObjectInner();
740+
$dummy->bar->foo = 'bar.foo';
741+
$dummy->bar->bar = 'bar.bar';
742+
743+
$this->assertEquals(array(
744+
'foo' => array(
745+
'bar' => 'foo.bar',
746+
),
747+
'bar' => array(
748+
'foo' => 'bar.foo',
749+
),
750+
), $this->normalizer->normalize($dummy, 'json', array(
751+
'attributes' => array(
752+
'foo' => array('bar'),
753+
'bar' => array('foo'),
754+
),
755+
)));
756+
}
726757
}
727758

728759
class ObjectDummy

src/Symfony/Component/Yaml/Inline.php

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
478478
$output = array();
479479
$len = strlen($mapping);
480480
++$i;
481+
$allowOverwrite = false;
481482

482483
// {foo: bar, bar:foo, ...}
483484
while ($i < $len) {
@@ -518,6 +519,10 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
518519
@trigger_error(self::getDeprecationMessage('Using a colon after an unquoted mapping key that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}") is deprecated since version 3.2 and will throw a ParseException in 4.0.'), E_USER_DEPRECATED);
519520
}
520521

522+
if ('<<' === $key) {
523+
$allowOverwrite = true;
524+
}
525+
521526
while ($i < $len) {
522527
if (':' === $mapping[$i] || ' ' === $mapping[$i]) {
523528
++$i;
@@ -526,17 +531,26 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
526531
}
527532

528533
$tag = self::parseTag($mapping, $i, $flags);
529-
$duplicate = false;
530534
switch ($mapping[$i]) {
531535
case '[':
532536
// nested sequence
533537
$value = self::parseSequence($mapping, $flags, $i, $references);
534538
// Spec: Keys MUST be unique; first one wins.
535539
// Parser cannot abort this mapping earlier, since lines
536540
// are processed sequentially.
537-
if (isset($output[$key])) {
541+
// But overwriting is allowed when a merge node is used in current block.
542+
if ('<<' === $key) {
543+
foreach ($value as $parsedValue) {
544+
$output += $parsedValue;
545+
}
546+
} elseif ($allowOverwrite || !isset($output[$key])) {
547+
if (null !== $tag) {
548+
$output[$key] = new TaggedValue($tag, $value);
549+
} else {
550+
$output[$key] = $value;
551+
}
552+
} elseif (isset($output[$key])) {
538553
@trigger_error(self::getDeprecationMessage(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key)), E_USER_DEPRECATED);
539-
$duplicate = true;
540554
}
541555
break;
542556
case '{':
@@ -545,30 +559,38 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
545559
// Spec: Keys MUST be unique; first one wins.
546560
// Parser cannot abort this mapping earlier, since lines
547561
// are processed sequentially.
548-
if (isset($output[$key])) {
562+
// But overwriting is allowed when a merge node is used in current block.
563+
if ('<<' === $key) {
564+
$output += $value;
565+
} elseif ($allowOverwrite || !isset($output[$key])) {
566+
if (null !== $tag) {
567+
$output[$key] = new TaggedValue($tag, $value);
568+
} else {
569+
$output[$key] = $value;
570+
}
571+
} elseif (isset($output[$key])) {
549572
@trigger_error(self::getDeprecationMessage(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key)), E_USER_DEPRECATED);
550-
$duplicate = true;
551573
}
552574
break;
553575
default:
554576
$value = self::parseScalar($mapping, $flags, array(',', '}'), $i, null === $tag, $references);
555577
// Spec: Keys MUST be unique; first one wins.
556578
// Parser cannot abort this mapping earlier, since lines
557579
// are processed sequentially.
558-
if (isset($output[$key])) {
580+
// But overwriting is allowed when a merge node is used in current block.
581+
if ('<<' === $key) {
582+
$output += $value;
583+
} elseif ($allowOverwrite || !isset($output[$key])) {
584+
if (null !== $tag) {
585+
$output[$key] = new TaggedValue($tag, $value);
586+
} else {
587+
$output[$key] = $value;
588+
}
589+
} elseif (isset($output[$key])) {
559590
@trigger_error(self::getDeprecationMessage(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key)), E_USER_DEPRECATED);
560-
$duplicate = true;
561591
}
562592
--$i;
563593
}
564-
565-
if (!$duplicate) {
566-
if (null !== $tag) {
567-
$output[$key] = new TaggedValue($tag, $value);
568-
} else {
569-
$output[$key] = $value;
570-
}
571-
}
572594
++$i;
573595

574596
continue 2;

src/Symfony/Component/Yaml/Tests/Fixtures/sfMergeKey.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ yaml: |
2121
c:
2222
foo: bar
2323
bar: foo
24+
bar_inline: {a: before, d: other, <<: *foo, b: new, x: Oren, c: { foo: bar, bar: foo}}
2425
foo2: &foo2
2526
a: Ballmer
2627
ding: &dong [ fi, fei, fo, fam]
@@ -42,14 +43,19 @@ yaml: |
4243
p: 12345
4344
z:
4445
<<: *nestedref
46+
head_inline: &head_inline { <<: [ *foo , *dong , *foo2 ] }
47+
recursive_inline: { <<: *head_inline, c: { <<: *foo2 } }
4548
php: |
4649
array(
4750
'foo' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull'),
4851
'bar' => array('a' => 'before', 'd' => 'other', 'e' => null, 'b' => 'new', 'c' => array('foo' => 'bar', 'bar' => 'foo'), 'x' => 'Oren'),
52+
'bar_inline' => array('a' => 'before', 'd' => 'other', 'b' => 'new', 'c' => array('foo' => 'bar', 'bar' => 'foo'), 'e' => 'notnull', 'x' => 'Oren'),
4953
'foo2' => array('a' => 'Ballmer'),
5054
'ding' => array('fi', 'fei', 'fo', 'fam'),
5155
'check' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam', 'isit' => 'tested'),
5256
'head' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam'),
5357
'taz' => array('a' => 'Steve', 'w' => array('p' => 1234)),
54-
'nested' => array('a' => 'Steve', 'w' => array('p' => 12345), 'd' => 'Doug', 'z' => array('p' => 12345))
58+
'nested' => array('a' => 'Steve', 'w' => array('p' => 12345), 'd' => 'Doug', 'z' => array('p' => 12345)),
59+
'head_inline' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam'),
60+
'recursive_inline' => array('a' => 'Steve', 'b' => 'Clark', 'c' => array('a' => 'Ballmer'), 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam'),
5561
)

0 commit comments

Comments
 (0)
0