diff --git a/src/Symfony/Component/Debug/Exception/FatalErrorException.php b/src/Symfony/Component/Debug/Exception/FatalErrorException.php index a58f855cdb..d142051ba9 100644 --- a/src/Symfony/Component/Debug/Exception/FatalErrorException.php +++ b/src/Symfony/Component/Debug/Exception/FatalErrorException.php @@ -9,9 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Debug\Exception; - -use Symfony\Component\HttpKernel\Exception\FatalErrorException as LegacyFatalErrorException; +namespace Symfony\Component\HttpKernel\Exception; /** * Fatal Error Exception. @@ -19,21 +17,23 @@ use Symfony\Component\HttpKernel\Exception\FatalErrorException as LegacyFatalErr * @author Fabien Potencier * @author Konstanton Myakshin * @author Nicolas Grekas + * + * @deprecated Deprecated in 2.3, to be removed in 3.0. Use the same class from the Debug component instead. */ -class FatalErrorException extends LegacyFatalErrorException +class FatalErrorException extends \ErrorException { } -namespace Symfony\Component\HttpKernel\Exception; +namespace Symfony\Component\Debug\Exception; + +use Symfony\Component\HttpKernel\Exception\FatalErrorException as LegacyFatalErrorException; /** * Fatal Error Exception. * * @author Konstanton Myakshin - * - * @deprecated Deprecated in 2.3, to be removed in 3.0. Use the same class from the Debug component instead. */ -class FatalErrorException extends \ErrorException +class FatalErrorException extends LegacyFatalErrorException { public function __construct($message, $code, $severity, $filename, $lineno, $traceOffset = null, $traceArgs = true) { diff --git a/src/Symfony/Component/Debug/Exception/FlattenException.php b/src/Symfony/Component/Debug/Exception/FlattenException.php index 75bd2b1df7..d8d5c5b921 100644 --- a/src/Symfony/Component/Debug/Exception/FlattenException.php +++ b/src/Symfony/Component/Debug/Exception/FlattenException.php @@ -9,6 +9,46 @@ * file that was distributed with this source code. */ +namespace Symfony\Component\HttpKernel\Exception; + +use Symfony\Component\Debug\Exception\FlattenException as DebugFlattenException; + +/** + * FlattenException wraps a PHP Exception to be able to serialize it. + * + * Basically, this class removes all objects from the trace. + * + * @author Fabien Potencier + * + * @deprecated Deprecated in 2.3, to be removed in 3.0. Use the same class from the Debug component instead. + */ +class FlattenException +{ + private $handler; + + public static function __callStatic($method, $args) + { + if (!method_exists('Symfony\Component\Debug\Exception\FlattenException', $method)) { + throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_called_class(), $method)); + } + + return call_user_func_array(array('Symfony\Component\Debug\Exception\FlattenException', $method), $args); + } + + public function __call($method, $args) + { + if (!isset($this->handler)) { + $this->handler = new DebugFlattenException(); + } + + if (!method_exists($this->handler, $method)) { + throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_class($this), $method)); + } + + return call_user_func_array(array($this->handler, $method), $args); + } +} + namespace Symfony\Component\Debug\Exception; use Symfony\Component\HttpKernel\Exception\FlattenException as LegacyFlattenException; @@ -250,35 +290,3 @@ class FlattenException extends LegacyFlattenException return $array['__PHP_Incomplete_Class_Name']; } } - -namespace Symfony\Component\HttpKernel\Exception; - -use Symfony\Component\Debug\Exception\FlattenException as DebugFlattenException; - -/** - * FlattenException wraps a PHP Exception to be able to serialize it. - * - * Basically, this class removes all objects from the trace. - * - * @author Fabien Potencier - * - * @deprecated Deprecated in 2.3, to be removed in 3.0. Use the same class from the Debug component instead. - */ -class FlattenException -{ - private $handler; - - public static function __callStatic($method, $args) - { - return forward_static_call_array(array('Symfony\Component\Debug\Exception\FlattenException', $method), $args); - } - - public function __call($method, $args) - { - if (!isset($this->handler)) { - $this->handler = new DebugFlattenException(); - } - - return call_user_func_array(array($this->handler, $method), $args); - } -} diff --git a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php index afe3ecd182..7e74a37aaf 100644 --- a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php +++ b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php @@ -91,8 +91,12 @@ class RegisterListenersPass implements CompilerPassInterface throw new \InvalidArgumentException(sprintf('The service "%s" must be public as event subscribers are lazy-loaded.', $id)); } + if ($def->isAbstract()) { + throw new \InvalidArgumentException(sprintf('The service "%s" must not be abstract as event subscribers are lazy-loaded.', $id)); + } + // We must assume that the class value has been correctly filled, even if the service is created by a factory - $class = $def->getClass(); + $class = $container->getParameterBag()->resolveValue($def->getClass()); $refClass = new \ReflectionClass($class); $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface'; diff --git a/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php b/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php index b291e1ee3c..0fdd6372bd 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php @@ -138,6 +138,58 @@ class RegisterListenersPassTest extends \PHPUnit_Framework_TestCase $registerListenersPass = new RegisterListenersPass(); $registerListenersPass->process($container); } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The service "foo" must not be abstract as event subscribers are lazy-loaded. + */ + public function testAbstractEventSubscriber() + { + $container = new ContainerBuilder(); + $container->register('foo', 'stdClass')->setAbstract(true)->addTag('kernel.event_subscriber', array()); + $container->register('event_dispatcher', 'stdClass'); + + $registerListenersPass = new RegisterListenersPass(); + $registerListenersPass->process($container); + } + + public function testEventSubscriberResolvableClassName() + { + $container = new ContainerBuilder(); + + $container->setParameter('subscriber.class', 'Symfony\Component\EventDispatcher\Tests\DependencyInjection\SubscriberService'); + $container->register('foo', '%subscriber.class%')->addTag('kernel.event_subscriber', array()); + $container->register('event_dispatcher', 'stdClass'); + + $registerListenersPass = new RegisterListenersPass(); + $registerListenersPass->process($container); + + $definition = $container->getDefinition('event_dispatcher'); + $expected_calls = array( + array( + 'addSubscriberService', + array( + 'foo', + 'Symfony\Component\EventDispatcher\Tests\DependencyInjection\SubscriberService', + ), + ), + ); + $this->assertSame($expected_calls, $definition->getMethodCalls()); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage You have requested a non-existent parameter "subscriber.class" + */ + public function testEventSubscriberUnresolvableClassName() + { + $container = new ContainerBuilder(); + $container->register('foo', '%subscriber.class%')->addTag('kernel.event_subscriber', array()); + $container->register('event_dispatcher', 'stdClass'); + + $registerListenersPass = new RegisterListenersPass(); + $registerListenersPass->process($container); + } } class SubscriberService implements \Symfony\Component\EventDispatcher\EventSubscriberInterface diff --git a/src/Symfony/Component/Yaml/Escaper.php b/src/Symfony/Component/Yaml/Escaper.php index 6f9785886f..2820778fea 100644 --- a/src/Symfony/Component/Yaml/Escaper.php +++ b/src/Symfony/Component/Yaml/Escaper.php @@ -72,7 +72,15 @@ class Escaper */ public static function requiresSingleQuoting($value) { - return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value); + // Determines if the PHP value contains any single characters that would + // cause it to require single quoting in YAML. + if (preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value)) { + return true; + } + + // Determines if a PHP value is entirely composed of a value that would + // require single quoting in YAML. + return in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off')); } /** diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index aec52e6295..1b4293d328 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -147,12 +147,10 @@ class Inline case Escaper::requiresDoubleQuoting($value): return Escaper::escapeWithDoubleQuotes($value); case Escaper::requiresSingleQuoting($value): + case preg_match(self::getTimestampRegex(), $value): return Escaper::escapeWithSingleQuotes($value); case '' == $value: return "''"; - case preg_match(self::getTimestampRegex(), $value): - case in_array(strtolower($value), array('null', '~', 'true', 'false')): - return "'$value'"; default: return $value; } diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 7f1876d7a9..ad5aac3ff8 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -194,6 +194,14 @@ class InlineTest extends \PHPUnit_Framework_TestCase array("'#cfcfcf'", '#cfcfcf'), array('::form_base.html.twig', '::form_base.html.twig'), + // Pre-YAML-1.2 booleans + array("'y'", 'y'), + array("'n'", 'n'), + array("'yes'", 'yes'), + array("'no'", 'no'), + array("'on'", 'on'), + array("'off'", 'off'), + array('2007-10-30', mktime(0, 0, 0, 10, 30, 2007)), array('2007-10-30T02:59:43Z', gmmktime(2, 59, 43, 10, 30, 2007)), array('2007-10-30 02:59:43 Z', gmmktime(2, 59, 43, 10, 30, 2007)), @@ -339,6 +347,14 @@ class InlineTest extends \PHPUnit_Framework_TestCase array("'-dash'", '-dash'), array("'-'", '-'), + // Pre-YAML-1.2 booleans + array("'y'", 'y'), + array("'n'", 'n'), + array("'yes'", 'yes'), + array("'no'", 'no'), + array("'on'", 'on'), + array("'off'", 'off'), + // sequences array('[foo, bar, false, null, 12]', array('foo', 'bar', false, null, 12)), array('[\'foo,bar\', \'foo bar\']', array('foo,bar', 'foo bar')),