8000 Merge branch '2.3' into 2.5 · symfony/symfony@99a627a · GitHub
[go: up one dir, main page]

Skip to content

Commit 99a627a

Browse files
committed
Merge branch '2.3' into 2.5
* 2.3: fixed tests [EventDispatcher] Add missing checks to RegisterListenersPass Inline private 'is quoting required' methods in Escaper [Debug] fix loading order for legacy classes Add comment as requested Remove duplicate 'require' [Yaml] Improve YAML boolean escaping Conflicts: src/Symfony/Component/Debug/Exception/FatalErrorException.php src/Symfony/Component/HttpKernel/DependencyInjection/RegisterListenersPass.php
2 parents b53ceb1 + b08115b commit 99a627a

File tree

7 files changed

+131
-45
lines changed

7 files changed

+131
-45
lines changed

src/Symfony/Component/Debug/Exception/FatalErrorException.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Debug\Exception;
13-
14-
use Symfony\Component\HttpKernel\Exception\FatalErrorException as LegacyFatalErrorException;
12+
namespace Symfony\Component\HttpKernel\Exception;
1513

1614
/**
1715
* Fatal Error Exception.
1816
*
1917
* @author Fabien Potencier <fabien@symfony.com>
2018
* @author Konstanton Myakshin <koc-dp@yandex.ru>
2119
* @author Nicolas Grekas <p@tchwork.com>
20+
*
21+
* @deprecated Deprecated in 2.3, to be removed in 3.0. Use the same class from the Debug component instead.
2222
*/
23-
class FatalErrorException extends LegacyFatalErrorException
23+
class FatalErrorException extends \ErrorException
2424
{
2525
}
2626

27-
namespace Symfony\Component\HttpKernel\Exception;
27+
namespace Symfony\Component\Debug\Exception;
28+
29+
use Symfony\Component\HttpKernel\Exception\FatalErrorException as LegacyFatalErrorException;
2830

2931
/**
3032
* Fatal Error Exception.
3133
*
3234
* @author Konstanton Myakshin <koc-dp@yandex.ru>
33-
*
34-
* @deprecated Deprecated in 2.3, to be removed in 3.0. Use the same class from the Debug component instead.
3535
*/
36-
class FatalErrorException extends \ErrorException
36+
class FatalErrorException extends LegacyFatalErrorException
3737
{
3838
public function __construct($message, $code, $severity, $filename, $lineno, $traceOffset = null, $traceArgs = true)
3939
{

src/Symfony/Component/Debug/Exception/FlattenException.php

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,46 @@
99
* file that was distributed with this source code.
1010
*/
1111

12+
namespace Symfony\Component\HttpKernel\Exception;
13+
14+
use Symfony\Component\Debug\Exception\FlattenException as DebugFlattenException;
15+
16+
/**
17+
* FlattenException wraps a PHP Exception to be able to serialize it.
18+
*
19+
* Basically, this class removes all objects from the trace.
20+
*
21+
* @author Fabien Potencier <fabien@symfony.com>
22+
*
23+
* @deprecated Deprecated in 2.3, to be removed in 3.0. Use the same class from the Debug component instead.
24+
*/
25+
class FlattenException
26+
{
27+
private $handler;
28+
29+
public static function __callStatic($method, $args)
30+
{
31+
if (!method_exists('Symfony\Component\Debug\Exception\FlattenException', $method)) {
32+
throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_called_class(), $method));
33+
}
34+
35+
return call_user_func_array(array('Symfony\Component\Debug\Exception\FlattenException', $method), $args);
36+
}
37+
38+
public function __call($method, $args)
39+
{
40+
if (!isset($this->handler)) {
41+
$this->handler = new DebugFlattenException();
42+
}
43+
44+
if (!method_exists($this->handler, $method)) {
45+
throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_class($this), $method));
46+
}
47+
48+
return call_user_func_array(array($this->handler, $method), $args);
49+
}
50+
}
51+
1252
namespace Symfony\Component\Debug\Exception;
1353

1454
use Symfony\Component\HttpKernel\Exception\FlattenException as LegacyFlattenException;
@@ -250,35 +290,3 @@ private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value)
250290
return $array['__PHP_Incomplete_Class_Name'];
251291
}
252292
}
253-
254-
namespace Symfony\Component\HttpKernel\Exception;
255-
256-
use Symfony\Component\Debug\Exception\FlattenException as DebugFlattenException;
257-
258-
/**
259-
* FlattenException wraps a PHP Exception to be able to serialize it.
260-
*
261-
* Basically, this class removes all objects from the trace.
262-
*
263-
* @author Fabien Potencier <fabien@symfony.com>
264-
*
265-
* @deprecated Deprecated in 2.3, to be removed in 3.0. Use the same class from the Debug component instead.
266-
*/
267-
class FlattenException
268-
{
269-
private $handler;
270-
271-
public static function __callStatic($method, $args)
272-
{
273-
return forward_static_call_array(array('Symfony\Component\Debug\Exception\FlattenException', $method), $args);
274-
}
275-
276-
public function __call($method, $args)
277-
{
278-
if (!isset($this->handler)) {
279-
$this->handler = new DebugFlattenException();
280-
}
281-
282-
return call_user_func_array(array($this->handler, $method), $args);
283-
}
284-
}

src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ public function process(ContainerBuilder $container)
9191
throw new \InvalidArgumentException(sprintf('The service "%s" must be public as event subscribers are lazy-loaded.', $id));
9292
}
9393

94+
if ($def->isAbstract()) {
95+
throw new \InvalidArgumentException(sprintf('The service "%s" must not be abstract as event subscribers are lazy-loaded.', $id));
96+
}
97+
9498
// We must assume that the class value has been correctly filled, even if the service is created by a factory
95-
$class = $def->getClass();
99+
$class = $container->getParameterBag()->resolveValue($def->getClass());
96100

97101
$refClass = new \ReflectionClass($class);
98102
$interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';

src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,58 @@ public function testAbstractEventListener()
138138
$registerListenersPass = new RegisterListenersPass();
139139
$registerListenersPass->process($container);
140140
}
141+
142+
/**
143+
* @expectedException \InvalidArgumentException
144+
* @expectedExceptionMessage The service "foo" must not be abstract as event subscribers are lazy-loaded.
145+
*/
146+
public function testAbstractEventSubscriber()
147+
{
148+
$container = new ContainerBuilder();
149+
$container->register('foo', 'stdClass')->setAbstract(true)->addTag('kernel.event_subscriber', array());
150+
$container->register('event_dispatcher', 'stdClass');
151+
152+
$registerListenersPass = new RegisterListenersPass();
153+
$registerListenersPass->process($container);
154+
}
155+
156+
public function testEventSubscriberResolvableClassName()
157+
{
158+
$container = new ContainerBuilder();
159+
160+
$container->setParameter('subscriber.class', 'Symfony\Component\EventDispatcher\Tests\DependencyInjection\SubscriberService');
161+
$container->register('foo', '%subscriber.class%')->addTag('kernel.event_subscriber', array());
162+
$container->register('event_dispatcher', 'stdClass');
163+
164+
$registerListenersPass = new RegisterListenersPass();
165+
$registerListenersPass->process($container);
166+
167+
$definition = $container->getDefinition('event_dispatcher');
168+
$expected_calls = array(
169+
1C6A array(
170+
'addSubscriberService',
171+
array(
172+
'foo',
173+
'Symfony\Component\EventDispatcher\Tests\DependencyInjection\SubscriberService',
174+
),
175+
),
176+
);
177+
$this->assertSame($expected_calls, $definition->getMethodCalls());
178+
}
179+
180+
/**
181+
* @expectedException \InvalidArgumentException
182+
* @expectedExceptionMessage You have requested a non-existent parameter "subscriber.class"
183+
*/
184+
public function testEventSubscriberUnresolvableClassName()
185+
{
186+
$container = new ContainerBuilder();
187+
$container->register('foo', '%subscriber.class%')->addTag('kernel.event_subscriber', array());
188+
$container->register('event_dispatcher', 'stdClass');
189+
190+
$registerListenersPass = new RegisterListenersPass();
191+
$registerListenersPass->process($container);
192+
}
141193
}
142194

143195
class SubscriberService implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

src/Symfony/Component/Yaml/Escaper.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,15 @@ public static function escapeWithDoubleQuotes($value)
7272
*/
7373
public static function requiresSingleQuoting($value)
7474
{
75-
return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value);
75+
// Determines if the PHP value contains any single characters that would
76+
// cause it to require single quoting in YAML.
77+
if (preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value)) {
78+
return true;
79+
}
80+
81+
// Determines if a PHP value is entirely composed of a value that would
82+
// require single quoting in YAML.
83+
return in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'));
7684
}
7785

7886
/**

src/Symfony/Component/Yaml/Inline.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,10 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
135135
case Escaper::requiresDoubleQuoting($value):
136136
return Escaper::escapeWithDoubleQuotes($value);
137137
case Escaper::requiresSingleQuoting($value):
138+
case preg_match(self::getTimestampRegex(), $value):
138139
return Escaper::escapeWithSingleQuotes($value);
139140
case '' == $value:
140141
return "''";
141-
case preg_match(self::getTimestampRegex(), $value):
142-
case in_array(strtolower($value), array('null', '~', 'true', 'false')):
143-
return "'$value'";
144142
default:
145143
return $value;
146144
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ protected function getTestsForParse()
190190
"'#cfcfcf'" => '#cfcfcf',
191191
'::form_base.html.twig' => '::form_base.html.twig',
192192

193+
// Pre-YAML-1.2 booleans
194+
"'y'" => 'y',
195+
"'n'" => 'n',
196+
"'yes'" => 'yes',
197+
"'no'" => 'no',
198+
"'on'" => 'on',
199+
"'off'" => 'off',
200+
193201
'2007-10-30' => mktime(0, 0, 0, 10, 30, 2007),
194202
'2007-10-30T02:59:43Z' => gmmktime(2, 59, 43, 10, 30, 2007),
195203
'2007-10-30 02:59:43 Z' => gmmktime(2, 59, 43, 10, 30, 2007),
@@ -256,6 +264,14 @@ protected function getTestsForDump()
256264
"'-dash'" => '-dash',
257265
"'-'" => '-',
258266

267+
// Pre-YAML-1.2 booleans
268+
"'y'" => 'y',
269+
"'n'" => 'n',
270+
"'yes'" => 'yes',
271+
"'no'" => 'no',
272+
"'on'" => 'on',
273+
"'off'" => 'off',
274+
259275
// sequences
260276
'[foo, bar, false, null, 12]' => array('foo', 'bar', false, null, 12),
261277
'[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'),

0 commit comments

Comments
 (0)
0