Skip to content

Commit bdc7e91

Browse files
committed
Merge branch '2.0' into 2.1
* 2.0: [DependencyInjection] fixed the creation of synthetic services in ContainerBuilder [Security] PHPDoc in SecurityEvents [FrameworkBundle] fixed Client::doRequest that must call its parent method (closes symfony#6737) [Yaml] fixed ignored text when parsing an inlined mapping or sequence (closes symfony#6786) [Yaml] fixed symfony#6773 [Yaml] fixed symfony#6770 bumped Symfony version to 2.0.23-DEV Conflicts: src/Symfony/Component/DependencyInjection/ContainerBuilder.php src/Symfony/Component/HttpKernel/Kernel.php src/Symfony/Component/Yaml/Inline.php src/Symfony/Component/Yaml/Tests/InlineTest.php
2 parents fada75c + 115114b commit bdc7e91

File tree

8 files changed

+267
-19
lines changed

8 files changed

+267
-19
lines changed

src/Symfony/Bundle/FrameworkBundle/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function doRequest($request)
7878
$this->hasPerformedRequest = true;
7979
}
8080

81-
return $this->kernel->handle($request);
81+
return parent::doRequest($request);
8282
}
8383

8484
/**

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,19 +734,22 @@ public function findDefinition($id)
734734
*
735735
* @throws RuntimeException When the scope is inactive
736736
* @throws RuntimeException When the factory definition is incomplete
737+
* @throws RuntimeException When the service is a synthetic service
737738
* @throws InvalidArgumentException When configure callable is not callable
738739
*/
739740
private function createService(Definition $definition, $id)
740741
{
742+
if ($definition->isSynthetic()) {
743+
throw new RuntimeException(sprintf('You have requested a synthetic service ("%s"). The DIC does not know how to construct this service.', $id));
744+
}
745+
741746
$parameterBag = $this->getParameterBag();
742747

743748
if (null !== $definition->getFile()) {
744749
require_once $parameterBag->resolveValue($definition->getFile());
745750
}
746751

747-
$arguments = $this->resolveServices(
748-
$parameterBag->unescapeValue($parameterBag->resolveValue($definition->getArguments()))
749-
);
752+
$arguments = $this->resolveServices($parameterBag->unescapeValue($parameterBag->resolveValue($definition->getArguments())));
750753

751754
if (null !== $definition->getFactoryMethod()) {
752755
if (null !== $definition->getFactoryClass()) {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,17 @@ public function testCreateServiceConfigurator()
319319
}
320320
}
321321

322+
/**
323+
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
324+
* @expectedException \RuntimeException
325+
*/
326+
public function testCreateSyntheticService()
327+
{
328+
$builder = new ContainerBuilder();
329+
$builder->register('foo', 'FooClass')->setSynthetic(true);
330+
$builder->get('foo');
331+
}
332+
322333
/**
323334
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::resolveServices
324335
*/

src/Symfony/Component/Security/Http/SecurityEvents.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,25 @@
1313

1414
final class SecurityEvents
1515
{
16+
/**
17+
* The INTERACTIVE_LOGIN event occurs after a user is logged in
18+
* interactively for authentication based on http, cookies or X509.
19+
*
20+
* The event listener method receives a
21+
* Symfony\Component\Security\Http\Event\InteractiveLoginEvent instance.
22+
*
23+
* @var string
24+
*/
1625
const INTERACTIVE_LOGIN = 'security.interactive_login';
1726

27+
/**
28+
* The SWITCH_USER event occurs before switch to another user and
29+
* before exit from an already switched user.
30+
*
31+
* The event listener method receives a
32+
* Symfony\Component\Security\Http\Event\SwitchUserEvent instance.
33+
*
34+
* @var string
35+
*/
1836
const SWITCH_USER = 'security.switch_user';
1937
}

src/Symfony/Component/Yaml/Inline.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,23 @@ public static function parse($value, $exceptionOnInvalidType = false, $objectSup
5050
mb_internal_encoding('ASCII');
5151
}
5252

53+
$i = 0;
5354
switch ($value[0]) {
5455
case '[':
55-
$result = self::parseSequence($value);
56+
$result = self::parseSequence($value, $i);
57+
++$i;
5658
break;
5759
case '{':
58-
$result = self::parseMapping($value);
60+
$result = self::parseMapping($value, $i);
61+
++$i;
5962
break;
6063
default:
61-
$i = 0;
6264
$result = self::parseScalar($value, null, array('"', "'"), $i);
65+
}
6366

64-
// some comment can end the scalar
65-
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
66-
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)));
67-
}
67+
// some comments are allowed at the end
68+
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
69+
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)));
6870
}
6971

7072
if (isset($mbEncoding)) {
@@ -411,6 +413,11 @@ private static function evaluateScalar($scalar)
411413
$cast = intval($scalar);
412414

413415
return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
416+
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
417+
$raw = $scalar;
418+
$cast = intval($scalar);
419+
420+
return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
414421
case 'true' === strtolower($scalar):
415422
return true;
416423
case 'false' === strtolower($scalar):

src/Symfony/Component/Yaml/Parser.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
190190
}
191191
}
192192
} else {
193-
// 1-liner followed by newline
194-
if (2 == count($this->lines) && empty($this->lines[1])) {
193+
// 1-liner optionally followed by newline
194+
$lineCount = count($this->lines);
195+
if (1 === $lineCount || (2 === $lineCount && empty($this->lines[1]))) {
195196
try {
196197
$value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport);
197198
} catch (ParseException $e) {
@@ -548,10 +549,6 @@ private function cleanup($value)
548549
{
549550
$value = str_replace(array("\r\n", "\r"), "\n", $value);
550551

551-
if (!preg_match("#\n$#", $value)) {
552-
$value .= "\n";
553-
}
554-
555552
// strip YAML header
556553
$count = 0;
557554
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#su', '', $value, -1, $count);

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class InlineTest extends \PHPUnit_Framework_TestCase
1919
public function testParse()
2020
{
2121
foreach ($this->getTestsForParse() as $yaml => $value) {
22-
$this->assertEquals($value, Inline::parse($yaml), sprintf('::parse() converts an inline YAML to a PHP structure (%s)', $yaml));
22+
$this->assertSame($value, Inline::parse($yaml), sprintf('::parse() converts an inline YAML to a PHP structure (%s)', $yaml));
2323
}
2424
}
2525

@@ -92,6 +92,22 @@ public function testParseInvalidMappingKeyShouldThrowException()
9292
Inline::parse($value);
9393
}
9494

95+
/**
96+
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
97+
*/
98+
public function testParseInvalidMappingShouldThrowException()
99+
{
100+
Inline::parse('[foo] bar');
101+
}
102+
103+
/**
104+
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
105+
*/
106+
public function testParseInvalidSequenceShouldThrowException()
107+
{
108+
Inline::parse('{ foo: bar } bar');
109+
}
110+
95111
public function testParseScalarWithCorrectlyQuotedStringShouldReturnString()
96112
{
97113
$value = "'don''t do somthin'' like that'";
@@ -108,6 +124,7 @@ protected function getTestsForParse()
108124
'false' => false,
109125
'true' => true,
110126
'12' => 12,
127+
'-12' => -12,
111128
'"quoted string"' => 'quoted string',
112129
"'quoted string'" => 'quoted string',
113130
'12.30e+02' => 12.30e+02,
@@ -117,7 +134,7 @@ protected function getTestsForParse()
117134
'-.Inf' => log(0),
118135
"'686e444'" => '686e444',
119136
'686e444' => 646e444,
120-
'123456789123456789' => '123456789123456789',
137+
'123456789123456789123456789123456789' => '123456789123456789123456789123456789',
121138
'"foo\r\nbar"' => "foo\r\nbar",
122139
"'foo#bar'" => 'foo#bar',
123140
"'foo # bar'" => 'foo # bar',

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

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,201 @@ public function testEndOfTheDocumentMarker()
105105
$this->assertEquals('foo', $this->parser->parse($yaml));
106106
}
107107

108+
public function getBlockChompingTests()
109+
{
110+
$tests = array();
111+
112+
$yaml = <<<'EOF'
113+
foo: |-
114+
one
115+
two
116+
117+
bar: |-
118+
one
119+
two
120+
121+
EOF;
122+
$expected = array(
123+
'foo' => "one\ntwo",
124+
'bar' => "one\ntwo",
125+
);
126+
$tests['Literal block chomping strip with trailing newline'] = array($expected, $yaml);
127+
128+
$yaml = <<<'EOF'
129+
foo: |-
130+
one
131+
two
132+
bar: |-
133+
one
134+
two
135+
EOF;
136+
$expected = array(
137+
'foo' => "one\ntwo",
138+
'bar' => "one\ntwo",
139+
);
140+
$tests['Literal block chomping strip without trailing newline'] = array($expected, $yaml);
141+
142+
$yaml = <<<'EOF'
143+
foo: |
144+
one
145+
two
146+
147+
bar: |
148+
one
149+
two
150+
151+
EOF;
152+
$expected = array(
153+
'foo' => "one\ntwo\n",
154+
'bar' => "one\ntwo\n",
155+
);
156+
$tests['Literal block chomping clip with trailing newline'] = array($expected, $yaml);
157+
158+
$yaml = <<<'EOF'
159+
foo: |
160+
one
161+
two
162+
bar: |
163+
one
164+
two
165+
EOF;
166+
$expected = array(
167+
'foo' => "one\ntwo\n",
168+
'bar' => "one\ntwo\n",
169+
);
170+
$tests['Literal block chomping clip without trailing newline'] = array($expected, $yaml);
171+
172+
$yaml = <<<'EOF'
173+
foo: |+
174+
one
175+
two
176+
177+
bar: |+
178+
one
179+
two
180+
181+
EOF;
182+
$expected = array(
183+
'foo' => "one\ntwo\n\n",
184+
'bar' => "one\ntwo\n\n",
185+
);
186+
$tests['Literal block chomping keep with trailing newline'] = array($expected, $yaml);
187+
188+
$yaml = <<<'EOF'
189+
foo: |+
190+
one
191+
two
192+
bar: |+
193+
one
194+
two
195+
EOF;
196+
$expected = array(
197+
'foo' => "one\ntwo\n",
198+
'bar' => "one\ntwo\n",
199+
);
200+
$tests['Literal block chomping keep without trailing newline'] = array($expected, $yaml);
201+
202+
$yaml = <<<'EOF'
203+
foo: >-
204+
one
205+
two
206+
207+
bar: >-
208+
one
209+
two
210+
211+
EOF;
212+
$expected = array(
213+
'foo' => "one two",
214+
'bar' => "one two",
215+
);
216+
$tests['Folded block chomping strip with trailing newline'] = array($expected, $yaml);
217+
218+
$yaml = <<<'EOF'
219+
foo: >-
220+
one
221+
two
222+
bar: >-
223+
one
224+
two
225+
EOF;
226+
$expected = array(
227+
'foo' => "one two",
228+
'bar' => "one two",
229+
);
230+
$tests['Folded block chomping strip without trailing newline'] = array($expected, $yaml);
231+
232+
$yaml = <<<'EOF'
233+
foo: >
234+
one
235+
two
236+
237+
bar: >
238+
one
239+
two
240+
241+
EOF;
242+
$expected = array(
243+
'foo' => "one two\n",
244+
'bar' => "one two\n",
245+
);
246+
$tests['Folded block chomping clip with trailing newline'] = array($expected, $yaml);
247+
248+
$yaml = <<<'EOF'
249+
foo: >
250+
one
251+
two
252+
bar: >
253+
one
254+
two
255+
EOF;
256+
$expected = array(
257+
'foo' => "one two\n",
258+
'bar' => "one two\n",
259+
);
260+
$tests['Folded block chomping clip without trailing newline'] = array($expected, $yaml);
261+
262+
$yaml = <<<'EOF'
263+
foo: >+
264+
one
265+
two
266+
267+
bar: >+
268+
one
269+
two
270+
271+
EOF;
272+
$expected = array(
273+
'foo' => "one two\n\n",
274+
'bar' => "one two\n\n",
275+
);
276+
$tests['Folded block chomping keep with trailing newline'] = array($expected, $yaml);
277+
278+
$yaml = <<<'EOF'
279+
foo: >+
280+
one
281+
two
282+
bar: >+
283+
one
284+
two
285+
EOF;
286+
$expected = array(
287+
'foo' => "one two\n",
288+
'bar' => "one two\n",
289+
);
290+
$tests['Folded block chomping keep without trailing newline'] = array($expected, $yaml);
291+
292+
return $tests;
293+
}
294+
295+
/**
296+
* @dataProvider getBlockChompingTests
297+
*/
298+
public function testBlockChomping($expected, $yaml)
299+
{
300+
$this->assertSame($expected, $this->parser->parse($yaml));
301+
}
302+
108303
public function testObjectSupportEnabled()
109304
{
110305
$input = <<<EOF

0 commit comments

Comments
 (0)