Commit 93c75faa authored by alexpott's avatar alexpott

Issue #2377281 by hussainweb: Upgrade to Symfony 2.6 stable

parent 596978a7
This diff is collapsed.
......@@ -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()
......
This diff is collapsed.
......@@ -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 @@ private static function findClasses($path)
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]) {
......
......@@ -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 @@ public function getDifferentOrders()
*/
public function testClassWithTraitsReordering(array $classes)
{
if (version_compare(phpversion(), '5.4', '<')) {
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Requires PHP > 5.4');
return;
......
......@@ -104,7 +104,7 @@ public function getTestCreateMapTests()
)),
);
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',
......
......@@ -487,7 +487,6 @@ public function handleException(\Exception $exception, array $error = null)
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();
......
......@@ -15,10 +15,6 @@
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 @@ public function getContent(FlattenException $exception)
} 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 @@ protected static function utf8Htmlize($str)
$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');
}
/**
......
......@@ -162,21 +162,21 @@ public function testDefaultLogger()
$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()));
......
......@@ -114,6 +114,10 @@ private function processArguments(array $arguments)
$this->processArguments($argument->getArguments());
$this->processArguments($argument->getMethodCalls());
$this->processArguments($argument->getProperties());
if ($argument->getFactoryService()) {
$this->processArguments(array(new Reference($argument->getFactoryService())));
}
}
}
}
......
......@@ -144,6 +144,10 @@ private function isInlineableDefinition(ContainerBuilder $container, $id, Defini
return false;
}
if (count($ids) > 1 && $definition->getFactoryService()) {
return false;
}
return $container->getDefinition(reset($ids))->getScope() === $definition->getScope();
}
}
......@@ -360,6 +360,10 @@ public function initialized($id)
return true;
}
if (isset($this->aliases[$id])) {
$id = $this->aliases[$id];
}
return isset($this->services[$id]) || array_key_exists($id, $this->services);
}
......
......@@ -79,6 +79,28 @@ public function testProcessDetectsReferencesFromInlinedDefinitions()
$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();
......
......@@ -110,6 +110,84 @@ public function testProcessInlinesIfMultipleReferencesButAllFromTheSameDefinitio
$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();
......
......@@ -305,6 +305,10 @@ public function testInitialized()
$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()
......
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
......
......@@ -17,8 +17,14 @@
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();
......
......@@ -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 @@ public static function getHttpMethodParameterOverride()
*/
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;
}
/**
......
......@@ -379,7 +379,6 @@ public function send()
fastcgi_finish_request();
} elseif ('cli' !== PHP_SAPI) {
static::closeOutputBuffers(0, true);
flush();
}
return $this;
......
......@@ -17,7 +17,7 @@
* @see http://php.net/sessionhandler
*/
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (PHP_VERSION_ID >= 50400) {
class NativeSessionHandler extends \SessionHandler
{
}
......
......@@ -52,17 +52,17 @@ public function destroy($sessionId)
/**
* {@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 @@ public function read($sessionId)
/**
* {@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);
}
}
......@@ -100,7 +100,7 @@ public function __construct(array $options = array(), $handler = null, MetadataB
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 @@ public function start()
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 @@ public function setSaveHandler($saveHandler = null)
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(
......
......@@ -15,7 +15,7 @@
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>
*/
......
......@@ -72,7 +72,7 @@ public function isWrapper()
*/
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 @@ public function isActive()
*/
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+');
}
......
......@@ -136,7 +136,7 @@ public function setProvider()
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 @@ public function testGetFlashBag()
*/
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 @@ public function testGetIterator()
public function testGetCount()
{
$this->session->set('hello', 'world');
$this->session->set('symfony2', 'rocks');
$this->session->set('symfony', 'rocks');
$this->assertCount(2, $this->session);
}
......
......@@ -103,7 +103,7 @@ public function testWrite()
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 @@ public function testGc()
public function testGcWhenUsingExpiresField()
{
$this->options = array(
'id_field' => '_id',
'id_field' => '_id',
'data_field' => 'data',
'time_field' => 'time',
'database' => 'sf2-test',
......
......@@ -27,7 +27,7 @@ public function testConstruct()
{
$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 {
......
......@@ -28,7 +28,7 @@ public function testConstruct()
// 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 {
......
......@@ -137,7 +137,7 @@ public function testCookieOptions()
$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 @@ public function testSetSaveHandlerException()
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 @@ public function testSetSaveHandler53()
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 @@ public function testSetSaveHandler54()
*/
public function testStartedOutside53()
{