Skip to content

Commit c674bd7

Browse files
Merge branch '3.3' into 3.4
* 3.3: [FrameworkBundle] Fix bad interface hint in AbstractController [DI] Improve some deprecation messages [Cache] Fix race condition in TagAwareAdapter [Yaml] parse references on merge keys treat trailing backslashes in multi-line strings
2 parents 71ed432 + 01644c5 commit c674bd7

File tree

8 files changed

+87
-39
lines changed

8 files changed

+87
-39
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,18 @@ protected function renderView($view, array $parameters = array())
281281
protected function render($view, array $parameters = array(), Response $response = null)
282282
{
283283
if ($this->container->has('templating')) {
284-
return $this->container->get('templating')->renderResponse($view, $parameters, $response);
285-
}
286-
287-
if (!$this->container->has('twig')) {
284+
$content = $this->container->get('templating')->render($view, $parameters);
285+
} elseif ($this->container->has('twig')) {
286+
$content = $this->container->get('twig')->render($view, $parameters);
287+
} else {
288288
throw new \LogicException('You can not use the "render" method if the Templating Component or the Twig Bundle are not available.');
289289
}
290290

291291
if (null === $response) {
292292
$response = new Response();
293293
}
294294

295-
$response->setContent($this->container->get('twig')->render($view, $parameters));
295+
$response->setContent($content);
296296

297297
return $response;
298298
}

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public function testRenderViewTemplating()
451451
public function testRenderTemplating()
452452
{
453453
$templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')->getMock();
454-
$templating->expects($this->once())->method('renderResponse')->willReturn(new Response('bar'));
454+
$templating->expects($this->once())->method('render')->willReturn('bar');
455455

456456
$container = new Container();
457457
$container->set('templating', $templating);

src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,12 @@ public function commit()
254254

255255
$f = $this->getTagsByKey;
256256
$tagsByKey = $f($items);
257-
$deletedTags = $this->deferred = array();
257+
$this->deferred = array();
258258
$tagVersions = $this->getTagVersions($tagsByKey);
259259
$f = $this->createCacheItem;
260260

261261
foreach ($tagsByKey as $key => $tags) {
262-
if ($tags) {
263-
$this->pool->saveDeferred($f(static::TAGS_PREFIX.$key, array_intersect_key($tagVersions, $tags), $items[$key]));
264-
} else {
265-
$deletedTags[] = static::TAGS_PREFIX.$key;
266-
}
267-
}
268-
if ($deletedTags) {
269-
$this->pool->deleteItems($deletedTags);
262+
$this->pool->saveDeferred($f(static::TAGS_PREFIX.$key, array_intersect_key($tagVersions, $tags), $items[$key]));
270263
}
271264
}
272265

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,16 @@ public function set($id, $service)
192192

193193
if (isset($this->privates[$id])) {
194194
if (null === $service) {
195-
@trigger_error(sprintf('Unsetting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
195+
@trigger_error(sprintf('The "%s" service is private, unsetting it is deprecated since Symfony 3.2 and will fail in 4.0.', $id), E_USER_DEPRECATED);
196196
unset($this->privates[$id]);
197197
} else {
198-
@trigger_error(sprintf('Setting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
198+
@trigger_error(sprintf('The "%s" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.', $id), E_USER_DEPRECATED);
199199
}
200200
} elseif ($wasSet && (isset($this->fileMap[$id]) || isset($this->methodMap[$id]))) {
201201
if (null === $service) {
202-
@trigger_error(sprintf('Unsetting the "%s" service after it\'s been initialized is deprecated since Symfony 3.3 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
202+
@trigger_error(sprintf('The "%s" service is already initialized, unsetting it is deprecated since Symfony 3.3 and will fail in 4.0.', $id), E_USER_DEPRECATED);
203203
} else {
204-
@trigger_error(sprintf('Setting the "%s" service after it\'s been initialized is deprecated since Symfony 3.3 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
204+
@trigger_error(sprintf('The "%s" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.', $id), E_USER_DEPRECATED);
205205
}
206206
}
207207
}
@@ -217,7 +217,7 @@ public function has($id)
217217
{
218218
for ($i = 2;;) {
219219
if (isset($this->privates[$id])) {
220-
@trigger_error(sprintf('Checking for the existence of the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
220+
@trigger_error(sprintf('The "%s" service is private, checking for its existence is deprecated since Symfony 3.2 and will fail in 4.0.', $id), E_USER_DEPRECATED);
221221
}
222222
if (isset($this->aliases[$id])) {
223223
$id = $this->aliases[$id];
@@ -275,7 +275,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
275275
// calling $this->normalizeId($id) unless necessary.
276276
for ($i = 2;;) {
277277
if (isset($this->privates[$id])) {
278-
@trigger_error(sprintf('Requesting the "%s" private service is deprecated since Symfony 3.2 and won\'t be supported anymore in Symfony 4.0.', $id), E_USER_DEPRECATED);
278+
@trigger_error(sprintf('The "%s" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.', $id), E_USER_DEPRECATED);
279279
}
280280
if (isset($this->aliases[$id])) {
281281
$id = $this->aliases[$id];

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function testSetReplacesAlias()
196196

197197
/**
198198
* @group legacy
199-
* @expectedDeprecation Unsetting the "bar" service after it's been initialized is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0.
199+
* @expectedDeprecation The "bar" service is already initialized, unsetting it is deprecated since Symfony 3.3 and will fail in 4.0.
200200
*/
201201
public function testSetWithNullOnInitializedPredefinedService()
202202
{
@@ -473,7 +473,7 @@ public function testThatCloningIsNotSupported()
473473

474474
/**
475475
* @group legacy
476-
* @expectedDeprecation Unsetting the "internal" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0.
476+
* @expectedDeprecation The "internal" service is private, unsetting it is deprecated since Symfony 3.2 and will fail in 4.0.
477477
*/
478478
public function testUnsetInternalPrivateServiceIsDeprecated()
479479
{
@@ -483,7 +483,7 @@ public function testUnsetInternalPrivateServiceIsDeprecated()
483483

484484
/**
485485
* @group legacy
486-
* @expectedDeprecation Setting the "internal" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0.
486+
* @expectedDeprecation The "internal" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0.
487487
*/
488488
public function testChangeInternalPrivateServiceIsDeprecated()
489489
{
@@ -494,7 +494,7 @@ public function testChangeInternalPrivateServiceIsDeprecated()
494494

495495
/**
496496
* @group legacy
497-
* @expectedDeprecation Checking for the existence of the "internal" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0.
497+
* @expectedDeprecation The "internal" service is private, checking for its existence is deprecated since Symfony 3.2 and will fail in 4.0.
498498
*/
499499
public function testCheckExistenceOfAnInternalPrivateServiceIsDeprecated()
500500
{
@@ -505,7 +505,7 @@ public function testCheckExistenceOfAnInternalPrivateServiceIsDeprecated()
505505

506506
/**
507507
* @group legacy
508-
* @expectedDeprecation Requesting the "internal" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0.
508+
* @expectedDeprecation The "internal" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop getting services directly from the container and use dependency injection instead.
509509
*/
510510
public function testRequestAnInternalSharedPrivateServiceIsDeprecated()
511511
{
@@ -516,7 +516,7 @@ public function testRequestAnInternalSharedPrivateServiceIsDeprecated()
516516

517517
/**
518518
* @group legacy
519-
* @expectedDeprecation Setting the "bar" service after it's been initialized is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0.
519+
* @expectedDeprecation The "bar" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.
520520
*/
521521
public function testReplacingAPreDefinedServiceIsDeprecated()
522522
{

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public function testFrozenContainerWithoutAliases()
287287

288288
/**
289289
* @group legacy
290-
* @expectedDeprecation Setting the "bar" service after it's been initialized is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0.
290+
* @expectedDeprecation The "bar" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.
291291
*/
292292
public function testOverrideServiceWhenUsingADumpedContainer()
293293
{
@@ -304,7 +304,7 @@ public function testOverrideServiceWhenUsingADumpedContainer()
304304

305305
/**
306306
* @group legacy
307-
* @expectedDeprecation Setting the "bar" service after it's been initialized is deprecated since Symfony 3.3 and won't be supported anymore in Symfony 4.0.
307+
* @expectedDeprecation The "bar" service is already initialized, replacing it is deprecated since Symfony 3.3 and will fail in 4.0.
308308
*/
309309
public function testOverrideServiceWhenUsingADumpedContainerAndServiceIsUsedFromAnotherOne()
310310
{

src/Symfony/Component/Yaml/Parser.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private function doParse($value, $flags)
281281
$key = (string) $key;
282282
}
283283

284-
if ('<<' === $key) {
284+
if ('<<' === $key && (!isset($values['value']) || !self::preg_match('#^&(?P<ref>[^ ]+)#u', $values['value'], $refMatches))) {
285285
$mergeNode = true;
286286
$allowOverwrite = true;
287287
if (isset($values['value'][0]) && '*' === $values['value'][0]) {
@@ -338,15 +338,15 @@ private function doParse($value, $flags)
338338
$data += $parsed; // array union
339339
}
340340
}
341-
} elseif (isset($values['value']) && self::preg_match('#^&(?P<ref>[^ ]++) *+(?P<value>.*)#u', $values['value'], $matches)) {
341+
} elseif ('<<' !== $key && isset($values['value']) && self::preg_match('#^&(?P<ref>[^ ]++) *+(?P<value>.*)#u', $values['value'], $matches)) {
342342
$isRef = $matches['ref'];
343343
$values['value'] = $matches['value'];
344344
}
345345

346346
$subTag = null;
347347
if ($mergeNode) {
348348
// Merge keys
349-
} elseif (!isset($values['value']) || '' === $values['value'] || 0 === strpos($values['value'], '#') || (null !== $subTag = $this->getLineTag($values['value'], $flags))) {
349+
} elseif (!isset($values['value']) || '' === $values['value'] || 0 === strpos($values['value'], '#') || (null !== $subTag = $this->getLineTag($values['value'], $flags)) || '<<' === $key) {
350350
// hash
351351
// if next line is less indented or equal, then it means that the current value is null
352352
if (!$this->isNextLineIndented() && !$this->isNextLineUnIndentedCollection()) {
@@ -365,9 +365,12 @@ private function doParse($value, $flags)
365365
// remember the parsed line number here in case we need it to provide some contexts in error messages below
366366
$realCurrentLineNbKey = $this->getRealCurrentLineNb();
367367
$value = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(), $flags);
368-
// Spec: Keys MUST be unique; first one wins.
369-
// But overwriting is allowed when a merge node is used in current block.
370-
if ($allowOverwrite || !isset($data[$key])) {
368+
if ('<<' === $key) {
369+
$this->refs[$refMatches['ref']] = $value;
370+
$data += $value;
371+
} elseif ($allowOverwrite || !isset($data[$key])) {
372+
// Spec: Keys MUST be unique; first one wins.
373+
// But overwriting is allowed when a merge node is used in current block.
371374
if (null !== $subTag) {
372375
$data[$key] = new TaggedValue($subTag, $value);
373376
} else {
@@ -418,6 +421,7 @@ private function doParse($value, $flags)
418421
if (0 === $this->currentLineNb) {
419422
$parseError = false;
420423
$previousLineWasNewline = false;
424+
$previousLineWasTerminatedWithBackslash = false;
421425
$value = '';
422426

423427
foreach ($this->lines as $line) {
@@ -435,13 +439,25 @@ private function doParse($value, $flags)
435439

436440
if ('' === trim($parsedLine)) {
437441
$value .= "\n";
438-
$previousLineWasNewline = true;
439-
} elseif ($previousLineWasNewline) {
442+
} elseif (!$previousLineWasNewline && !$previousLineWasTerminatedWithBackslash) {
443+
$value .= ' ';
444+
}
445+
446+
if ('' !== trim($parsedLine) && '\\' === substr($parsedLine, -1)) {
447+
$value .= ltrim(substr($parsedLine, 0, -1));
448+
} elseif ('' !== trim($parsedLine)) {
440449
$value .= trim($parsedLine);
450+
}
451+
452+
if ('' === trim($parsedLine)) {
453+
$previousLineWasNewline = true;
454+
$previousLineWasTerminatedWithBackslash = false;
455+
} elseif ('\\' === substr($parsedLine, -1)) {
441456
$previousLineWasNewline = false;
457+
$previousLineWasTerminatedWithBackslash = true;
442458
} else {
443-
$value .= ' '.trim($parsedLine);
444459
$previousLineWasNewline = false;
460+
$previousLineWasTerminatedWithBackslash = false;
445461
}
446462
} catch (ParseException $e) {
447463
$parseError = true;
@@ -450,7 +466,7 @@ private function doParse($value, $flags)
450466
}
451467

452468
if (!$parseError) {
453-
return trim($value);
469+
return Inline::parse(trim($value));
454470
}
455471
}
456472

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,17 @@ public function testParseMultiLineQuotedString()
15501550
$this->assertSame(array('foo' => 'bar baz foobar foo', 'bar' => 'baz'), $this->parser->parse($yaml));
15511551
}
15521552

1553+
public function testMultiLineQuotedStringWithTrailingBackslash()
1554+
{
1555+
$yaml = <<<YAML
1556+
foobar:
1557+
"foo\
1558+
bar"
1559+
YAML;
1560+
1561+
$this->assertSame(array('foobar' => 'foobar'), $this->parser->parse($yaml));
1562+
}
1563+
15531564
public function testParseMultiLineUnquotedString()
15541565
{
15551566
$yaml = <<<EOT
@@ -1979,6 +1990,34 @@ public function testParsingNotReadableFilesThrowsException()
19791990

19801991
$this->parser->parseFile($file);
19811992
}
1993+
1994+
public function testParseReferencesOnMergeKeys()
1995+
{
1996+
$yaml = <<<YAML
1997+
mergekeyrefdef:
1998+
a: foo
1999+
<<: &quux
2000+
b: bar
2001+
c: baz
2002+
mergekeyderef:
2003+
d: quux
2004+
<<: *quux
2005+
YAML;
2006+
$expected = array(
2007+
'mergekeyrefdef' => array(
2008+
'a' => 'foo',
2009+
'b' => 'bar',
2010+
'c' => 'baz',
2011+
),
2012+
'mergekeyderef' => array(
2013+
'd' => 'quux',
2014+
'b' => 'bar',
2015+
'c' => 'baz',
2016+
),
2017+
);
2018+
2019+
$this->assertSame($expected, $this->parser->parse($yaml));
2020+
}
19822021
}
19832022

19842023
class B

0 commit comments

Comments
 (0)