Commit d822f213 authored by webchick's avatar webchick

Issue #2088651 by pwolanin: Update symfony components to latest 2.3.*.

parent 99670f08
This diff is collapsed.
<?php
// autoload.php generated by Composer
// autoload.php @generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit3a4905090abf2f2252330204ffd02eb8::getLoader();
return ComposerAutoloaderInit0b93b0210b8b39c2a0b13410cd082de9::getLoader();
<?php
// autoload_classmap.php generated by Composer
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname(dirname($vendorDir));
......
<?php
// autoload_files.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname(dirname($vendorDir));
return array(
$vendorDir . '/kriswallsmith/assetic/src/functions.php',
$baseDir . '/core/lib/Drupal.php',
);
\ No newline at end of file
<?php
// autoload_namespaces.php generated by Composer
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname(dirname($vendorDir));
......
<?php
// autoload_real.php generated by Composer
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit3a4905090abf2f2252330204ffd02eb8
class ComposerAutoloaderInit0b93b0210b8b39c2a0b13410cd082de9
{
private static $loader;
......@@ -19,9 +19,9 @@ public static function getLoader()
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit3a4905090abf2f2252330204ffd02eb8', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit0b93b0210b8b39c2a0b13410cd082de9', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit3a4905090abf2f2252330204ffd02eb8', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit0b93b0210b8b39c2a0b13410cd082de9', 'loadClassLoader'));
$vendorDir = dirname(__DIR__);
$baseDir = dirname(dirname($vendorDir));
......@@ -42,8 +42,10 @@ public static function getLoader()
$loader->register(true);
require $vendorDir . '/kriswallsmith/assetic/src/functions.php';
require $baseDir . '/core/lib/Drupal.php';
$includeFiles = require __DIR__ . '/autoload_files.php';
foreach ($includeFiles as $file) {
require $file;
}
return $loader;
}
......
<?php
// include_paths.php generated by Composer
// include_paths.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname(dirname($vendorDir));
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -177,7 +177,7 @@ public function findFile($class)
$classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className).'.php';
foreach ($this->prefixes as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
if ($class === strstr($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($dir.DIRECTORY_SEPARATOR.$classPath)) {
return $dir.DIRECTORY_SEPARATOR.$classPath;
......
......@@ -104,6 +104,7 @@ public function handle($level, $message, $file = 'unknown', $line = 0, $context
$stack = array_map(
function ($row) {
unset($row['args']);
return $row;
},
array_slice(debug_backtrace(false), 0, 10)
......@@ -119,6 +120,11 @@ function ($row) {
}
if ($this->displayErrors && error_reporting() & $level && $this->level & $level) {
// make sure the ContextErrorException class is loaded (https://bugs.php.net/bug.php?id=65322)
if (!class_exists('Symfony\Component\Debug\Exception\ContextErrorException')) {
require __DIR__.'/Exception/ContextErrorException.php';
}
throw new ContextErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line, $context);
}
......
......@@ -19,18 +19,18 @@
class ContextErrorException extends \ErrorException
{
private $context = array();
public function __construct($message, $code, $severity, $filename, $lineno, $context = array())
{
parent::__construct($message, $code, $severity, $filename, $lineno);
$this->context = $context;
}
/**
* @return array Array of variables that existed when the exception occured
*/
public function getContext()
{
return $this->context;
}
}
}
......@@ -20,6 +20,31 @@
*/
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
{
public function testCompileTimeError()
{
// the ContextErrorException must not be loaded for this test to work
if (class_exists('Symfony\Component\Debug\Exception\ContextErrorException', false)) {
$this->markTestSkipped('The ContextErrorException class is already loaded.');
}
$handler = ErrorHandler::register(E_ALL | E_STRICT);
$displayErrors = ini_get('display_errors');
ini_set('display_errors', '1');
try {
// trigger compile time error
eval(<<<'PHP'
class _BaseCompileTimeError { function foo() {} }
class _CompileTimeError extends _BaseCompileTimeError { function foo($invalid) {} }
PHP
);
} catch(\Exception $e) {
// if an exception is thrown, the test passed
}
ini_set('display_errors', $displayErrors);
restore_error_handler();
}
public function testConstruct()
{
......
......@@ -87,6 +87,7 @@ private function resolveDefinition($id, DefinitionDecorator $definition)
$def->setConfigurator($parentDef->getConfigurator());
$def->setFile($parentDef->getFile());
$def->setPublic($parentDef->isPublic());
$def->setLazy($parentDef->isLazy());
// overwrite with values specified in the decorator
$changes = $definition->getChanges();
......@@ -111,6 +112,9 @@ private function resolveDefinition($id, DefinitionDecorator $definition)
if (isset($changes['public'])) {
$def->setPublic($definition->isPublic());
}
if (isset($changes['lazy'])){
$def->setLazy($definition->isLazy());
}
// merge arguments
foreach ($definition->getArguments() as $k => $v) {
......
......@@ -88,6 +88,7 @@ public function __construct(ParameterBagInterface $parameterBag = null)
$this->parameterBag = null === $parameterBag ? new ParameterBag() : $parameterBag;
$this->services = array();
$this->aliases = array();
$this->scopes = array();
$this->scopeChildren = array();
$this->scopedServices = array();
......@@ -183,6 +184,9 @@ public function setParameter($name, $value)
/**
* Sets a service.
*
* Setting a service to null resets the service: has() returns false and get()
* behaves in the same way as if the service was never created.
*
* @param string $id The service identifier
* @param object $service The service instance
* @param string $scope The scope of the service
......@@ -213,6 +217,14 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
if (method_exists($this, $method = 'synchronize'.strtr($id, array('_' => '', '.' => '_')).'Service')) {
$this->$method();
}
if (self::SCOPE_CONTAINER !== $scope && null === $service) {
unset($this->scopedServices[$scope][$id]);
}
if (null === $service) {
unset($this->services[$id]);
}
}
/**
......@@ -228,7 +240,10 @@ public function has($id)
{
$id = strtolower($id);
return array_key_exists($id, $this->services) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service');
return array_key_exists($id, $this->services)
|| array_key_exists($id, $this->aliases)
|| method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service')
;
}
/**
......@@ -509,7 +524,7 @@ public function isScopeActive($name)
*/
public static function camelize($id)
{
return preg_replace_callback('/(^|_|\.)+(.)/', function ($match) { return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); }, $id);
return strtr(ucwords(strtr($id, array('_' => ' ', '.' => '_ '))), array(' ' => ''));
}
/**
......
......@@ -149,6 +149,18 @@ public function setPublic($boolean)
return parent::setPublic($boolean);
}
/**
* {@inheritDoc}
*
* @api
*/
public function setLazy($boolean)
{
$this->changes['lazy'] = true;
return parent::setLazy($boolean);
}
/**
* Gets an argument to pass to the service constructor/factory method.
*
......
......@@ -490,7 +490,6 @@ private function addServiceConfigurator($id, $definition, $variableName = 'insta
*/
private function addService($id, $definition)
{
$name = Container::camelize($id);
$this->definitionVariables = new \SplObjectStorage();
$this->referenceVariables = array();
$this->variableCount = 0;
......@@ -555,7 +554,7 @@ private function addService($id, $definition)
*$lazyInitializationDoc
* $return
*/
{$visibility} function get{$name}Service($lazyInitialization)
{$visibility} function get{$this->camelize($id)}Service($lazyInitialization)
{
EOF;
......@@ -656,14 +655,12 @@ private function addServiceSynchronizer($id, Definition $definition)
return;
}
$name = Container::camelize($id);
return <<<EOF
/**
* Updates the '$id' service.
*/
protected function synchronize{$name}Service()
protected function synchronize{$this->camelize($id)}Service()
{
$code }
......@@ -835,7 +832,7 @@ private function addMethodMap()
$code = " \$this->methodMap = array(\n";
ksort($definitions);
foreach ($definitions as $id => $definition) {
$code .= ' '.var_export($id, true).' => '.var_export('get'.Container::camelize($id).'Service', true).",\n";
$code .= ' '.var_export($id, true).' => '.var_export('get'.$this->camelize($id).'Service', true).",\n";
}
return $code . " );\n";
......@@ -849,7 +846,11 @@ private function addMethodMap()
private function addAliases()
{
if (!$aliases = $this->container->getAliases()) {
return '';
if ($this->container->isFrozen()) {
return "\n \$this->aliases = array();\n";
} else {
return '';
}
}
$code = " \$this->aliases = array(\n";
......@@ -1256,6 +1257,26 @@ private function getServiceCall($id, Reference $reference = null)
}
}
/**
* Convert a service id to a valid PHP method name.
*
* @param string $id
*
* @return string
*
* @throws InvalidArgumentException
*/
private function camelize($id)
{
$name = Container::camelize($id);
if (!preg_match('/^[a-zA-Z0-9_\x7f-\xff]+$/', $name)) {
throw new InvalidArgumentException(sprintf('Service id "%s" cannot be converted to a valid PHP method name.', $id));
}
return $name;
}
/**
* Returns the next name to use
*
......
......@@ -11,7 +11,6 @@
namespace Symfony\Component\DependencyInjection\LazyProxy\PhpDumper;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
/**
......
......@@ -11,7 +11,6 @@
namespace Symfony\Component\DependencyInjection\LazyProxy\PhpDumper;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
/**
......
......@@ -143,6 +143,36 @@ public function testProcessHandlesMultipleInheritance()
$this->assertEquals('foo', $def->getClass());
}
public function testSetLazyOnServiceHasParent()
{
$container = new ContainerBuilder();
$container->register('parent','stdClass');
$container->setDefinition('child1',new DefinitionDecorator('parent'))
->setLazy(true)
;
$this->process($container);
$this->assertTrue($container->getDefinition('child1')->isLazy());
}
public function testSetLazyOnServiceIsParent()
{
$container = new ContainerBuilder();
$container->register('parent','stdClass')
->setLazy(true)
;
$container->setDefinition('child1',new DefinitionDecorator('parent'));
$this->process($container);
$this->assertTrue($container->getDefinition('child1')->isLazy());
}
protected function process(ContainerBuilder $container)
{
$pass = new ResolveDefinitionTemplatesPass();
......
......@@ -31,6 +31,29 @@ public function testConstructor()
$this->assertEquals(array('foo' => 'bar'), $sc->getParameterBag()->all(), '__construct() takes an array of parameters as its first argument');
}
/**
* @dataProvider dataForTestCamelize
*/
public function testCamelize($id, $expected)
{
$this->assertEquals($expected, Container::camelize($id), sprintf('Container::camelize("%s")', $id));
}
public function dataForTestCamelize()
{
return array(
array('foo_bar', 'FooBar'),
array('foo.bar', 'Foo_Bar'),
array('foo.bar_baz', 'Foo_BarBaz'),
array('foo._bar', 'Foo_Bar'),
array('foo_.bar', 'Foo_Bar'),
array('_foo', 'Foo'),
array('.foo', '_Foo'),
array('foo_', 'Foo'),
array('foo.', 'Foo_'),
);
}
/**
* @covers Symfony\Component\DependencyInjection\Container::compile
*/
......@@ -112,6 +135,16 @@ public function testSet()
$this->assertEquals($foo, $sc->get('foo'), '->set() sets a service');
}
/**
* @covers Symfony\Component\DependencyInjection\Container::set
*/
public function testSetWithNullResetTheService()
{
$sc = new Container();
$sc->set('foo', null);
$this->assertFalse($sc->has('foo'));
}
/**
* @expectedException \InvalidArgumentException
*/
......@@ -477,6 +510,14 @@ protected function getField($obj, $field)
return $reflection->getValue($obj);
}
public function testAlias()
{
$c = new ProjectServiceContainer();
$this->assertTrue($c->has('alias'));
$this->assertSame($c->get('alias'), $c->get('bar'));
}
}
class ProjectServiceContainer extends Container
......@@ -490,6 +531,7 @@ public function __construct()
$this->__bar = new \stdClass();
$this->__foo_bar = new \stdClass();
$this->__foo_baz = new \stdClass();
$this->aliases = array('alias' => 'bar');
}
protected function getScopedService()
......
......@@ -61,6 +61,16 @@ public function testSetPublic()
$this->assertEquals(array('public' => true), $def->getChanges());
}
public function testSetLazy()
{
$def = new DefinitionDecorator('foo');
$this->assertFalse($def->isLazy());
$this->assertSame($def, $def->setLazy(false));
$this->assertFalse($def->isLazy());
$this->assertEquals(array('lazy' => true), $def->getChanges());
}
public function testSetArgument()
{
$def = new DefinitionDecorator('foo');
......
......@@ -120,6 +120,18 @@ public function testAddService()
}
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Service id "bar$" cannot be converted to a valid PHP method name.
*/
public function testAddServiceInvalidServiceId()
{
$container = new ContainerBuilder();
$container->register('bar$', 'FooClass');
$dumper = new PhpDumper($container);
$dumper->dump();
}
public function testAliases()
{
$container = include self::$fixturesPath.'/containers/container9.php';
......@@ -134,6 +146,18 @@ public function testAliases()
$this->assertSame($foo, $container->get('alias_for_alias'));
}
public function testFrozenContainerWithoutAliases()
{
$container = new ContainerBuilder();
$container->compile();
$dumper = new PhpDumper($container);
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Frozen_No_Aliases')));
$container = new \Symfony_DI_PhpDumper_Test_Frozen_No_Aliases();
$this->assertFalse($container->has('foo'));
}
public function testOverrideServiceWhenUsingADumpedContainer()
{
require_once self::$fixturesPath.'/php/services9.php';
......
......@@ -36,6 +36,8 @@ public function __construct()
$this->methodMap = array(
'test' => 'getTestService',
);
$this->aliases = array();
}
/**
......
......@@ -50,31 +50,25 @@ public function testIniFileCanBeLoaded()
/**
* @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::__construct
* @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::load
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The file "foo.ini" does not exist (in:
*/
public function testExceptionIsRaisedWhenIniFileDoesNotExist()
{
try {
$this->loader->load('foo.ini');
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
$this->assertStringStartsWith('The file "foo.ini" does not exist (in: ', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
}
$this->loader->load('foo.ini');
}
/**
* @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::__construct
* @covers Symfony\Component\DependencyInjection\Loader\IniFileLoader::load
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The "nonvalid.ini" file is not valid.
*/
public function testExceptionIsRaisedWhenIniFileCannotBeParsed()
{
try {
@$this->loader->load('nonvalid.ini');
$this->fail('->load() throws an InvalidArgumentException if the loaded file is not parseable');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not parseable');
$this->assertEquals('The "nonvalid.ini" file is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not parseable');
}
@$this->loader->load('nonvalid.ini');
}
/**
......
......@@ -37,6 +37,16 @@ class Request
protected static $trustedProxies = array();
/**
* @var string[]
*/
protected static $trustedHostPatterns = array();
/**
* @var string[]
*/
protected static $trustedHosts = array();
/**
* Names for headers that can be trusted when
* using trusted proxies.
......@@ -394,6 +404,10 @@ public function duplicate(array $query = null, array $request = null, array $att
$dup->method = null;
$dup->format = null;
if (!$dup->get('_format')) {
$dup->setRequestFormat($this->getRequestFormat());
}
return $dup;
}
......@@ -486,6 +500,32 @@ public static function getTrustedProxies()
return self::$trustedProxies;
}