Issue #2377281 by hussainweb: Upgrade to Symfony 2.6 stable

8.0.x
Alex Pott 2014-11-28 22:53:38 +00:00
parent 596978a71d
commit 93c75faa37
58 changed files with 1529 additions and 1355 deletions

View File

@ -6,17 +6,17 @@
"require": {
"php": ">=5.4.5",
"sdboyer/gliph": "0.1.*",
"symfony/class-loader": "2.6.0-beta1",
"symfony/css-selector": "2.6.0-beta1",
"symfony/debug": "2.6.0-beta1",
"symfony/dependency-injection": "2.6.0-beta1",
"symfony/event-dispatcher": "2.6.0-beta1",
"symfony/http-foundation": "2.6.0-beta1",
"symfony/http-kernel": "2.6.0-beta1",
"symfony/routing": "2.6.0-beta1",
"symfony/serializer": "2.6.0-beta1",
"symfony/validator": "2.6.0-beta1",
"symfony/yaml": "2.6.0-beta1",
"symfony/class-loader": "2.6.*",
"symfony/css-selector": "2.6.*",
"symfony/debug": "2.6.*",
"symfony/dependency-injection": "2.6.*",
"symfony/event-dispatcher": "2.6.*",
"symfony/http-foundation": "2.6.*",
"symfony/http-kernel": "2.6.*",
"symfony/routing": "2.6.*",
"symfony/serializer": "2.6.*",
"symfony/validator": "2.6.*",
"symfony/yaml": "2.6.*",
"twig/twig": "1.16.*",
"doctrine/common": "dev-master#a45d110f71c323e29f41eb0696fa230e3fa1b1b5",
"doctrine/annotations": "1.2.*",

129
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "34a4f5a56891e51217c305b97e8cc675",
"hash": "fce47406c708047e654d8274620405e8",
"packages": [
{
"name": "doctrine/annotations",
@ -1643,17 +1643,17 @@
},
{
"name": "symfony/class-loader",
"version": "v2.6.0-BETA1",
"version": "v2.6.0",
"target-dir": "Symfony/Component/ClassLoader",
"source": {
"type": "git",
"url": "https://github.com/symfony/ClassLoader.git",
"reference": "d1a16139ea522ec3cc20801b7e19cd3cafd12d8c"
"reference": "b403af3d4fa3a2c3c926121c05042107e3a5b916"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/ClassLoader/zipball/d1a16139ea522ec3cc20801b7e19cd3cafd12d8c",
"reference": "d1a16139ea522ec3cc20801b7e19cd3cafd12d8c",
"url": "https://api.github.com/repos/symfony/ClassLoader/zipball/b403af3d4fa3a2c3c926121c05042107e3a5b916",
"reference": "b403af3d4fa3a2c3c926121c05042107e3a5b916",
"shasum": ""
},
"require": {
@ -1689,11 +1689,11 @@
],
"description": "Symfony ClassLoader Component",
"homepage": "http://symfony.com",
"time": "2014-11-03 03:55:50"
"time": "2014-11-20 13:24:23"
},
{
"name": "symfony/css-selector",
"version": "v2.6.0-BETA1",
"version": "v2.6.0",
"target-dir": "Symfony/Component/CssSelector",
"source": {
"type": "git",
@ -1744,17 +1744,17 @@
},
{
"name": "symfony/debug",
"version": "v2.6.0-BETA1",
"version": "v2.6.0",
"target-dir": "Symfony/Component/Debug",
"source": {
"type": "git",
"url": "https://github.com/symfony/Debug.git",
"reference": "3548595c26175fdaca19cbec204668c22cda41f0"
"reference": "e1e27710efabc3f67a2d1f6710641b3bdca289d3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Debug/zipball/3548595c26175fdaca19cbec204668c22cda41f0",
"reference": "3548595c26175fdaca19cbec204668c22cda41f0",
"url": "https://api.github.com/repos/symfony/Debug/zipball/e1e27710efabc3f67a2d1f6710641b3bdca289d3",
"reference": "e1e27710efabc3f67a2d1f6710641b3bdca289d3",
"shasum": ""
},
"require": {
@ -1796,21 +1796,21 @@
],
"description": "Symfony Debug Component",
"homepage": "http://symfony.com",
"time": "2014-10-28 10:06:58"
"time": "2014-11-28 10:00:40"
},
{
"name": "symfony/dependency-injection",
"version": "v2.6.0-BETA1",
"version": "v2.6.0",
"target-dir": "Symfony/Component/DependencyInjection",
"source": {
"type": "git",
"url": "https://github.com/symfony/DependencyInjection.git",
"reference": "926500fe0b8a6562c4e8b8166a1cb664733804aa"
"reference": "20bc8737876e4a2222101749b5547fd5acc24e30"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/926500fe0b8a6562c4e8b8166a1cb664733804aa",
"reference": "926500fe0b8a6562c4e8b8166a1cb664733804aa",
"url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/20bc8737876e4a2222101749b5547fd5acc24e30",
"reference": "20bc8737876e4a2222101749b5547fd5acc24e30",
"shasum": ""
},
"require": {
@ -1853,21 +1853,21 @@
],
"description": "Symfony DependencyInjection Component",
"homepage": "http://symfony.com",
"time": "2014-11-03 03:55:50"
"time": "2014-11-28 10:00:40"
},
{
"name": "symfony/event-dispatcher",
"version": "v2.6.0-BETA1",
"version": "v2.6.0",
"target-dir": "Symfony/Component/EventDispatcher",
"source": {
"type": "git",
"url": "https://github.com/symfony/EventDispatcher.git",
"reference": "dcf345d5ed96bc6c3b4521c1989670d2c9e5014e"
"reference": "697331d4ac78668cf6d21a2bb009b3faae92814f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/dcf345d5ed96bc6c3b4521c1989670d2c9e5014e",
"reference": "dcf345d5ed96bc6c3b4521c1989670d2c9e5014e",
"url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/697331d4ac78668cf6d21a2bb009b3faae92814f",
"reference": "697331d4ac78668cf6d21a2bb009b3faae92814f",
"shasum": ""
},
"require": {
@ -1911,21 +1911,21 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "http://symfony.com",
"time": "2014-11-03 03:55:50"
"time": "2014-11-28 10:00:40"
},
{
"name": "symfony/http-foundation",
"version": "v2.6.0-BETA1",
"version": "v2.6.0",
"target-dir": "Symfony/Component/HttpFoundation",
"source": {
"type": "git",
"url": "https://github.com/symfony/HttpFoundation.git",
"reference": "4cd6c807598e560db7b3da50c4330fdb4808cfa1"
"reference": "bb46e43145184ce8c3069a8ea2c299fb53d432f9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/4cd6c807598e560db7b3da50c4330fdb4808cfa1",
"reference": "4cd6c807598e560db7b3da50c4330fdb4808cfa1",
"url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/bb46e43145184ce8c3069a8ea2c299fb53d432f9",
"reference": "bb46e43145184ce8c3069a8ea2c299fb53d432f9",
"shasum": ""
},
"require": {
@ -1964,21 +1964,21 @@
],
"description": "Symfony HttpFoundation Component",
"homepage": "http://symfony.com",
"time": "2014-11-03 03:55:50"
"time": "2014-11-28 10:00:40"
},
{
"name": "symfony/http-kernel",
"version": "v2.6.0-BETA1",
"version": "v2.6.0",
"target-dir": "Symfony/Component/HttpKernel",
"source": {
"type": "git",
"url": "https://github.com/symfony/HttpKernel.git",
"reference": "7fa0bd9220cd529ee78d8565bbf8d5a854bd72d2"
"reference": "0e3cad4d574e84b01d2a0df706bb31f024a93bdc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/HttpKernel/zipball/7fa0bd9220cd529ee78d8565bbf8d5a854bd72d2",
"reference": "7fa0bd9220cd529ee78d8565bbf8d5a854bd72d2",
"url": "https://api.github.com/repos/symfony/HttpKernel/zipball/0e3cad4d574e84b01d2a0df706bb31f024a93bdc",
"reference": "0e3cad4d574e84b01d2a0df706bb31f024a93bdc",
"shasum": ""
},
"require": {
@ -2039,21 +2039,21 @@
],
"description": "Symfony HttpKernel Component",
"homepage": "http://symfony.com",
"time": "2014-11-03 20:15:26"
"time": "2014-11-28 15:59:01"
},
{
"name": "symfony/routing",
"version": "v2.6.0-BETA1",
"version": "v2.6.0",
"target-dir": "Symfony/Component/Routing",
"source": {
"type": "git",
"url": "https://github.com/symfony/Routing.git",
"reference": "f0bb6f818f9a7ece41c7dfe14e08b13c2de55b0c"
"reference": "5e2c6aba6cbb00a6b7e3760db99f72c85c52b6e5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Routing/zipball/f0bb6f818f9a7ece41c7dfe14e08b13c2de55b0c",
"reference": "f0bb6f818f9a7ece41c7dfe14e08b13c2de55b0c",
"url": "https://api.github.com/repos/symfony/Routing/zipball/5e2c6aba6cbb00a6b7e3760db99f72c85c52b6e5",
"reference": "5e2c6aba6cbb00a6b7e3760db99f72c85c52b6e5",
"shasum": ""
},
"require": {
@ -2106,21 +2106,21 @@
"uri",
"url"
],
"time": "2014-11-03 19:16:49"
"time": "2014-11-16 17:28:09"
},
{
"name": "symfony/serializer",
"version": "v2.6.0-BETA1",
"version": "v2.6.0",
"target-dir": "Symfony/Component/Serializer",
"source": {
"type": "git",
"url": "https://github.com/symfony/Serializer.git",
"reference": "e96b7ac54b3d75a458f76eab11b7cd2d757f09f1"
"reference": "16e548902fab42d26ceb1de5ca06ab676d1a81a7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Serializer/zipball/e96b7ac54b3d75a458f76eab11b7cd2d757f09f1",
"reference": "e96b7ac54b3d75a458f76eab11b7cd2d757f09f1",
"url": "https://api.github.com/repos/symfony/Serializer/zipball/16e548902fab42d26ceb1de5ca06ab676d1a81a7",
"reference": "16e548902fab42d26ceb1de5ca06ab676d1a81a7",
"shasum": ""
},
"require": {
@ -2153,39 +2153,41 @@
],
"description": "Symfony Serializer Component",
"homepage": "http://symfony.com",
"time": "2014-11-03 03:55:50"
"time": "2014-11-20 13:24:23"
},
{
"name": "symfony/translation",
"version": "v2.5.6",
"version": "v2.6.0",
"target-dir": "Symfony/Component/Translation",
"source": {
"type": "git",
"url": "https://github.com/symfony/Translation.git",
"reference": "362fe4da2cfe587f72d57aaa2f89e6b61c05dedf"
"reference": "0a3711860976f15ee46642b4dd354e9ef9fc9a15"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Translation/zipball/362fe4da2cfe587f72d57aaa2f89e6b61c05dedf",
"reference": "362fe4da2cfe587f72d57aaa2f89e6b61c05dedf",
"url": "https://api.github.com/repos/symfony/Translation/zipball/0a3711860976f15ee46642b4dd354e9ef9fc9a15",
"reference": "0a3711860976f15ee46642b4dd354e9ef9fc9a15",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~2.0",
"symfony/intl": "~2.3",
"symfony/yaml": "~2.2"
},
"suggest": {
"psr/log": "To use logging capability in translator",
"symfony/config": "",
"symfony/yaml": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5-dev"
"dev-master": "2.6-dev"
}
},
"autoload": {
@ -2209,21 +2211,21 @@
],
"description": "Symfony Translation Component",
"homepage": "http://symfony.com",
"time": "2014-10-01 05:50:18"
"time": "2014-11-28 10:00:40"
},
{
"name": "symfony/validator",
"version": "v2.6.0-BETA1",
"version": "v2.6.0",
"target-dir": "Symfony/Component/Validator",
"source": {
"type": "git",
"url": "https://github.com/symfony/Validator.git",
"reference": "6e521cdbc963cef7daf9931a7bde48b56d67d10a"
"reference": "cbf6575c4c9c83621df01483e215599f5377fc0b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Validator/zipball/6e521cdbc963cef7daf9931a7bde48b56d67d10a",
"reference": "6e521cdbc963cef7daf9931a7bde48b56d67d10a",
"url": "https://api.github.com/repos/symfony/Validator/zipball/cbf6575c4c9c83621df01483e215599f5377fc0b",
"reference": "cbf6575c4c9c83621df01483e215599f5377fc0b",
"shasum": ""
},
"require": {
@ -2279,21 +2281,21 @@
],
"description": "Symfony Validator Component",
"homepage": "http://symfony.com",
"time": "2014-11-03 03:55:50"
"time": "2014-11-28 10:00:40"
},
{
"name": "symfony/yaml",
"version": "v2.6.0-BETA1",
"version": "v2.6.0",
"target-dir": "Symfony/Component/Yaml",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml.git",
"reference": "9da3813f36985a4089f7e83c601a1034d125ff69"
"reference": "51c845cf3e4bfc182d1d5c05ed1c7338361d86f8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/9da3813f36985a4089f7e83c601a1034d125ff69",
"reference": "9da3813f36985a4089f7e83c601a1034d125ff69",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/51c845cf3e4bfc182d1d5c05ed1c7338361d86f8",
"reference": "51c845cf3e4bfc182d1d5c05ed1c7338361d86f8",
"shasum": ""
},
"require": {
@ -2326,7 +2328,7 @@
],
"description": "Symfony Yaml Component",
"homepage": "http://symfony.com",
"time": "2014-11-03 03:55:50"
"time": "2014-11-20 13:24:23"
},
{
"name": "twig/twig",
@ -2522,17 +2524,6 @@
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"symfony/class-loader": 10,
"symfony/css-selector": 10,
"symfony/debug": 10,
"symfony/dependency-injection": 10,
"symfony/event-dispatcher": 10,
"symfony/http-foundation": 10,
"symfony/http-kernel": 10,
"symfony/routing": 10,
"symfony/serializer": 10,
"symfony/validator": 10,
"symfony/yaml": 10,
"doctrine/common": 20,
"phpunit/phpunit-mock-objects": 20
},

View File

@ -56,7 +56,10 @@ class ClassLoader
public function getPrefixes()
{
return call_user_func_array('array_merge', $this->prefixesPsr0);
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()

File diff suppressed because it is too large Load Diff

View File

@ -11,8 +11,10 @@
namespace Symfony\Component\ClassLoader;
if (!defined('T_TRAIT')) {
define('T_TRAIT', 0);
if (PHP_VERSION_ID >= 50400) {
define('SYMFONY_TRAIT', T_TRAIT);
} else {
define('SYMFONY_TRAIT', 0);
}
/**
@ -113,7 +115,7 @@ class ClassMapGenerator
break;
case T_CLASS:
case T_INTERFACE:
case T_TRAIT:
case SYMFONY_TRAIT:
// Find the classname
while (($t = $tokens[++$i]) && is_array($t)) {
if (T_STRING === $t[0]) {

View File

@ -22,7 +22,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
{
public function testTraitDependencies()
{
if (version_compare(phpversion(), '5.4', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Requires PHP > 5.4');
return;
@ -100,7 +100,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
*/
public function testClassWithTraitsReordering(array $classes)
{
if (version_compare(phpversion(), '5.4', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Requires PHP > 5.4');
return;

View File

@ -104,7 +104,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
)),
);
if (version_compare(PHP_VERSION, '5.4', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$data[] = array(__DIR__.'/Fixtures/php5.4', array(
'TFoo' => __DIR__.'/Fixtures/php5.4/traits.php',
'CFoo' => __DIR__.'/Fixtures/php5.4/traits.php',

View File

@ -487,7 +487,6 @@ class ErrorHandler
public static function handleFatalError(array $error = null)
{
self::$reservedMemory = '';
gc_collect_cycles();
$handler = set_error_handler('var_dump', 0);
$handler = is_array($handler) ? $handler[0] : null;
restore_error_handler();

View File

@ -15,10 +15,6 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\Debug\Exception\OutOfMemoryException;
if (!defined('ENT_SUBSTITUTE')) {
define('ENT_SUBSTITUTE', 8);
}
/**
* ExceptionHandler converts an exception to a Response object.
*
@ -253,7 +249,7 @@ EOF
} catch (\Exception $e) {
// something nasty happened and we cannot throw an exception anymore
if ($this->debug) {
$title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception->getMessage());
$title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage());
} else {
$title = 'Whoops, looks like something went wrong.';
}
@ -428,7 +424,7 @@ EOF;
$str = iconv($charset, 'UTF-8', $str);
}
return htmlspecialchars($str, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
return htmlspecialchars($str, ENT_QUOTES | (PHP_VERSION_ID >= 50400 ? ENT_SUBSTITUTE : 0), 'UTF-8');
}
/**

View File

@ -162,21 +162,21 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
$handler->setDefaultLogger($logger, array(E_USER_NOTICE => LogLevel::CRITICAL));
$loggers = array(
E_DEPRECATED => array(null, LogLevel::INFO),
E_USER_DEPRECATED => array(null, LogLevel::INFO),
E_NOTICE => array($logger, LogLevel::NOTICE),
E_USER_NOTICE => array($logger, LogLevel::CRITICAL),
E_STRICT => array(null, LogLevel::NOTICE),
E_WARNING => array(null, LogLevel::WARNING),
E_USER_WARNING => array(null, LogLevel::WARNING),
E_COMPILE_WARNING => array(null, LogLevel::WARNING),
E_CORE_WARNING => array(null, LogLevel::WARNING),
E_USER_ERROR => array(null, LogLevel::ERROR),
E_DEPRECATED => array(null, LogLevel::INFO),
E_USER_DEPRECATED => array(null, LogLevel::INFO),
E_NOTICE => array($logger, LogLevel::NOTICE),
E_USER_NOTICE => array($logger, LogLevel::CRITICAL),
E_STRICT => array(null, LogLevel::NOTICE),
E_WARNING => array(null, LogLevel::WARNING),
E_USER_WARNING => array(null, LogLevel::WARNING),
E_COMPILE_WARNING => array(null, LogLevel::WARNING),
E_CORE_WARNING => array(null, LogLevel::WARNING),
E_USER_ERROR => array(null, LogLevel::ERROR),
E_RECOVERABLE_ERROR => array(null, LogLevel::ERROR),
E_COMPILE_ERROR => array(null, LogLevel::EMERGENCY),
E_PARSE => array(null, LogLevel::EMERGENCY),
E_ERROR => array(null, LogLevel::EMERGENCY),
E_CORE_ERROR => array(null, LogLevel::EMERGENCY),
E_COMPILE_ERROR => array(null, LogLevel::EMERGENCY),
E_PARSE => array(null, LogLevel::EMERGENCY),
E_ERROR => array(null, LogLevel::EMERGENCY),
E_CORE_ERROR => array(null, LogLevel::EMERGENCY),
);
$this->assertSame($loggers, $handler->setLoggers(array()));

View File

@ -114,6 +114,10 @@ class AnalyzeServiceReferencesPass implements RepeatablePassInterface
$this->processArguments($argument->getArguments());
$this->processArguments($argument->getMethodCalls());
$this->processArguments($argument->getProperties());
if ($argument->getFactoryService()) {
$this->processArguments(array(new Reference($argument->getFactoryService())));
}
}
}
}

View File

@ -144,6 +144,10 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface
return false;
}
if (count($ids) > 1 && $definition->getFactoryService()) {
return false;
}
return $container->getDefinition(reset($ids))->getScope() === $definition->getScope();
}
}

View File

@ -360,6 +360,10 @@ class Container implements IntrospectableContainerInterface
return true;
}
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
return isset($this->services[$id]) || array_key_exists($id, $this->services);
}

View File

@ -79,6 +79,28 @@ class AnalyzeServiceReferencesPassTest extends \PHPUnit_Framework_TestCase
$this->assertSame($ref, $refs[0]->getValue());
}
public function testProcessDetectsReferencesFromInlinedFactoryDefinitions()
{
$container = new ContainerBuilder();
$container
->register('a')
;
$factory = new Definition();
$factory->setFactoryService('a');
$container
->register('b')
->addArgument($factory)
;
$graph = $this->process($container);
$this->assertTrue($graph->hasNode('a'));
$this->assertCount(1, $refs = $graph->getNode('a')->getInEdges());
}
public function testProcessDoesNotSaveDuplicateReferences()
{
$container = new ContainerBuilder();

View File

@ -110,6 +110,84 @@ class InlineServiceDefinitionsPassTest extends \PHPUnit_Framework_TestCase
$this->assertSame($a, $inlinedArguments[0]);
}
public function testProcessInlinesPrivateFactoryReference()
{
$container = new ContainerBuilder();
$container->register('a')->setPublic(false);
$b = $container
->register('b')
->setPublic(false)
->setFactoryService('a')
;
$container
->register('foo')
->setArguments(array(
$ref = new Reference('b'),
));
$this->process($container);
$inlinedArguments = $container->getDefinition('foo')->getArguments();
$this->assertSame($b, $inlinedArguments[0]);
}
public function testProcessDoesNotInlinePrivateFactoryIfReferencedMultipleTimesWithinTheSameDefinition()
{
$container = new ContainerBuilder();
$container
->register('a')
;
$container
->register('b')
->setPublic(false)
->setFactoryService('a')
;
$container
->register('foo')
->setArguments(array(
$ref1 = new Reference('b'),
$ref2 = new Reference('b'),
))
;
$this->process($container);
$args = $container->getDefinition('foo')->getArguments();
$this->assertSame($ref1, $args[0]);
$this->assertSame($ref2, $args[1]);
}
public function testProcessDoesNotInlineReferenceWhenUsedByInlineFactory()
{
$container = new ContainerBuilder();
$container
->register('a')
;
$container
->register('b')
->setPublic(false)
->setFactoryService('a')
;
$inlineFactory = new Definition();
$inlineFactory->setPublic(false);
$inlineFactory->setFactoryService('b');
$container
->register('foo')
->setArguments(array(
$ref = new Reference('b'),
$inlineFactory,
))
;
$this->process($container);
$args = $container->getDefinition('foo')->getArguments();
$this->assertSame($ref, $args[0]);
}
public function testProcessInlinesOnlyIfSameScope()
{
$container = new ContainerBuilder();

View File

@ -305,6 +305,10 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($sc->initialized('foo'), '->initialized() returns true if service is loaded');
$this->assertFalse($sc->initialized('foo1'), '->initialized() returns false if service is not loaded');
$this->assertFalse($sc->initialized('bar'), '->initialized() returns false if a service is defined, but not currently loaded');
$this->assertFalse($sc->initialized('alias'), '->initialized() returns false if an aliased service is not initialized');
$sc->set('bar', new \stdClass());
$this->assertTrue($sc->initialized('alias'), '->initialized() returns true for alias if aliased service is initialized');
}
public function testEnterLeaveCurrentScope()

View File

@ -1,7 +1,7 @@
EventDispatcher Component
=========================
The Symfony2 EventDispatcher component implements the Mediator pattern in a
The Symfony EventDispatcher component implements the Mediator pattern in a
simple and effective way to make your projects truly extensible.
```php

View File

@ -0,0 +1,369 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\EventDispatcher\Tests;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
{
/* Some pseudo events */
const preFoo = 'pre.foo';
const postFoo = 'post.foo';
const preBar = 'pre.bar';
const postBar = 'post.bar';
/**
* @var EventDispatcher
*/
private $dispatcher;
private $listener;
protected function setUp()
{
$this->dispatcher = $this->createEventDispatcher();
$this->listener = new TestEventListener();
}
protected function tearDown()
{
$this->dispatcher = null;
$this->listener = null;
}
abstract protected function createEventDispatcher();
public function testInitialState()
{
$this->assertEquals(array(), $this->dispatcher->getListeners());
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
$this->assertFalse($this->dispatcher->hasListeners(self::postFoo));
}
public function testAddListener()
{
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
$this->assertCount(1, $this->dispatcher->getListeners(self::preFoo));
$this->assertCount(1, $this->dispatcher->getListeners(self::postFoo));
$this->assertCount(2, $this->dispatcher->getListeners());
}
public function testGetListenersSortsByPriority()
{
$listener1 = new TestEventListener();
$listener2 = new TestEventListener();
$listener3 = new TestEventListener();
$listener1->name = '1';
$listener2->name = '2';
$listener3->name = '3';
$this->dispatcher->addListener('pre.foo', array($listener1, 'preFoo'), -10);
$this->dispatcher->addListener('pre.foo', array($listener2, 'preFoo'), 10);
$this->dispatcher->addListener('pre.foo', array($listener3, 'preFoo'));
$expected = array(
array($listener2, 'preFoo'),
array($listener3, 'preFoo'),
array($listener1, 'preFoo'),
);
$this->assertSame($expected, $this->dispatcher->getListeners('pre.foo'));
}
public function testGetAllListenersSortsByPriority()
{
$listener1 = new TestEventListener();
$listener2 = new TestEventListener();
$listener3 = new TestEventListener();
$listener4 = new TestEventListener();
$listener5 = new TestEventListener();
$listener6 = new TestEventListener();
$this->dispatcher->addListener('pre.foo', $listener1, -10);
$this->dispatcher->addListener('pre.foo', $listener2);
$this->dispatcher->addListener('pre.foo', $listener3, 10);
$this->dispatcher->addListener('post.foo', $listener4, -10);
$this->dispatcher->addListener('post.foo', $listener5);
$this->dispatcher->addListener('post.foo', $listener6, 10);
$expected = array(
'pre.foo' => array($listener3, $listener2, $listener1),
'post.foo' => array($listener6, $listener5, $listener4),
);
$this->assertSame($expected, $this->dispatcher->getListeners());
}
public function testDispatch()
{
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
$this->dispatcher->dispatch(self::preFoo);
$this->assertTrue($this->listener->preFooInvoked);
$this->assertFalse($this->listener->postFooInvoked);
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch('noevent'));
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch(self::preFoo));
$event = new Event();
$return = $this->dispatcher->dispatch(self::preFoo, $event);
$this->assertEquals('pre.foo', $event->getName());
$this->assertSame($event, $return);
}
public function testDispatchForClosure()
{
$invoked = 0;
$listener = function () use (&$invoked) {
$invoked++;
};
$this->dispatcher->addListener('pre.foo', $listener);
$this->dispatcher->addListener('post.foo', $listener);
$this->dispatcher->dispatch(self::preFoo);
$this->assertEquals(1, $invoked);
}
public function testStopEventPropagation()
{
$otherListener = new TestEventListener();
// postFoo() stops the propagation, so only one listener should
// be executed
// Manually set priority to enforce $this->listener to be called first
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'), 10);
$this->dispatcher->addListener('post.foo', array($otherListener, 'preFoo'));
$this->dispatcher->dispatch(self::postFoo);
$this->assertTrue($this->listener->postFooInvoked);
$this->assertFalse($otherListener->postFooInvoked);
}
public function testDispatchByPriority()
{
$invoked = array();
$listener1 = function () use (&$invoked) {
$invoked[] = '1';
};
$listener2 = function () use (&$invoked) {
$invoked[] = '2';
};
$listener3 = function () use (&$invoked) {
$invoked[] = '3';
};
$this->dispatcher->addListener('pre.foo', $listener1, -10);
$this->dispatcher->addListener('pre.foo', $listener2);
$this->dispatcher->addListener('pre.foo', $listener3, 10);
$this->dispatcher->dispatch(self::preFoo);
$this->assertEquals(array('3', '2', '1'), $invoked);
}
public function testRemoveListener()
{
$this->dispatcher->addListener('pre.bar', $this->listener);
$this->assertTrue($this->dispatcher->hasListeners(self::preBar));
$this->dispatcher->removeListener('pre.bar', $this->listener);
$this->assertFalse($this->dispatcher->hasListeners(self::preBar));
$this->dispatcher->removeListener('notExists', $this->listener);
}
public function testAddSubscriber()
{
$eventSubscriber = new TestEventSubscriber();
$this->dispatcher->addSubscriber($eventSubscriber);
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
}
public function testAddSubscriberWithPriorities()
{
$eventSubscriber = new TestEventSubscriber();
$this->dispatcher->addSubscriber($eventSubscriber);
$eventSubscriber = new TestEventSubscriberWithPriorities();
$this->dispatcher->addSubscriber($eventSubscriber);
$listeners = $this->dispatcher->getListeners('pre.foo');
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertCount(2, $listeners);
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Tests\TestEventSubscriberWithPriorities', $listeners[0][0]);
}
public function testAddSubscriberWithMultipleListeners()
{
$eventSubscriber = new TestEventSubscriberWithMultipleListeners();
$this->dispatcher->addSubscriber($eventSubscriber);
$listeners = $this->dispatcher->getListeners('pre.foo');
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertCount(2, $listeners);
$this->assertEquals('preFoo2', $listeners[0][1]);
}
public function testRemoveSubscriber()
{
$eventSubscriber = new TestEventSubscriber();
$this->dispatcher->addSubscriber($eventSubscriber);
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
$this->dispatcher->removeSubscriber($eventSubscriber);
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
$this->assertFalse($this->dispatcher->hasListeners(self::postFoo));
}
public function testRemoveSubscriberWithPriorities()
{
$eventSubscriber = new TestEventSubscriberWithPriorities();
$this->dispatcher->addSubscriber($eventSubscriber);
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->dispatcher->removeSubscriber($eventSubscriber);
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
}
public function testRemoveSubscriberWithMultipleListeners()
{
$eventSubscriber = new TestEventSubscriberWithMultipleListeners();
$this->dispatcher->addSubscriber($eventSubscriber);
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertCount(2, $this->dispatcher->getListeners(self::preFoo));
$this->dispatcher->removeSubscriber($eventSubscriber);
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
}
public function testEventReceivesTheDispatcherInstance()
{
$dispatcher = null;
$this->dispatcher->addListener('test', function ($event) use (&$dispatcher) {
$dispatcher = $event->getDispatcher();
});
$this->dispatcher->dispatch('test');
$this->assertSame($this->dispatcher, $dispatcher);
}
public function testEventReceivesTheDispatcherInstanceAsArgument()
{
$listener = new TestWithDispatcher();
$this->dispatcher->addListener('test', array($listener, 'foo'));
$this->assertNull($listener->name);
$this->assertNull($listener->dispatcher);
$this->dispatcher->dispatch('test');
$this->assertEquals('test', $listener->name);
$this->assertSame($this->dispatcher, $listener->dispatcher);
}
/**
* @see https://bugs.php.net/bug.php?id=62976
*
* This bug affects:
* - The PHP 5.3 branch for versions < 5.3.18
* - The PHP 5.4 branch for versions < 5.4.8
* - The PHP 5.5 branch is not affected
*/
public function testWorkaroundForPhpBug62976()
{
$dispatcher = $this->createEventDispatcher();
$dispatcher->addListener('bug.62976', new CallableClass());
$dispatcher->removeListener('bug.62976', function () {});
$this->assertTrue($dispatcher->hasListeners('bug.62976'));
}
public function testHasListenersWhenAddedCallbackListenerIsRemoved()
{
$listener = function () {};
$this->dispatcher->addListener('foo', $listener);
$this->dispatcher->removeListener('foo', $listener);
$this->assertFalse($this->dispatcher->hasListeners());
}
public function testGetListenersWhenAddedCallbackListenerIsRemoved()
{
$listener = function () {};
$this->dispatcher->addListener('foo', $listener);
$this->dispatcher->removeListener('foo', $listener);
$this->assertSame(array(), $this->dispatcher->getListeners());
}
public function testHasListenersWithoutEventsReturnsFalseAfterHasListenersWithEventHasBeenCalled()
{
$this->assertFalse($this->dispatcher->hasListeners('foo'));
$this->assertFalse($this->dispatcher->hasListeners());
}
}
class CallableClass
{
public function __invoke()
{
}
}
class TestEventListener
{
public $preFooInvoked = false;
public $postFooInvoked = false;
/* Listener methods */
public function preFoo(Event $e)
{
$this->preFooInvoked = true;
}
public function postFoo(Event $e)
{
$this->postFooInvoked = true;
$e->stopPropagation();
}
}
class TestWithDispatcher
{
public $name;
public $dispatcher;
public function foo(Event $e, $name, $dispatcher)
{
$this->name = $name;
$this->dispatcher = $dispatcher;
}
}
class TestEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array('pre.foo' => 'preFoo', 'post.foo' => 'postFoo');
}
}
class TestEventSubscriberWithPriorities implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array(
'pre.foo' => array('preFoo', 10),
'post.foo' => array('postFoo'),
);
}
}
class TestEventSubscriberWithMultipleListeners implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array('pre.foo' => array(
array('preFoo1'),
array('preFoo2', 10),
));
}
}

View File

@ -17,8 +17,14 @@ use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ContainerAwareEventDispatcherTest extends \PHPUnit_Framework_TestCase
class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
{
protected function createEventDispatcher()
{
$container = new Container();
return new ContainerAwareEventDispatcher($container);
}
public function testAddAListenerService()
{
$event = new Event();

View File

@ -11,358 +11,12 @@
namespace Symfony\Component\EventDispatcher\Tests;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class EventDispatcherTest extends \PHPUnit_Framework_TestCase
class EventDispatcherTest extends AbstractEventDispatcherTest
{
/* Some pseudo events */
const preFoo = 'pre.foo';
const postFoo = 'post.foo';
const preBar = 'pre.bar';
const postBar = 'post.bar';
/**
* @var EventDispatcher
*/
private $dispatcher;
private $listener;
protected function setUp()
protected function createEventDispatcher()
{
$this->dispatcher = new EventDispatcher();
$this->listener = new TestEventListener();
}
protected function tearDown()
{
$this->dispatcher = null;
$this->listener = null;
}
public function testInitialState()
{
$this->assertEquals(array(), $this->dispatcher->getListeners());
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
$this->assertFalse($this->dispatcher->hasListeners(self::postFoo));
}
public function testAddListener()
{
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
$this->assertCount(1, $this->dispatcher->getListeners(self::preFoo));
$this->assertCount(1, $this->dispatcher->getListeners(self::postFoo));
$this->assertCount(2, $this->dispatcher->getListeners());
}
public function testGetListenersSortsByPriority()
{
$listener1 = new TestEventListener();
$listener2 = new TestEventListener();
$listener3 = new TestEventListener();
$listener1->name = '1';
$listener2->name = '2';
$listener3->name = '3';
$this->dispatcher->addListener('pre.foo', array($listener1, 'preFoo'), -10);
$this->dispatcher->addListener('pre.foo', array($listener2, 'preFoo'), 10);
$this->dispatcher->addListener('pre.foo', array($listener3, 'preFoo'));
$expected = array(
array($listener2, 'preFoo'),
array($listener3, 'preFoo'),
array($listener1, 'preFoo'),
);
$this->assertSame($expected, $this->dispatcher->getListeners('pre.foo'));
}
public function testGetAllListenersSortsByPriority()
{
$listener1 = new TestEventListener();
$listener2 = new TestEventListener();
$listener3 = new TestEventListener();
$listener4 = new TestEventListener();
$listener5 = new TestEventListener();
$listener6 = new TestEventListener();
$this->dispatcher->addListener('pre.foo', $listener1, -10);
$this->dispatcher->addListener('pre.foo', $listener2);
$this->dispatcher->addListener('pre.foo', $listener3, 10);
$this->dispatcher->addListener('post.foo', $listener4, -10);
$this->dispatcher->addListener('post.foo', $listener5);
$this->dispatcher->addListener('post.foo', $listener6, 10);
$expected = array(
'pre.foo' => array($listener3, $listener2, $listener1),
'post.foo' => array($listener6, $listener5, $listener4),
);
$this->assertSame($expected, $this->dispatcher->getListeners());
}
public function testDispatch()
{
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
$this->dispatcher->dispatch(self::preFoo);
$this->assertTrue($this->listener->preFooInvoked);
$this->assertFalse($this->listener->postFooInvoked);
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch('noevent'));
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $this->dispatcher->dispatch(self::preFoo));
$event = new Event();
$return = $this->dispatcher->dispatch(self::preFoo, $event);
$this->assertEquals('pre.foo', $event->getName());
$this->assertSame($event, $return);
}
public function testDispatchForClosure()
{
$invoked = 0;
$listener = function () use (&$invoked) {
$invoked++;
};
$this->dispatcher->addListener('pre.foo', $listener);
$this->dispatcher->addListener('post.foo', $listener);
$this->dispatcher->dispatch(self::preFoo);
$this->assertEquals(1, $invoked);
}
public function testStopEventPropagation()
{
$otherListener = new TestEventListener();
// postFoo() stops the propagation, so only one listener should
// be executed
// Manually set priority to enforce $this->listener to be called first
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'), 10);
$this->dispatcher->addListener('post.foo', array($otherListener, 'preFoo'));
$this->dispatcher->dispatch(self::postFoo);
$this->assertTrue($this->listener->postFooInvoked);
$this->assertFalse($otherListener->postFooInvoked);
}
public function testDispatchByPriority()
{
$invoked = array();
$listener1 = function () use (&$invoked) {
$invoked[] = '1';
};
$listener2 = function () use (&$invoked) {
$invoked[] = '2';
};
$listener3 = function () use (&$invoked) {
$invoked[] = '3';
};
$this->dispatcher->addListener('pre.foo', $listener1, -10);
$this->dispatcher->addListener('pre.foo', $listener2);
$this->dispatcher->addListener('pre.foo', $listener3, 10);
$this->dispatcher->dispatch(self::preFoo);
$this->assertEquals(array('3', '2', '1'), $invoked);
}
public function testRemoveListener()
{
$this->dispatcher->addListener('pre.bar', $this->listener);
$this->assertTrue($this->dispatcher->hasListeners(self::preBar));
$this->dispatcher->removeListener('pre.bar', $this->listener);
$this->assertFalse($this->dispatcher->hasListeners(self::preBar));
$this->dispatcher->removeListener('notExists', $this->listener);
}
public function testAddSubscriber()
{
$eventSubscriber = new TestEventSubscriber();
$this->dispatcher->addSubscriber($eventSubscriber);
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
}
public function testAddSubscriberWithPriorities()
{
$eventSubscriber = new TestEventSubscriber();
$this->dispatcher->addSubscriber($eventSubscriber);
$eventSubscriber = new TestEventSubscriberWithPriorities();
$this->dispatcher->addSubscriber($eventSubscriber);
$listeners = $this->dispatcher->getListeners('pre.foo');
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertCount(2, $listeners);
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Tests\TestEventSubscriberWithPriorities', $listeners[0][0]);
}
public function testAddSubscriberWithMultipleListeners()
{
$eventSubscriber = new TestEventSubscriberWithMultipleListeners();
$this->dispatcher->addSubscriber($eventSubscriber);
$listeners = $this->dispatcher->getListeners('pre.foo');
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertCount(2, $listeners);
$this->assertEquals('preFoo2', $listeners[0][1]);
}
public function testRemoveSubscriber()
{
$eventSubscriber = new TestEventSubscriber();
$this->dispatcher->addSubscriber($eventSubscriber);
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
$this->dispatcher->removeSubscriber($eventSubscriber);
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
$this->assertFalse($this->dispatcher->hasListeners(self::postFoo));
}
public function testRemoveSubscriberWithPriorities()
{
$eventSubscriber = new TestEventSubscriberWithPriorities();
$this->dispatcher->addSubscriber($eventSubscriber);
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->dispatcher->removeSubscriber($eventSubscriber);
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
}
public function testRemoveSubscriberWithMultipleListeners()
{
$eventSubscriber = new TestEventSubscriberWithMultipleListeners();
$this->dispatcher->addSubscriber($eventSubscriber);
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
$this->assertCount(2, $this->dispatcher->getListeners(self::preFoo));
$this->dispatcher->removeSubscriber($eventSubscriber);
$this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
}
public function testEventReceivesTheDispatcherInstance()
{
$dispatcher = null;
$this->dispatcher->addListener('test', function ($event) use (&$dispatcher) {
$dispatcher = $event->getDispatcher();
});
$this->dispatcher->dispatch('test');
$this->assertSame($this->dispatcher, $dispatcher);
}
public function testEventReceivesTheDispatcherInstanceAsArgument()
{
$listener = new TestWithDispatcher();
$this->dispatcher->addListener('test', array($listener, 'foo'));
$this->assertNull($listener->name);
$this->assertNull($listener->dispatcher);
$this->dispatcher->dispatch('test');
$this->assertEquals('test', $listener->name);
$this->assertSame($this->dispatcher, $listener->dispatcher);
}
/**
* @see https://bugs.php.net/bug.php?id=62976
*
* This bug affects:
* - The PHP 5.3 branch for versions < 5.3.18
* - The PHP 5.4 branch for versions < 5.4.8
* - The PHP 5.5 branch is not affected
*/
public function testWorkaroundForPhpBug62976()
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener('bug.62976', new CallableClass());
$dispatcher->removeListener('bug.62976', function () {});
$this->assertTrue($dispatcher->hasListeners('bug.62976'));
}
public function testHasListenersWhenAddedCallbackListenerIsRemoved()
{
$listener = function () {};
$this->dispatcher->addListener('foo', $listener);
$this->dispatcher->removeListener('foo', $listener);
$this->assertFalse($this->dispatcher->hasListeners());
}
public function testGetListenersWhenAddedCallbackListenerIsRemoved()
{
$listener = function () {};
$this->dispatcher->addListener('foo', $listener);
$this->dispatcher->removeListener('foo', $listener);
$this->assertSame(array(), $this->dispatcher->getListeners());
}
public function testHasListenersWithoutEventsReturnsFalseAfterHasListenersWithEventHasBeenCalled()
{
$this->assertFalse($this->dispatcher->hasListeners('foo'));
$this->assertFalse($this->dispatcher->hasListeners());
}
}
class CallableClass
{
public function __invoke()
{
}
}
class TestEventListener
{
public $preFooInvoked = false;
public $postFooInvoked = false;
/* Listener methods */
public function preFoo(Event $e)
{
$this->preFooInvoked = true;
}
public function postFoo(Event $e)
{
$this->postFooInvoked = true;
$e->stopPropagation();
}
}
class TestWithDispatcher
{
public $name;
public $dispatcher;
public function foo(Event $e, $name, $dispatcher)
{
$this->name = $name;
$this->dispatcher = $dispatcher;
}
}
class TestEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array('pre.foo' => 'preFoo', 'post.foo' => 'postFoo');
}
}
class TestEventSubscriberWithPriorities implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array(
'pre.foo' => array('preFoo', 10),
'post.foo' => array('postFoo'),
);
}
}
class TestEventSubscriberWithMultipleListeners implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array('pre.foo' => array(
array('preFoo1'),
array('preFoo2', 10),
));
return new EventDispatcher();
}
}

View File

@ -35,15 +35,15 @@ class Request
const HEADER_CLIENT_PROTO = 'client_proto';
const HEADER_CLIENT_PORT = 'client_port';
const METHOD_HEAD = 'HEAD';
const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
const METHOD_PUT = 'PUT';
const METHOD_PATCH = 'PATCH';
const METHOD_DELETE = 'DELETE';
const METHOD_PURGE = 'PURGE';
const METHOD_HEAD = 'HEAD';
const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
const METHOD_PUT = 'PUT';
const METHOD_PATCH = 'PATCH';
const METHOD_DELETE = 'DELETE';
const METHOD_PURGE = 'PURGE';
const METHOD_OPTIONS = 'OPTIONS';
const METHOD_TRACE = 'TRACE';
const METHOD_TRACE = 'TRACE';
const METHOD_CONNECT = 'CONNECT';
protected static $trustedProxies = array();
@ -726,7 +726,19 @@ class Request
*/
public function get($key, $default = null, $deep = false)
{
return $this->query->get($key, $this->attributes->get($key, $this->request->get($key, $default, $deep), $deep), $deep);
if ($this !== $result = $this->query->get($key, $this, $deep)) {
return $result;
}
if ($this !== $result = $this->attributes->get($key, $this, $deep)) {
return $result;
}
if ($this !== $result = $this->request->get($key, $this, $deep)) {
return $result;
}
return $default;
}
/**

View File

@ -379,7 +379,6 @@ class Response
fastcgi_finish_request();
} elseif ('cli' !== PHP_SAPI) {
static::closeOutputBuffers(0, true);
flush();
}
return $this;

View File

@ -17,7 +17,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
* @see http://php.net/sessionhandler
*/
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
class NativeSessionHandler extends \SessionHandler
{
}

View File

@ -52,17 +52,17 @@ class WriteCheckSessionHandler implements \SessionHandlerInterface
/**
* {@inheritdoc}
*/
public function gc($maxLifetime)
public function gc($maxlifetime)
{
return $this->wrappedSessionHandler->gc($maxLifetime);
return $this->wrappedSessionHandler->gc($maxlifetime);
}
/**
* {@inheritdoc}
*/
public function open($savePath, $sessionId)
public function open($savePath, $sessionName)
{
return $this->wrappedSessionHandler->open($savePath, $sessionId);
return $this->wrappedSessionHandler->open($savePath, $sessionName);
}
/**
@ -80,12 +80,12 @@ class WriteCheckSessionHandler implements \SessionHandlerInterface
/**
* {@inheritdoc}
*/
public function write($sessionId, $sessionData)
public function write($sessionId, $data)
{
if (isset($this->readSessions[$sessionId]) && $sessionData === $this->readSessions[$sessionId]) {
if (isset($this->readSessions[$sessionId]) && $data === $this->readSessions[$sessionId]) {
return true;
}
return $this->wrappedSessionHandler->write($sessionId, $sessionData);
return $this->wrappedSessionHandler->write($sessionId, $data);
}
}

View File

@ -100,7 +100,7 @@ class NativeSessionStorage implements SessionStorageInterface
session_cache_limiter(''); // disable by default because it's managed by HeaderBag (if used)
ini_set('session.use_cookies', 1);
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
session_register_shutdown();
} else {
register_shutdown_function('session_write_close');
@ -130,11 +130,11 @@ class NativeSessionStorage implements SessionStorageInterface
return true;
}
if (version_compare(phpversion(), '5.4.0', '>=') && \PHP_SESSION_ACTIVE === session_status()) {
if (PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status()) {
throw new \RuntimeException('Failed to start the session: already started by PHP.');
}
if (version_compare(phpversion(), '5.4.0', '<') && isset($_SESSION) && session_id()) {
if (PHP_VERSION_ID < 50400 && isset($_SESSION) && session_id()) {
// not 100% fool-proof, but is the most reliable way to determine if a session is active in PHP 5.3
throw new \RuntimeException('Failed to start the session: already started by PHP ($_SESSION is set).');
}
@ -366,13 +366,13 @@ class NativeSessionStorage implements SessionStorageInterface
if (!$saveHandler instanceof AbstractProxy && $saveHandler instanceof \SessionHandlerInterface) {
$saveHandler = new SessionHandlerProxy($saveHandler);
} elseif (!$saveHandler instanceof AbstractProxy) {
$saveHandler = version_compare(phpversion(), '5.4.0', '>=') ?
$saveHandler = PHP_VERSION_ID >= 50400 ?
new SessionHandlerProxy(new \SessionHandler()) : new NativeProxy();
}
$this->saveHandler = $saveHandler;
if ($this->saveHandler instanceof \SessionHandlerInterface) {
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
session_set_save_handler($this->saveHandler, false);
} else {
session_set_save_handler(

View File

@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
/**
* Allows session to be started by PHP and managed by Symfony2
* Allows session to be started by PHP and managed by Symfony
*
* @author Drak <drak@zikula.org>
*/

View File

@ -72,7 +72,7 @@ abstract class AbstractProxy
*/
public function isActive()
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
return $this->active = \PHP_SESSION_ACTIVE === session_status();
}
@ -93,7 +93,7 @@ abstract class AbstractProxy
*/
public function setActive($flag)
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
throw new \LogicException('This method is disabled in PHP 5.4.0+');
}

View File

@ -136,7 +136,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
return array(
array('foo', 'bar', array('foo' => 'bar')),
array('foo.bar', 'too much beer', array('foo.bar' => 'too much beer')),
array('great', 'symfony2 is great', array('great' => 'symfony2 is great')),
array('great', 'symfony is great', array('great' => 'symfony is great')),
);
}
@ -195,7 +195,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
*/
public function testGetIterator()
{
$attributes = array('hello' => 'world', 'symfony2' => 'rocks');
$attributes = array('hello' => 'world', 'symfony' => 'rocks');
foreach ($attributes as $key => $val) {
$this->session->set($key, $val);
}
@ -215,7 +215,7 @@ class SessionTest extends \PHPUnit_Framework_TestCase
public function testGetCount()
{
$this->session->set('hello', 'world');
$this->session->set('symfony2', 'rocks');
$this->session->set('symfony', 'rocks');
$this->assertCount(2, $this->session);
}

View File

@ -103,7 +103,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
public function testWriteWhenUsingExpiresField()
{
$this->options = array(
'id_field' => '_id',
'id_field' => '_id',
'data_field' => 'data',
'time_field' => 'time',
'database' => 'sf2-test',
@ -202,7 +202,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
public function testGcWhenUsingExpiresField()
{
$this->options = array(
'id_field' => '_id',
'id_field' => '_id',
'data_field' => 'data',
'time_field' => 'time',
'database' => 'sf2-test',

View File

@ -27,7 +27,7 @@ class NativeFileSessionHandlerTest extends \PHPUnit_Framework_TestCase
{
$storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir()));
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
$this->assertEquals('files', ini_get('session.save_handler'));
} else {

View File

@ -28,7 +28,7 @@ class NativeSessionHandlerTest extends \PHPUnit_Framework_TestCase
// note for PHPUnit optimisers - the use of assertTrue/False
// here is deliberate since the tests do not require the classes to exist - drak
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->assertFalse($handler instanceof \SessionHandler);
$this->assertTrue($handler instanceof NativeSessionHandler);
} else {

View File

@ -137,7 +137,7 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
$options = array(
'cookie_lifetime' => 123456,
'cookie_path' => '/my/cookie/path',
'cookie_domain' => 'symfony2.example.com',
'cookie_domain' => 'symfony.example.com',
'cookie_secure' => true,
'cookie_httponly' => false,
);
@ -164,7 +164,7 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
public function testSetSaveHandler53()
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.3 only.');
}
@ -186,7 +186,7 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
public function testSetSaveHandler54()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.4 only.');
}
@ -211,7 +211,7 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
*/
public function testStartedOutside53()
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.3 only.');
}
@ -234,7 +234,7 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
*/
public function testCanStartOutside54()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.4 only.');
}

View File

@ -60,7 +60,7 @@ class PhpBridgeSessionStorageTest extends \PHPUnit_Framework_TestCase
public function testPhpSession53()
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.3 only.');
}
@ -84,7 +84,7 @@ class PhpBridgeSessionStorageTest extends \PHPUnit_Framework_TestCase
public function testPhpSession54()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.4 only.');
}

View File

@ -87,7 +87,7 @@ class AbstractProxyTest extends \PHPUnit_Framework_TestCase
public function testIsActivePhp53()
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.3 only.');
}
@ -99,7 +99,7 @@ class AbstractProxyTest extends \PHPUnit_Framework_TestCase
*/
public function testIsActivePhp54()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.4 only.');
}
@ -110,7 +110,7 @@ class AbstractProxyTest extends \PHPUnit_Framework_TestCase
public function testSetActivePhp53()
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.3 only.');
}
@ -126,7 +126,7 @@ class AbstractProxyTest extends \PHPUnit_Framework_TestCase
*/
public function testSetActivePhp54()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.4 only.');
}
@ -149,7 +149,7 @@ class AbstractProxyTest extends \PHPUnit_Framework_TestCase
*/
public function testNameExceptionPhp53()
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.3 only.');
}
@ -163,7 +163,7 @@ class AbstractProxyTest extends \PHPUnit_Framework_TestCase
*/
public function testNameExceptionPhp54()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.4 only.');
}
@ -187,7 +187,7 @@ class AbstractProxyTest extends \PHPUnit_Framework_TestCase
*/
public function testIdExceptionPhp53()
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.3 only.');
}
@ -201,7 +201,7 @@ class AbstractProxyTest extends \PHPUnit_Framework_TestCase
*/
public function testIdExceptionPhp54()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Test skipped, for PHP 5.4 only.');
}

View File

@ -52,7 +52,7 @@ class SessionHandlerProxyTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($this->proxy->isActive());
$this->proxy->open('name', 'id');
if (version_compare(phpversion(), '5.4.0', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->assertTrue($this->proxy->isActive());
} else {
$this->assertFalse($this->proxy->isActive());

View File

@ -155,24 +155,21 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1)
{
$data = fopen('php://memory', 'r+b');
if ('html' === $format) {
$dumper = new HtmlDumper();
$dumper = new HtmlDumper($data);
} else {
throw new \InvalidArgumentException(sprintf('Invalid dump format: %s', $format));
}
$dumps = array();
foreach ($this->data as $dump) {
$data = '';
$dumper->dump(
$dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth),
function ($line, $depth) use (&$data) {
if (-1 !== $depth) {
$data .= str_repeat(' ', $depth).$line."\n";
}
}
);
$dump['data'] = $data;
$dumper->dump($dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth));
rewind($data);
$dump['data'] = stream_get_contents($data);
ftruncate($data, 0);
rewind($data);
$dumps[] = $dump;
}

View File

@ -147,6 +147,14 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
'file' => $r->getFilename(),
'line' => $r->getStartLine(),
);
} elseif (is_object($controller)) {
$r = new \ReflectionClass($controller);
$this->data['controller'] = array(
'class' => $r->getName(),
'method' => null,
'file' => $r->getFileName(),
'line' => $r->getStartLine(),
);
} else {
$this->data['controller'] = (string) $controller ?: 'n/a';
}

View File

@ -11,9 +11,10 @@
namespace Symfony\Component\HttpKernel\EventListener;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
use Symfony\Component\VarDumper\VarDumper;
/**
@ -27,30 +28,23 @@ class DumpListener implements EventSubscriberInterface
private $dumper;
/**
* @param ContainerInterface $container Service container, for lazy loading.
* @param string $dumper var_dumper dumper service to use.
* @param ClonerInterface $cloner Cloner service.
* @param DataDumperInterface $dumper Dumper service.
*/
public function __construct(ContainerInterface $container, $dumper)
public function __construct(ClonerInterface $cloner, DataDumperInterface $dumper)
{
$this->container = $container;
$this->cloner = $cloner;
$this->dumper = $dumper;
}
public function configure()
{
if ($this->container) {
$container = $this->container;
$dumper = $this->dumper;
$this->container = null;
$cloner = $this->cloner;
$dumper = $this->dumper;
VarDumper::setHandler(function ($var) use ($container, $dumper) {
$dumper = $container->get($dumper);
$cloner = $container->get('var_dumper.cloner');
$handler = function ($var) use ($dumper, $cloner) {$dumper->dump($cloner->cloneVar($var));};
VarDumper::setHandler($handler);
$handler($var);
});
}
VarDumper::setHandler(function ($var) use ($cloner, $dumper) {
$dumper->dump($cloner->cloneVar($var));
});
}
public static function getSubscribedEvents()

View File

@ -47,7 +47,7 @@ class SaveSessionListener implements EventSubscriberInterface
{
public function onKernelResponse(FilterResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
if (!$event->isMasterRequest()) {
return;
}

View File

@ -11,10 +11,6 @@
namespace Symfony\Component\HttpKernel\Fragment;
if (!defined('ENT_SUBSTITUTE')) {
define('ENT_SUBSTITUTE', 8);
}
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Templating\EngineInterface;
@ -111,11 +107,16 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
}
$renderedAttributes = '';
if (count($attributes) > 0) {
if (PHP_VERSION_ID >= 50400) {
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
} else {
$flags = ENT_QUOTES;
}
foreach ($attributes as $attribute => $value) {
$renderedAttributes .= sprintf(
' %s="%s"',
htmlspecialchars($attribute, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset, false),
htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset, false)
htmlspecialchars($attribute, $flags, $this->charset, false),
htmlspecialchars($value, $flags, $this->charset, false)
);
}
}

View File

@ -59,12 +59,12 @@ abstract class Kernel implements KernelInterface, TerminableInterface
protected $startTime;
protected $loadClassCache;
const VERSION = '2.6.0-BETA1';
const VERSION = '2.6.0';
const VERSION_ID = '20600';
const MAJOR_VERSION = '2.6.0-BETA1';
const MINOR_VERSION = '2.6.0-BETA1';
const RELEASE_VERSION = '2.6.0-BETA1';
const EXTRA_VERSION = 'BETA1';
const MAJOR_VERSION = '2';
const MINOR_VERSION = '6';
const RELEASE_VERSION = '0';
const EXTRA_VERSION = '';
/**
* Constructor.

View File

@ -29,6 +29,8 @@ final class KernelEvents
* receives a Symfony\Component\HttpKernel\Event\GetResponseEvent
* instance.
*
* @Event
*
* @var string
*
* @api
@ -43,6 +45,8 @@ final class KernelEvents
* a Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
* instance.
*
* @Event
*
* @var string
*
* @api
@ -58,6 +62,8 @@ final class KernelEvents
* Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent
* instance.
*
* @Event
*
* @var string
*
* @api
@ -72,6 +78,8 @@ final class KernelEvents
* request. The event listener method receives a
* Symfony\Component\HttpKernel\Event\FilterControllerEvent instance.
*
* @Event
*
* @var string
*
* @api
@ -86,6 +94,8 @@ final class KernelEvents
* replied. The event listener method receives a
* Symfony\Component\HttpKernel\Event\FilterResponseEvent instance.
*
* @Event
*
* @var string
*
* @api
@ -99,6 +109,8 @@ final class KernelEvents
* The event listener method receives a
* Symfony\Component\HttpKernel\Event\PostResponseEvent instance.
*
* @Event
*
* @var string
*/
const TERMINATE = 'kernel.terminate';

View File

@ -4,7 +4,7 @@ HttpKernel Component
HttpKernel provides the building blocks to create flexible and fast HTTP-based
frameworks.
``HttpKernelInterface`` is the core interface of the Symfony2 full-stack
``HttpKernelInterface`` is the core interface of the Symfony full-stack
framework:
```php
@ -23,11 +23,11 @@ interface HttpKernelInterface
It takes a ``Request`` as an input and should return a ``Response`` as an
output. Using this interface makes your code compatible with all frameworks
using the Symfony2 components. And this will give you many cool features for
using the Symfony components. And this will give you many cool features for
free.
Creating a framework based on the Symfony2 components is really easy. Here is
a very simple, but fully-featured framework based on the Symfony2 components:
Creating a framework based on the Symfony components is really easy. Here is
a very simple, but fully-featured framework based on the Symfony components:
```php
$routes = new RouteCollection();
@ -54,7 +54,7 @@ $kernel = new HttpKernel($dispatcher, $resolver);
$kernel->handle($request)->send();
```
This is all you need to create a flexible framework with the Symfony2
This is all you need to create a flexible framework with the Symfony
components.
Want to add an HTTP reverse proxy and benefit from HTTP caching and Edge Side

View File

@ -181,7 +181,7 @@ class ControllerResolverTest extends \PHPUnit_Framework_TestCase
$request->attributes->set('foobar', 'foobar');
$controller = array(new self(), 'controllerMethod3');
if (version_compare(PHP_VERSION, '5.3.16', '==')) {
if (PHP_VERSION_ID === 50316) {
$this->markTestSkipped('PHP 5.3.16 has a major bug in the Reflection sub-system');
} else {
try {

View File

@ -59,6 +59,7 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
// make sure we always match the line number
$r1 = new \ReflectionMethod($this, 'testControllerInspection');
$r2 = new \ReflectionMethod($this, 'staticControllerMethod');
$r3 = new \ReflectionClass($this);
// test name, callable, expected
$controllerTests = array(
array(
@ -132,6 +133,17 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
'line' => 'n/a',
),
),
array(
'Invokable controller',
$this,
array(
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => null,
'file' => __FILE__,
'line' => $r3->getStartLine(),
),
),
);
$c = new RequestDataCollector();
@ -202,4 +214,9 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
{
throw new \LogicException('Unexpected method call');
}
public function __invoke()
{
throw new \LogicException('Unexpected method call');
}
}

View File

@ -11,10 +11,11 @@
namespace Symfony\Component\HttpKernel\Tests\EventListener;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\HttpKernel\EventListener\DumpListener;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
use Symfony\Component\VarDumper\VarDumper;
/**
@ -34,34 +35,23 @@ class DumpListenerTest extends \PHPUnit_Framework_TestCase
public function testConfigure()
{
$prevDumper = $this->getDumpHandler();
$prevDumper = VarDumper::setHandler('var_dump');
VarDumper::setHandler($prevDumper);
$container = new ContainerBuilder();
$container->setDefinition('var_dumper.cloner', new Definition('Symfony\Component\HttpKernel\Tests\EventListener\MockCloner'));
$container->setDefinition('mock_dumper', new Definition('Symfony\Component\HttpKernel\Tests\EventListener\MockDumper'));
$cloner = new MockCloner();
$dumper = new MockDumper();
ob_start();
$exception = null;
$listener = new DumpListener($container, 'mock_dumper');
$listener = new DumpListener($cloner, $dumper);
try {
$listener->configure();
$lazyDumper = $this->getDumpHandler();
VarDumper::dump('foo');
$loadedDumper = $this->getDumpHandler();
VarDumper::dump('bar');
$this->assertSame('+foo-+bar-', ob_get_clean());
$listenerReflector = new \ReflectionClass($listener);
$lazyReflector = new \ReflectionFunction($lazyDumper);
$loadedReflector = new \ReflectionFunction($loadedDumper);
$this->assertSame($listenerReflector->getFilename(), $lazyReflector->getFilename());
$this->assertSame($listenerReflector->getFilename(), $loadedReflector->getFilename());
$this->assertGreaterThan($lazyReflector->getStartLine(), $loadedReflector->getStartLine());
} catch (\Exception $exception) {
}
@ -71,28 +61,22 @@ class DumpListenerTest extends \PHPUnit_Framework_TestCase
throw $exception;
}
}
private function getDumpHandler()
{
$prevDumper = VarDumper::setHandler('var_dump');
VarDumper::setHandler($prevDumper );
return $prevDumper;
}
}
class MockCloner
class MockCloner implements ClonerInterface
{
public function cloneVar($var)
{
return $var.'-';
return new Data(array($var.'-'));
}
}
class MockDumper
class MockDumper implements DataDumperInterface
{
public function dump($var)
public function dump(Data $data)
{
echo '+'.$var;
$rawData = $data->getRawData();
echo '+'.$rawData[0];
}
}

View File

@ -64,7 +64,7 @@ class Route implements \Serializable
/**
* @var string
*/
private $condition;
private $condition = '';
/**
* Constructor.
@ -84,7 +84,7 @@ class Route implements \Serializable
*
* @api
*/
public function __construct($path, array $defaults = array(), array $requirements = array(), array $options = array(), $host = '', $schemes = array(), $methods = array(), $condition = null)
public function __construct($path, array $defaults = array(), array $requirements = array(), array $options = array(), $host = '', $schemes = array(), $methods = array(), $condition = '')
{
$this->setPath($path);
$this->setDefaults($defaults);

View File

@ -99,7 +99,7 @@ class JsonDecode implements DecoderInterface
$recursionDepth = $context['json_decode_recursion_depth'];
$options = $context['json_decode_options'];
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
if (PHP_VERSION_ID >= 50400) {
$decodedData = json_decode($data, $associative, $recursionDepth, $options);
} else {
$decodedData = json_decode($data, $associative, $recursionDepth);

View File

@ -446,11 +446,11 @@ XML;
protected function getNamespacedArray()
{
return array(
'@xmlns' => 'http://www.w3.org/2005/Atom',
'@xmlns:app' => 'http://www.w3.org/2007/app',
'@xmlns' => 'http://www.w3.org/2005/Atom',
'@xmlns:app' => 'http://www.w3.org/2007/app',
'@xmlns:media' => 'http://search.yahoo.com/mrss/',
'@xmlns:gd' => 'http://schemas.google.com/g/2005',
'@xmlns:yt' => 'http://gdata.youtube.com/schemas/2007',
'@xmlns:gd' => 'http://schemas.google.com/g/2005',
'@xmlns:yt' => 'http://gdata.youtube.com/schemas/2007',
'qux' => "1",
'app:foo' => "foo",
'yt:bar' => array("a", "b"),
@ -469,7 +469,7 @@ XML;
'Barry' => array(
'@size' => 'large',
'FooBar' => array(
'Baz' => 'Ed',
'Baz' => 'Ed',
'@gd:id' => 1,
),
),

View File

@ -35,7 +35,7 @@ class RangeValidator extends ConstraintValidator
if (!is_numeric($value) && !$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$this->buildViolation($constraint->invalidMessage)
->setParameter('{{ value }}', $this->formatValue($value))
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
->setCode(Range::INVALID_VALUE_ERROR)
->addViolation();
@ -61,7 +61,7 @@ class RangeValidator extends ConstraintValidator
if (null !== $constraint->max && $value > $max) {
$this->buildViolation($constraint->maxMessage)
->setParameter('{{ value }}', $value)
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
->setParameter('{{ limit }}', $this->formatValue($max, self::PRETTY_DATE))
->setCode(Range::BEYOND_RANGE_ERROR)
->addViolation();
@ -71,7 +71,7 @@ class RangeValidator extends ConstraintValidator
if (null !== $constraint->min && $value < $min) {
$this->buildViolation($constraint->minMessage)
->setParameter('{{ value }}', $value)
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
->setParameter('{{ limit }}', $this->formatValue($min, self::PRETTY_DATE))
->setCode(Range::BELOW_RANGE_ERROR)
->addViolation();

View File

@ -271,9 +271,9 @@ abstract class FileValidatorTest extends AbstractConstraintValidatorTest
fclose($this->file);
$constraint = new File(array(
'maxSize' => $limit,
'binaryFormat' => $binaryFormat,
'maxSizeMessage' => 'myMessage',
'maxSize' => $limit,
'binaryFormat' => $binaryFormat,
'maxSizeMessage' => 'myMessage',
));
$this->validator->validate($this->getFile($this->path), $constraint);

View File

@ -52,20 +52,20 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
public function getLessThanTen()
{
return array(
array(9.99999),
array('9.99999'),
array(5),
array(1.0),
array(9.99999, '9.99999'),
array('9.99999', '"9.99999"'),
array(5, '5'),
array(1.0, '1.0'),
);
}
public function getMoreThanTwenty()
{
return array(
array(20.000001),
array('20.000001'),
array(21),
array(30.0),
array(20.000001, '20.000001'),
array('20.000001', '"20.000001"'),
array(21, '21'),
array(30.0, '30.0'),
);
}
@ -105,7 +105,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
/**
* @dataProvider getLessThanTen
*/
public function testInvalidValuesMin($value)
public function testInvalidValuesMin($value, $formattedValue)
{
$constraint = new Range(array(
'min' => 10,
@ -115,7 +115,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
$this->validator->validate($value, $constraint);
$this->buildViolation('myMessage')
->setParameter('{{ value }}', $value)
->setParameter('{{ value }}', $formattedValue)
->setParameter('{{ limit }}', 10)
->setCode(Range::BELOW_RANGE_ERROR)
->assertRaised();
@ -124,7 +124,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
/**
* @dataProvider getMoreThanTwenty
*/
public function testInvalidValuesMax($value)
public function testInvalidValuesMax($value, $formattedValue)
{
$constraint = new Range(array(
'max' => 20,
@ -134,7 +134,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
$this->validator->validate($value, $constraint);
$this->buildViolation('myMessage')
->setParameter('{{ value }}', $value)
->setParameter('{{ value }}', $formattedValue)
->setParameter('{{ limit }}', 20)
->setCode(Range::BEYOND_RANGE_ERROR)
->assertRaised();
@ -143,7 +143,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
/**
* @dataProvider getMoreThanTwenty
*/
public function testInvalidValuesCombinedMax($value)
public function testInvalidValuesCombinedMax($value, $formattedValue)
{
$constraint = new Range(array(
'min' => 10,
@ -155,7 +155,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
$this->validator->validate($value, $constraint);
$this->buildViolation('myMaxMessage')
->setParameter('{{ value }}', $value)
->setParameter('{{ value }}', $formattedValue)
->setParameter('{{ limit }}', 20)
->setCode(Range::BEYOND_RANGE_ERROR)
->assertRaised();
@ -164,7 +164,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
/**
* @dataProvider getLessThanTen
*/
public function testInvalidValuesCombinedMin($value)
public function testInvalidValuesCombinedMin($value, $formattedValue)
{
$constraint = new Range(array(
'min' => 10,
@ -176,7 +176,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
$this->validator->validate($value, $constraint);
$this->buildViolation('myMinMessage')
->setParameter('{{ value }}', $value)
->setParameter('{{ value }}', $formattedValue)
->setParameter('{{ limit }}', 10)
->setCode(Range::BELOW_RANGE_ERROR)
->assertRaised();
@ -212,13 +212,13 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
$this->setDefaultTimezone('UTC');
$tests = array(
array(new \DateTime('March 20, 2013')),
array(new \DateTime('March 9, 2014')),
array(new \DateTime('March 20, 2013'), 'Mar 20, 2013, 12:00 AM'),
array(new \DateTime('March 9, 2014'), 'Mar 9, 2014, 12:00 AM'),
);
if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) {
$tests[] = array(new \DateTimeImmutable('March 20, 2013'));
$tests[] = array(new \DateTimeImmutable('March 9, 2014'));
$tests[] = array(new \DateTimeImmutable('March 20, 2013'), 'Mar 20, 2013, 12:00 AM');
$tests[] = array(new \DateTimeImmutable('March 9, 2014'), 'Mar 9, 2014, 12:00 AM');
}
$this->restoreDefaultTimezone();
@ -233,13 +233,13 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
$this->setDefaultTimezone('UTC');
$tests = array(
array(new \DateTime('March 21, 2014')),
array(new \DateTime('March 9, 2015')),
array(new \DateTime('March 21, 2014'), 'Mar 21, 2014, 12:00 AM'),
array(new \DateTime('March 9, 2015'), 'Mar 9, 2015, 12:00 AM'),
);
if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) {
$tests[] = array(new \DateTimeImmutable('March 21, 2014'));
$tests[] = array(new \DateTimeImmutable('March 9, 2015'));
$tests[] = array(new \DateTimeImmutable('March 21, 2014'), 'Mar 21, 2014, 12:00 AM');
$tests[] = array(new \DateTimeImmutable('March 9, 2015'), 'Mar 9, 2015, 12:00 AM');
}
$this->restoreDefaultTimezone();
@ -283,7 +283,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
/**
* @dataProvider getSoonerThanTenthMarch2014
*/
public function testInvalidDatesMin($value)
public function testInvalidDatesMin($value, $dateTimeAsString)
{
// Conversion of dates to string differs between ICU versions
// Make sure we have the correct version loaded
@ -297,7 +297,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
$this->validator->validate($value, $constraint);
$this->buildViolation('myMessage')
->setParameter('{{ value }}', $value)
->setParameter('{{ value }}', $dateTimeAsString)
->setParameter('{{ limit }}', 'Mar 10, 2014, 12:00 AM')
->setCode(Range::BELOW_RANGE_ERROR)
->assertRaised();
@ -306,7 +306,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
/**
* @dataProvider getLaterThanTwentiethMarch2014
*/
public function testInvalidDatesMax($value)
public function testInvalidDatesMax($value, $dateTimeAsString)
{
// Conversion of dates to string differs between ICU versions
// Make sure we have the correct version loaded
@ -320,7 +320,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
$this->validator->validate($value, $constraint);
$this->buildViolation('myMessage')
->setParameter('{{ value }}', $value)
->setParameter('{{ value }}', $dateTimeAsString)
->setParameter('{{ limit }}', 'Mar 20, 2014, 12:00 AM')
->setCode(Range::BEYOND_RANGE_ERROR)
->assertRaised();
@ -329,7 +329,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
/**
* @dataProvider getLaterThanTwentiethMarch2014
*/
public function testInvalidDatesCombinedMax($value)
public function testInvalidDatesCombinedMax($value, $dateTimeAsString)
{
// Conversion of dates to string differs between ICU versions
// Make sure we have the correct version loaded
@ -345,7 +345,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
$this->validator->validate($value, $constraint);
$this->buildViolation('myMaxMessage')
->setParameter('{{ value }}', $value)
->setParameter('{{ value }}', $dateTimeAsString)
->setParameter('{{ limit }}', 'Mar 20, 2014, 12:00 AM')
->setCode(Range::BEYOND_RANGE_ERROR)
->assertRaised();
@ -354,7 +354,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
/**
* @dataProvider getSoonerThanTenthMarch2014
*/
public function testInvalidDatesCombinedMin($value)
public function testInvalidDatesCombinedMin($value, $dateTimeAsString)
{
// Conversion of dates to string differs between ICU versions
// Make sure we have the correct version loaded
@ -370,7 +370,7 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
$this->validator->validate($value, $constraint);
$this->buildViolation('myMinMessage')
->setParameter('{{ value }}', $value)
->setParameter('{{ value }}', $dateTimeAsString)
->setParameter('{{ limit }}', 'Mar 10, 2014, 12:00 AM')
->setCode(Range::BELOW_RANGE_ERROR)
->assertRaised();

View File

@ -21,7 +21,7 @@ class LegacyValidator2Dot5ApiTest extends Abstract2Dot5ApiTest
{
protected function setUp()
{
if (version_compare(PHP_VERSION, '5.3.9', '<')) {
if (PHP_VERSION_ID < 50309) {
$this->markTestSkipped('Not supported prior to PHP 5.3.9');
}

View File

@ -21,7 +21,7 @@ class LegacyValidatorLegacyApiTest extends AbstractLegacyApiTest
{
protected function setUp()
{
if (version_compare(PHP_VERSION, '5.3.9', '<')) {
if (PHP_VERSION_ID < 50309) {
$this->markTestSkipped('Not supported prior to PHP 5.3.9');
}

View File

@ -112,7 +112,7 @@ class ValidatorBuilderTest extends \PHPUnit_Framework_TestCase
public function testDefaultApiVersion()
{
if (version_compare(PHP_VERSION, '5.3.9', '<')) {
if (PHP_VERSION_ID < 50309) {
// Old implementation on PHP < 5.3.9
$this->assertInstanceOf('Symfony\Component\Validator\Validator', $this->builder->getValidator());
} else {
@ -135,7 +135,7 @@ class ValidatorBuilderTest extends \PHPUnit_Framework_TestCase
public function testSetApiVersion24And25()
{
if (version_compare(PHP_VERSION, '5.3.9', '<')) {
if (PHP_VERSION_ID < 50309) {
$this->markTestSkipped('Not supported prior to PHP 5.3.9');
}

View File

@ -325,7 +325,7 @@ class ValidatorBuilder implements ValidatorBuilderInterface
));
}
if (version_compare(PHP_VERSION, '5.3.9', '<') && $apiVersion === Validation::API_VERSION_2_5_BC) {
if (PHP_VERSION_ID < 50309 && $apiVersion === Validation::API_VERSION_2_5_BC) {
throw new InvalidArgumentException(sprintf(
'The Validator API that is compatible with both Symfony 2.4 '.
'and Symfony 2.5 can only be used on PHP 5.3.9 and higher. '.
@ -385,7 +385,7 @@ class ValidatorBuilder implements ValidatorBuilderInterface
$apiVersion = $this->apiVersion;
if (null === $apiVersion) {
$apiVersion = version_compare(PHP_VERSION, '5.3.9', '<')
$apiVersion = PHP_VERSION_ID < 50309
? Validation::API_VERSION_2_4
: Validation::API_VERSION_2_5_BC;
}

View File

@ -11,11 +11,6 @@
namespace Symfony\Component\Yaml\Exception;
if (!defined('JSON_UNESCAPED_UNICODE')) {
define('JSON_UNESCAPED_SLASHES', 64);
define('JSON_UNESCAPED_UNICODE', 256);
}
/**
* Exception class thrown when an error occurs during parsing.
*
@ -130,7 +125,12 @@ class ParseException extends RuntimeException
}
if (null !== $this->parsedFile) {
$this->message .= sprintf(' in %s', json_encode($this->parsedFile, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
if (PHP_VERSION_ID >= 50400) {
$jsonOptions = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
} else {
$jsonOptions = 0;
}
$this->message .= sprintf(' in %s', json_encode($this->parsedFile, $jsonOptions));
}
if ($this->parsedLine >= 0) {

View File

@ -19,7 +19,7 @@ class ParseExceptionTest extends \PHPUnit_Framework_TestCase
public function testGetMessage()
{
$exception = new ParseException('Error message', 42, 'foo: bar', '/var/www/app/config.yml');
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
$message = 'Error message in "/var/www/app/config.yml" at line 42 (near "foo: bar")';
} else {
$message = 'Error message in "\\/var\\/www\\/app\\/config.yml" at line 42 (near "foo: bar")';
@ -27,4 +27,16 @@ class ParseExceptionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($message, $exception->getMessage());
}
public function testGetMessageWithUnicodeInFilename()
{
$exception = new ParseException('Error message', 42, 'foo: bar', 'äöü.yml');
if (PHP_VERSION_ID >= 50400) {
$message = 'Error message in "äöü.yml" at line 42 (near "foo: bar")';
} else {
$message = 'Error message in "\u00e4\u00f6\u00fc.yml" at line 42 (near "foo: bar")';
}
$this->assertEquals($message, $exception->getMessage());
}
}