Merge branch '2.5' into 2.6

* 2.5:
  [Form] fixed a maxlength overring on a guessing
  [Debug] Show only unique class candidates
  [SecurityBundle] Firewall providers building - code cleaning
  [Filesystem] symlink use RealPath instead LinkTarget
  [DependencyInjection] Remove duplicate  declaration in PhpDumper
  terminals are not interactive on Travis
  Revert "[DependencyInjection] backport perf optim"
  [WebProfilerBundle] replaced pattern to path attribute in routes definitions.
  fix phpdoc's alignment
  Fixed the AuthenticationProviderInterface alignment
  Fixed the proxy-manager version constraint
  [FrameworkBundle][Template name] avoid  error message for the shortcut notation.
  [DependencyInjection] perf optim: call dirname() at most 5x
  [DependencyInjection] backport perf optim
  Fixed #12845 adding a listener to an event that is currently being dispatched will not result into a fatal error in TraceableEventDispatcher [EventDispatcher]
  [2.5] Remove possible call_user_func()
  [2.3] Remove possible call_user_func()

Conflicts:
	src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
	src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php
	src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php
	src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php
	src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php
	src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php
	src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php
This commit is contained in:
Nicolas Grekas 2014-12-12 17:21:40 +01:00
commit ea17bc78a8
45 changed files with 366 additions and 168 deletions

View File

@ -75,7 +75,7 @@
"monolog/monolog": "~1.11", "monolog/monolog": "~1.11",
"propel/propel1": "~1.6", "propel/propel1": "~1.6",
"ircmaxell/password-compat": "~1.0", "ircmaxell/password-compat": "~1.0",
"ocramius/proxy-manager": ">=0.3.1,<0.6-dev", "ocramius/proxy-manager": "~0.3.1",
"egulias/email-validator": "~1.2" "egulias/email-validator": "~1.2"
}, },
"autoload": { "autoload": {

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=5.3.3", "php": ">=5.3.3",
"symfony/dependency-injection": "~2.3", "symfony/dependency-injection": "~2.3",
"ocramius/proxy-manager": ">=0.3.1,<0.6-dev" "ocramius/proxy-manager": "~0.3.1"
}, },
"require-dev": { "require-dev": {
"symfony/config": "~2.3" "symfony/config": "~2.3"

View File

@ -11,9 +11,9 @@
namespace Symfony\Bundle\FrameworkBundle\Templating; namespace Symfony\Bundle\FrameworkBundle\Templating;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Templating\TemplateReferenceInterface; use Symfony\Component\Templating\TemplateReferenceInterface;
use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Templating\TemplateNameParser as BaseTemplateNameParser;
/** /**
* TemplateNameParser converts template names from the short notation * TemplateNameParser converts template names from the short notation
@ -22,7 +22,7 @@ use Symfony\Component\HttpKernel\KernelInterface;
* *
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class TemplateNameParser implements TemplateNameParserInterface class TemplateNameParser extends BaseTemplateNameParser
{ {
protected $kernel; protected $kernel;
protected $cache = array(); protected $cache = array();
@ -56,7 +56,7 @@ class TemplateNameParser implements TemplateNameParserInterface
} }
if (!preg_match('/^([^:]*):([^:]*):(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) { if (!preg_match('/^([^:]*):([^:]*):(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name)); return parent::parse($name);
} }
$template = new TemplateReference($matches[1], $matches[2], $matches[3], $matches[4], $matches[5]); $template = new TemplateReference($matches[1], $matches[2], $matches[3], $matches[4], $matches[5]);

View File

@ -141,7 +141,7 @@ abstract class KernelTestCase extends \PHPUnit_Framework_TestCase
static::$kernel->boot(); static::$kernel->boot();
} }
/** /**
* Creates a Kernel. * Creates a Kernel.
* *
* Available options: * Available options:

View File

@ -105,7 +105,8 @@ class AppKernel extends Kernel
public function unserialize($str) public function unserialize($str)
{ {
call_user_func_array(array($this, '__construct'), unserialize($str)); $a = unserialize($str);
$this->__construct($a[0], $a[1], $a[2], $a[3]);
} }
protected function getKernelParameters() protected function getKernelParameters()

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser; use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use Symfony\Component\Templating\TemplateReference as BaseTemplateReference;
class TemplateNameParserTest extends TestCase class TemplateNameParserTest extends TestCase
{ {
@ -63,25 +64,17 @@ class TemplateNameParserTest extends TestCase
array(':Post:index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')), array(':Post:index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
array('::index.html.php', new TemplateReference('', '', 'index', 'html', 'php')), array('::index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
array('FooBundle:Post:foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')), array('FooBundle:Post:foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
array('/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
array('name.twig', new BaseTemplateReference('name.twig', 'twig')),
array('name', new BaseTemplateReference('name')),
); );
} }
/** /**
* @dataProvider getInvalidLogicalNameProvider
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
*/ */
public function testParseInvalidName($name) public function testParseValidNameWithNotFoundBundle()
{ {
$this->parser->parse($name); $this->parser->parse('BarBundle:Post:index.html.php');
}
public function getInvalidLogicalNameProvider()
{
return array(
array('BarBundle:Post:index.html.php'),
array('FooBundle:Post:index'),
array('FooBundle:Post'),
array('FooBundle:Post:foo:bar'),
);
} }
} }

View File

@ -513,6 +513,7 @@ class SecurityExtension extends Extension
{ {
$name = $this->getUserProviderId(strtolower($name)); $name = $this->getUserProviderId(strtolower($name));
// Doctrine Entity and In-memory DAO provider are managed by factories
foreach ($this->userProviderFactories as $factory) { foreach ($this->userProviderFactories as $factory) {
$key = str_replace('-', '_', $factory->getKey()); $key = str_replace('-', '_', $factory->getKey());
@ -539,37 +540,12 @@ class SecurityExtension extends Extension
$container $container
->setDefinition($name, new DefinitionDecorator('security.user.provider.chain')) ->setDefinition($name, new DefinitionDecorator('security.user.provider.chain'))
->addArgument($providers) ->addArgument($providers);
;
return $name; return $name;
} }
// Doctrine Entity DAO provider throw new InvalidConfigurationException(sprintf('Unable to create definition for "%s" user provider', $name));
if (isset($provider['entity'])) {
$container
->setDefinition($name, new DefinitionDecorator('security.user.provider.entity'))
->addArgument($provider['entity']['class'])
->addArgument($provider['entity']['property'])
;
return $name;
}
// In-memory DAO provider
$definition = $container->setDefinition($name, new DefinitionDecorator('security.user.provider.in_memory'));
foreach ($provider['users'] as $username => $user) {
$userId = $name.'_'.$username;
$container
->setDefinition($userId, new DefinitionDecorator('security.user.provider.in_memory.user'))
->setArguments(array($username, (string) $user['password'], $user['roles']))
;
$definition->addMethodCall('createUser', array(new Reference($userId)));
}
return $name;
} }
private function getUserProviderId($name) private function getUserProviderId($name)

View File

@ -0,0 +1,25 @@
<?php
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class DummyProvider implements UserProviderFactoryInterface
{
public function create(ContainerBuilder $container, $id, $config)
{
}
public function getKey()
{
return 'foo';
}
public function addConfiguration(NodeDefinition $node)
{
}
}

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection;
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension; use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Fixtures\UserProvider\DummyProvider;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
class SecurityExtensionTest extends \PHPUnit_Framework_TestCase class SecurityExtensionTest extends \PHPUnit_Framework_TestCase
@ -66,6 +67,33 @@ class SecurityExtensionTest extends \PHPUnit_Framework_TestCase
$container->compile(); $container->compile();
} }
/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @expectedExceptionMessage Unable to create definition for "security.user.provider.concrete.my_foo" user provider
*/
public function testFirewallWithInvalidUserProvider()
{
$container = $this->getRawContainer();
$extension = $container->getExtension('security');
$extension->addUserProviderFactory(new DummyProvider());
$container->loadFromExtension('security', array(
'providers' => array(
'my_foo' => array('foo' => []),
),
'firewalls' => array(
'some_firewall' => array(
'pattern' => '/.*',
'http_basic' => [],
),
),
));
$container->compile();
}
protected function getRawContainer() protected function getRawContainer()
{ {
$container = new ContainerBuilder(); $container = new ContainerBuilder();

View File

@ -105,7 +105,8 @@ class AppKernel extends Kernel
public function unserialize($str) public function unserialize($str)
{ {
call_user_func_array(array($this, '__construct'), unserialize($str)); $a = unserialize($str);
$this->__construct($a[0], $a[1], $a[2], $a[3]);
} }
protected function getKernelParameters() protected function getKernelParameters()

View File

@ -4,47 +4,47 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="_profiler_home" pattern="/"> <route id="_profiler_home" path="/">
<default key="_controller">web_profiler.controller.profiler:homeAction</default> <default key="_controller">web_profiler.controller.profiler:homeAction</default>
</route> </route>
<route id="_profiler_search" pattern="/search"> <route id="_profiler_search" path="/search">
<default key="_controller">web_profiler.controller.profiler:searchAction</default> <default key="_controller">web_profiler.controller.profiler:searchAction</default>
</route> </route>
<route id="_profiler_search_bar" pattern="/search_bar"> <route id="_profiler_search_bar" path="/search_bar">
<default key="_controller">web_profiler.controller.profiler:searchBarAction</default> <default key="_controller">web_profiler.controller.profiler:searchBarAction</default>
</route> </route>
<route id="_profiler_purge" pattern="/purge"> <route id="_profiler_purge" path="/purge">
<default key="_controller">web_profiler.controller.profiler:purgeAction</default> <default key="_controller">web_profiler.controller.profiler:purgeAction</default>
</route> </route>
<route id="_profiler_info" pattern="/info/{about}"> <route id="_profiler_info" path="/info/{about}">
<default key="_controller">web_profiler.controller.profiler:infoAction</default> <default key="_controller">web_profiler.controller.profiler:infoAction</default>
</route> </route>
<route id="_profiler_phpinfo" pattern="/phpinfo"> <route id="_profiler_phpinfo" path="/phpinfo">
<default key="_controller">web_profiler.controller.profiler:phpinfoAction</default> <default key="_controller">web_profiler.controller.profiler:phpinfoAction</default>
</route> </route>
<route id="_profiler_search_results" pattern="/{token}/search/results"> <route id="_profiler_search_results" path="/{token}/search/results">
<default key="_controller">web_profiler.controller.profiler:searchResultsAction</default> <default key="_controller">web_profiler.controller.profiler:searchResultsAction</default>
</route> </route>
<route id="_profiler" pattern="/{token}"> <route id="_profiler" path="/{token}">
<default key="_controller">web_profiler.controller.profiler:panelAction</default> <default key="_controller">web_profiler.controller.profiler:panelAction</default>
</route> </route>
<route id="_profiler_router" pattern="/{token}/router"> <route id="_profiler_router" path="/{token}/router">
<default key="_controller">web_profiler.controller.router:panelAction</default> <default key="_controller">web_profiler.controller.router:panelAction</default>
</route> </route>
<route id="_profiler_exception" pattern="/{token}/exception"> <route id="_profiler_exception" path="/{token}/exception">
<default key="_controller">web_profiler.controller.exception:showAction</default> <default key="_controller">web_profiler.controller.exception:showAction</default>
</route> </route>
<route id="_profiler_exception_css" pattern="/{token}/exception.css"> <route id="_profiler_exception_css" path="/{token}/exception.css">
<default key="_controller">web_profiler.controller.exception:cssAction</default> <default key="_controller">web_profiler.controller.exception:cssAction</default>
</route> </route>

View File

@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="_wdt" pattern="/{token}"> <route id="_wdt" path="/{token}">
<default key="_controller">web_profiler.controller.profiler:toolbarAction</default> <default key="_controller">web_profiler.controller.profiler:toolbarAction</default>
</route> </route>
</routes> </routes>

View File

@ -225,8 +225,10 @@ class ExprBuilder
{ {
foreach ($expressions as $k => $expr) { foreach ($expressions as $k => $expr) {
if ($expr instanceof ExprBuilder) { if ($expr instanceof ExprBuilder) {
$expressions[$k] = function ($v) use ($expr) { $if = $expr->ifPart;
return call_user_func($expr->ifPart, $v) ? call_user_func($expr->thenPart, $v) : $v; $then = $expr->thenPart;
$expressions[$k] = function ($v) use ($if, $then) {
return $if($v) ? $then($v) : $v;
}; };
} }
} }

View File

@ -49,7 +49,9 @@ class VariableNode extends BaseNode implements PrototypeNodeInterface
*/ */
public function getDefaultValue() public function getDefaultValue()
{ {
return $this->defaultValue instanceof \Closure ? call_user_func($this->defaultValue) : $this->defaultValue; $v = $this->defaultValue;
return $v instanceof \Closure ? $v() : $v;
} }
/** /**

View File

@ -22,6 +22,6 @@ class FileLoaderImportCircularReferenceException extends FileLoaderLoadException
{ {
$message = sprintf('Circular reference detected in "%s" ("%s" > "%s").', $this->varToString($resources[0]), implode('" > "', $resources), $resources[0]); $message = sprintf('Circular reference detected in "%s" ("%s" > "%s").', $this->varToString($resources[0]), implode('" > "', $resources), $resources[0]);
call_user_func('Exception::__construct', $message, $code, $previous); \Exception::__construct($message, $code, $previous);
} }
} }

View File

@ -994,7 +994,6 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$tester = new ApplicationTester($application); $tester = new ApplicationTester($application);
$tester->run(array('command' => 'help')); $tester->run(array('command' => 'help'));
$this->assertTrue($tester->getInput()->isInteractive());
$this->assertFalse($tester->getInput()->hasParameterOption(array('--no-interaction', '-n'))); $this->assertFalse($tester->getInput()->hasParameterOption(array('--no-interaction', '-n')));
$inputStream = $application->getHelperSet()->get('question')->getInputStream(); $inputStream = $application->getHelperSet()->get('question')->getInputStream();

View File

@ -119,7 +119,7 @@ class ClassNotFoundFatalErrorHandler implements FatalErrorHandlerInterface
} }
} }
return $classes; return array_unique($classes);
} }
/** /**

View File

@ -115,17 +115,19 @@ class PhpDumper extends Dumper
), $options); ), $options);
if (!empty($options['file']) && is_dir($dir = dirname($options['file']))) { if (!empty($options['file']) && is_dir($dir = dirname($options['file']))) {
// Build a regexp where the first two root dirs are mandatory, // Build a regexp where the first root dirs are mandatory,
// but every other sub-dir is optional up to the full path in $dir // but every other sub-dir is optional up to the full path in $dir
// Mandate at least 2 root dirs and not more that 5 optional dirs.
$dir = explode(DIRECTORY_SEPARATOR, realpath($dir)); $dir = explode(DIRECTORY_SEPARATOR, realpath($dir));
$i = count($dir); $i = count($dir);
if (3 <= $i) { if (3 <= $i) {
$regex = ''; $regex = '';
$this->targetDirMaxMatches = $i - 3; $lastOptionalDir = $i > 8 ? $i - 5 : 3;
$this->targetDirMaxMatches = $i - $lastOptionalDir;
while (2 < --$i) { while (--$i >= $lastOptionalDir) {
$regex = sprintf('(%s%s)?', preg_quote(DIRECTORY_SEPARATOR.$dir[$i], '#'), $regex); $regex = sprintf('(%s%s)?', preg_quote(DIRECTORY_SEPARATOR.$dir[$i], '#'), $regex);
} }
@ -824,6 +826,7 @@ $bagClass
class $class extends $baseClass class $class extends $baseClass
{ {
private \$parameters; private \$parameters;
private \$targetDirs = array();
EOF; EOF;
} }
@ -835,7 +838,8 @@ EOF;
*/ */
private function addConstructor() private function addConstructor()
{ {
$parameters = $this->exportParameters($this->container->getParameterBag()->all()); $targetDirs = $this->exportTargetDirs();
$arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null;
$code = <<<EOF $code = <<<EOF
@ -843,10 +847,8 @@ EOF;
* Constructor. * Constructor.
*/ */
public function __construct() public function __construct()
{ {{$targetDirs}
\$this->parameters = $parameters; parent::__construct($arguments);
parent::__construct(new ParameterBag(\$this->parameters));
EOF; EOF;
@ -874,7 +876,7 @@ EOF;
*/ */
private function addFrozenConstructor() private function addFrozenConstructor()
{ {
$parameters = $this->exportParameters($this->container->getParameterBag()->all()); $targetDirs = $this->exportTargetDirs();
$code = <<<EOF $code = <<<EOF
@ -882,11 +884,18 @@ EOF;
* Constructor. * Constructor.
*/ */
public function __construct() public function __construct()
{ {{$targetDirs}
EOF;
if ($this->container->getParameterBag()->all()) {
$code .= "\n \$this->parameters = \$this->getDefaultParameters();\n";
}
$code .= <<<EOF
\$this->services = \$this->services =
\$this->scopedServices = \$this->scopedServices =
\$this->scopeStacks = array(); \$this->scopeStacks = array();
\$this->parameters = $parameters;
\$this->set('service_container', \$this); \$this->set('service_container', \$this);
@ -991,6 +1000,8 @@ EOF;
return ''; return '';
} }
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
$code = ''; $code = '';
if ($this->container->isFrozen()) { if ($this->container->isFrozen()) {
$code .= <<<EOF $code .= <<<EOF
@ -1042,6 +1053,20 @@ EOF;
EOF; EOF;
} }
$code .= <<<EOF
/**
* Gets the default parameters.
*
* @return array An array of the default parameters
*/
protected function getDefaultParameters()
{
return $parameters;
}
EOF;
return $code; return $code;
} }
@ -1474,6 +1499,17 @@ EOF;
return $this->expressionLanguage; return $this->expressionLanguage;
} }
private function exportTargetDirs()
{
return null === $this->targetDirRegex ? '' : <<<EOF
\$dir = __DIR__;
for (\$i = 1; \$i <= {$this->targetDirMaxMatches}; ++\$i) {
\$this->targetDirs[\$i] = \$dir = dirname(\$dir);
}
EOF;
}
private function export($value) private function export($value)
{ {
if (null !== $this->targetDirRegex && is_string($value) && preg_match($this->targetDirRegex, $value, $matches, PREG_OFFSET_CAPTURE)) { if (null !== $this->targetDirRegex && is_string($value) && preg_match($this->targetDirRegex, $value, $matches, PREG_OFFSET_CAPTURE)) {
@ -1482,8 +1518,8 @@ EOF;
$suffix = isset($value[$suffix]) ? '.'.var_export(substr($value, $suffix), true) : ''; $suffix = isset($value[$suffix]) ? '.'.var_export(substr($value, $suffix), true) : '';
$dirname = '__DIR__'; $dirname = '__DIR__';
for ($i = $this->targetDirMaxMatches - count($matches); 0 <= $i; --$i) { if (0 < $offset = 1 + $this->targetDirMaxMatches - count($matches)) {
$dirname = sprintf('dirname(%s)', $dirname); $dirname = sprintf('$this->targetDirs[%d]', $offset);
} }
if ($prefix || $suffix) { if ($prefix || $suffix) {

View File

@ -70,13 +70,14 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
$definition = new Definition(); $definition = new Definition();
$definition->setClass('stdClass'); $definition->setClass('stdClass');
$definition->addArgument('%foo%'); $definition->addArgument('%foo%');
$definition->addArgument(array('%foo%' => '%foo%')); $definition->addArgument(array('%foo%' => '%buz%/'));
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$container->setDefinition('test', $definition); $container->setDefinition('test', $definition);
$container->setParameter('foo', 'wiz'.dirname(dirname(__FILE__))); $container->setParameter('foo', 'wiz'.dirname(dirname(__FILE__)));
$container->setParameter('bar', dirname(__FILE__)); $container->setParameter('bar', dirname(__FILE__));
$container->setParameter('baz', '%bar%/PhpDumperTest.php'); $container->setParameter('baz', '%bar%/PhpDumperTest.php');
$container->setParameter('buz', dirname(dirname(__DIR__)));
$container->compile(); $container->compile();
$dumper = new PhpDumper($container); $dumper = new PhpDumper($container);

View File

@ -18,16 +18,13 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
class Container extends AbstractContainer class Container extends AbstractContainer
{ {
private $parameters; private $parameters;
private $targetDirs = array();
/** /**
* Constructor. * Constructor.
*/ */
public function __construct() public function __construct()
{ {
$this->parameters = array( parent::__construct();
);
parent::__construct(new ParameterBag($this->parameters));
} }
} }

View File

@ -17,16 +17,13 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
class ProjectServiceContainer extends Container class ProjectServiceContainer extends Container
{ {
private $parameters; private $parameters;
private $targetDirs = array();
/** /**
* Constructor. * Constructor.
*/ */
public function __construct() public function __construct()
{ {
$this->parameters = array( parent::__construct();
);
parent::__construct(new ParameterBag($this->parameters));
} }
} }

View File

@ -17,19 +17,18 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
class ProjectServiceContainer extends Container class ProjectServiceContainer extends Container
{ {
private $parameters; private $parameters;
private $targetDirs = array();
/** /**
* Constructor. * Constructor.
*/ */
public function __construct() public function __construct()
{ {
$this->parameters = $this->getDefaultParameters();
$this->services = $this->services =
$this->scopedServices = $this->scopedServices =
$this->scopeStacks = array(); $this->scopeStacks = array();
$this->parameters = array(
'empty_value' => '',
'some_string' => '-',
);
$this->set('service_container', $this); $this->set('service_container', $this);
@ -106,4 +105,17 @@ class ProjectServiceContainer extends Container
return $this->parameterBag; return $this->parameterBag;
} }
/**
* Gets the default parameters.
*
* @return array An array of the default parameters
*/
protected function getDefaultParameters()
{
return array(
'empty_value' => '',
'some_string' => '-',
);
}
} }

View File

@ -17,20 +17,22 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
class ProjectServiceContainer extends Container class ProjectServiceContainer extends Container
{ {
private $parameters; private $parameters;
private $targetDirs = array();
/** /**
* Constructor. * Constructor.
*/ */
public function __construct() public function __construct()
{ {
$dir = __DIR__;
for ($i = 1; $i <= 5; ++$i) {
$this->targetDirs[$i] = $dir = dirname($dir);
}
$this->parameters = $this->getDefaultParameters();
$this->services = $this->services =
$this->scopedServices = $this->scopedServices =
$this->scopeStacks = array(); $this->scopeStacks = array();
$this->parameters = array(
'foo' => ('wiz'.dirname(__DIR__)),
'bar' => __DIR__,
'baz' => (__DIR__.'/PhpDumperTest.php'),
);
$this->set('service_container', $this); $this->set('service_container', $this);
@ -61,7 +63,7 @@ class ProjectServiceContainer extends Container
*/ */
protected function getTestService() protected function getTestService()
{ {
return $this->services['test'] = new \stdClass(('wiz'.dirname(__DIR__)), array(('wiz'.dirname(__DIR__)) => ('wiz'.dirname(__DIR__)))); return $this->services['test'] = new \stdClass(('wiz'.$this->targetDirs[1]), array(('wiz'.$this->targetDirs[1]) => ($this->targetDirs[2].'/')));
} }
/** /**
@ -107,4 +109,19 @@ class ProjectServiceContainer extends Container
return $this->parameterBag; return $this->parameterBag;
} }
/**
* Gets the default parameters.
*
* @return array An array of the default parameters
*/
protected function getDefaultParameters()
{
return array(
'foo' => ('wiz'.$this->targetDirs[1]),
'bar' => __DIR__,
'baz' => (__DIR__.'/PhpDumperTest.php'),
'buz' => $this->targetDirs[2],
);
}
} }

View File

@ -17,17 +17,14 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
class ProjectServiceContainer extends Container class ProjectServiceContainer extends Container
{ {
private $parameters; private $parameters;
private $targetDirs = array();
/** /**
* Constructor. * Constructor.
*/ */
public function __construct() public function __construct()
{ {
$this->parameters = array( parent::__construct();
);
parent::__construct(new ParameterBag($this->parameters));
$this->methodMap = array( $this->methodMap = array(
'service_from_anonymous_factory' => 'getServiceFromAnonymousFactoryService', 'service_from_anonymous_factory' => 'getServiceFromAnonymousFactoryService',
'service_with_method_call_and_factory' => 'getServiceWithMethodCallAndFactoryService', 'service_with_method_call_and_factory' => 'getServiceWithMethodCallAndFactoryService',

View File

@ -17,13 +17,24 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
class ProjectServiceContainer extends Container class ProjectServiceContainer extends Container
{ {
private $parameters; private $parameters;
private $targetDirs = array();
/** /**
* Constructor. * Constructor.
*/ */
public function __construct() public function __construct()
{ {
$this->parameters = array( parent::__construct(new ParameterBag($this->getDefaultParameters()));
}
/**
* Gets the default parameters.
*
* @return array An array of the default parameters
*/
protected function getDefaultParameters()
{
return array(
'foo' => '%baz%', 'foo' => '%baz%',
'baz' => 'bar', 'baz' => 'bar',
'bar' => 'foo is %%foo bar', 'bar' => 'foo is %%foo bar',
@ -39,7 +50,5 @@ class ProjectServiceContainer extends Container
7 => 'null', 7 => 'null',
), ),
); );
parent::__construct(new ParameterBag($this->parameters));
} }
} }

View File

@ -17,19 +17,14 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
class ProjectServiceContainer extends Container class ProjectServiceContainer extends Container
{ {
private $parameters; private $parameters;
private $targetDirs = array();
/** /**
* Constructor. * Constructor.
*/ */
public function __construct() public function __construct()
{ {
$this->parameters = array( parent::__construct(new ParameterBag($this->getDefaultParameters()));
'baz_class' => 'BazClass',
'foo_class' => 'Bar\\FooClass',
'foo' => 'bar',
);
parent::__construct(new ParameterBag($this->parameters));
$this->methodMap = array( $this->methodMap = array(
'bar' => 'getBarService', 'bar' => 'getBarService',
'baz' => 'getBazService', 'baz' => 'getBazService',
@ -392,4 +387,18 @@ class ProjectServiceContainer extends Container
return $instance; return $instance;
} }
/**
* Gets the default parameters.
*
* @return array An array of the default parameters
*/
protected function getDefaultParameters()
{
return array(
'baz_class' => 'BazClass',
'foo_class' => 'Bar\\FooClass',
'foo' => 'bar',
);
}
} }

View File

@ -17,20 +17,18 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
class ProjectServiceContainer extends Container class ProjectServiceContainer extends Container
{ {
private $parameters; private $parameters;
private $targetDirs = array();
/** /**
* Constructor. * Constructor.
*/ */
public function __construct() public function __construct()
{ {
$this->parameters = $this->getDefaultParameters();
$this->services = $this->services =
$this->scopedServices = $this->scopedServices =
$this->scopeStacks = array(); $this->scopeStacks = array();
$this->parameters = array(
'baz_class' => 'BazClass',
'foo_class' => 'Bar\\FooClass',
'foo' => 'bar',
);
$this->set('service_container', $this); $this->set('service_container', $this);
@ -373,4 +371,18 @@ class ProjectServiceContainer extends Container
return $this->parameterBag; return $this->parameterBag;
} }
/**
* Gets the default parameters.
*
* @return array An array of the default parameters
*/
protected function getDefaultParameters()
{
return array(
'baz_class' => 'BazClass',
'foo_class' => 'Bar\\FooClass',
'foo' => 'bar',
);
}
} }

View File

@ -224,6 +224,9 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
{ {
$skipped = false; $skipped = false;
foreach ($this->dispatcher->getListeners($eventName) as $listener) { foreach ($this->dispatcher->getListeners($eventName) as $listener) {
if (!$listener instanceof WrappedListener) { // #12845: a new listener was added during dispatch.
continue;
}
// Unwrap listener // Unwrap listener
$this->dispatcher->removeListener($eventName, $listener); $this->dispatcher->removeListener($eventName, $listener);
$this->dispatcher->addListener($eventName, $listener->getWrappedListener()); $this->dispatcher->addListener($eventName, $listener->getWrappedListener());

View File

@ -87,11 +87,12 @@ class BinaryNode extends Node
if (isset(self::$functions[$operator])) { if (isset(self::$functions[$operator])) {
$right = $this->nodes['right']->evaluate($functions, $values); $right = $this->nodes['right']->evaluate($functions, $values);
if ('not in' == $operator) { if ('not in' === $operator) {
return !call_user_func('in_array', $left, $right); return !in_array($left, $right);
} }
$f = self::$functions[$operator];
return call_user_func(self::$functions[$operator], $left, $right); return $f($left, $right);
} }
switch ($operator) { switch ($operator) {

View File

@ -423,7 +423,7 @@ class Filesystem
} }
} else { } else {
if (is_link($file)) { if (is_link($file)) {
$this->symlink($file->getLinkTarget(), $target); $this->symlink($file->getRealPath(), $target);
} elseif (is_dir($file)) { } elseif (is_dir($file)) {
$this->mkdir($target); $this->mkdir($target);
} elseif (is_file($file)) { } elseif (is_file($file)) {

View File

@ -901,6 +901,31 @@ class FilesystemTest extends FilesystemTestCase
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1')); $this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
} }
public function testMirrorCopiesRelativeLinkedContents()
{
$this->markAsSkippedIfSymlinkIsMissing();
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
$oldPath = getcwd();
mkdir($sourcePath.'nested/', 0777, true);
file_put_contents($sourcePath.'/nested/file1.txt', 'FILE1');
// Note: Create relative symlink
chdir($sourcePath);
symlink('nested', 'link1');
chdir($oldPath);
$targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;
$this->filesystem->mirror($sourcePath, $targetPath);
$this->assertTrue(is_dir($targetPath));
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.DIRECTORY_SEPARATOR.'link1/file1.txt');
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
$this->assertEquals($sourcePath.'nested', readlink($targetPath.DIRECTORY_SEPARATOR.'link1'));
}
/** /**
* @dataProvider providePathsForIsAbsolutePath * @dataProvider providePathsForIsAbsolutePath
*/ */

View File

@ -246,14 +246,14 @@ class Command
*/ */
public function execute() public function execute()
{ {
if (null === $this->errorHandler) { if (null === $errorHandler = $this->errorHandler) {
exec($this->join(), $output); exec($this->join(), $output);
} else { } else {
$process = proc_open($this->join(), array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes); $process = proc_open($this->join(), array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
$output = preg_split('~(\r\n|\r|\n)~', stream_get_contents($pipes[1]), -1, PREG_SPLIT_NO_EMPTY); $output = preg_split('~(\r\n|\r|\n)~', stream_get_contents($pipes[1]), -1, PREG_SPLIT_NO_EMPTY);
if ($error = stream_get_contents($pipes[2])) { if ($error = stream_get_contents($pipes[2])) {
call_user_func($this->errorHandler, $error); $errorHandler($error);
} }
proc_close($process); proc_close($process);

View File

@ -113,11 +113,11 @@ class FormFactory implements FormFactoryInterface
$pattern = $patternGuess ? $patternGuess->getValue() : null; $pattern = $patternGuess ? $patternGuess->getValue() : null;
if (null !== $pattern) { if (null !== $pattern) {
$options = array_merge(array('attr' => array('pattern' => $pattern)), $options); $options = array_replace_recursive(array('attr' => array('pattern' => $pattern)), $options);
} }
if (null !== $maxLength) { if (null !== $maxLength) {
$options = array_merge(array('attr' => array('maxlength' => $maxLength)), $options); $options = array_replace_recursive(array('attr' => array('maxlength' => $maxLength)), $options);
} }
if ($requiredGuess) { if ($requiredGuess) {

View File

@ -504,6 +504,41 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('builderInstance', $this->builder); $this->assertEquals('builderInstance', $this->builder);
} }
public function testCreateBuilderUsesMaxLengthAndPattern()
{
$this->guesser1->expects($this->once())
->method('guessMaxLength')
->with('Application\Author', 'firstName')
->will($this->returnValue(new ValueGuess(
20,
Guess::HIGH_CONFIDENCE
)));
$this->guesser2->expects($this->once())
->method('guessPattern')
->with('Application\Author', 'firstName')
->will($this->returnValue(new ValueGuess(
'.{5,}',
Guess::HIGH_CONFIDENCE
)));
$factory = $this->getMockFactory(array('createNamedBuilder'));
$factory->expects($this->once())
->method('createNamedBuilder')
->with('firstName', 'text', null, array('attr' => array('maxlength' => 20, 'pattern' => '.{5,}', 'class' => 'tinymce')))
->will($this->returnValue('builderInstance'));
$this->builder = $factory->createBuilderForProperty(
'Application\Author',
'firstName',
null,
array('attr' => array('class' => 'tinymce'))
);
$this->assertEquals('builderInstance', $this->builder);
}
public function testCreateBuilderUsesRequiredSettingWithHighestConfidence() public function testCreateBuilderUsesRequiredSettingWithHighestConfidence()
{ {
$this->guesser1->expects($this->once()) $this->guesser1->expects($this->once())

View File

@ -75,6 +75,24 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
$kernel->handle($request); $kernel->handle($request);
} }
public function testAddListenerNested()
{
$called1 = false;
$called2 = false;
$dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
$dispatcher->addListener('my-event', function () use ($dispatcher, &$called1, &$called2) {
$called1 = true;
$dispatcher->addListener('my-event', function () use (&$called2) {
$called2 = true;
});
});
$dispatcher->dispatch('my-event');
$this->assertTrue($called1);
$this->assertFalse($called2);
$dispatcher->dispatch('my-event');
$this->assertTrue($called2);
}
protected function getHttpKernel($dispatcher, $controller) protected function getHttpKernel($dispatcher, $controller)
{ {
$resolver = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface'); $resolver = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface');

View File

@ -72,8 +72,8 @@ class TestHttpKernel extends HttpKernel implements ControllerResolverInterface
$response = new Response($this->body, $this->status, $this->headers); $response = new Response($this->body, $this->status, $this->headers);
if (null !== $this->customizer) { if (null !== $customizer = $this->customizer) {
call_user_func($this->customizer, $request, $response); $customizer($request, $response);
} }
return $response; return $response;

View File

@ -1370,11 +1370,12 @@ class Process
{ {
$result = $this->processPipes->readAndWrite($blocking, $close); $result = $this->processPipes->readAndWrite($blocking, $close);
$callback = $this->callback;
foreach ($result as $type => $data) { foreach ($result as $type => $data) {
if (3 == $type) { if (3 == $type) {
$this->fallbackExitcode = (int) $data; $this->fallbackExitcode = (int) $data;
} else { } else {
call_user_func($this->callback, $type === self::STDOUT ? self::OUT : self::ERR, $data); $callback($type === self::STDOUT ? self::OUT : self::ERR, $data);
} }
} }
} }

View File

@ -865,7 +865,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
{ {
$process = $this->getProcess('php -m'); $process = $this->getProcess('php -m');
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', sprintf('Process must be started before calling %s.', $method)); $this->setExpectedException('Symfony\Component\Process\Exception\LogicException', sprintf('Process must be started before calling %s.', $method));
call_user_func(array($process, $method)); $process->{$method}();
} }
public function provideMethodsThatNeedARunningProcess() public function provideMethodsThatNeedARunningProcess()
@ -887,7 +887,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$process = $this->getProcess('php -r "sleep(1);"'); $process = $this->getProcess('php -r "sleep(1);"');
$process->start(); $process->start();
try { try {
call_user_func(array($process, $method)); $process->{$method}();
$process->stop(0); $process->stop(0);
$this->fail('A LogicException must have been thrown'); $this->fail('A LogicException must have been thrown');
} catch (\Exception $e) { } catch (\Exception $e) {
@ -1013,7 +1013,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$p = $this->getProcess('php -r "usleep(500000);"'); $p = $this->getProcess('php -r "usleep(500000);"');
$p->disableOutput(); $p->disableOutput();
$this->setExpectedException($exception, $exceptionMessage); $this->setExpectedException($exception, $exceptionMessage);
call_user_func(array($p, $startMethod), function () {}); $p->{$startMethod}(function () {});
} }
public function provideStartMethods() public function provideStartMethods()
@ -1034,7 +1034,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$p->disableOutput(); $p->disableOutput();
$p->start(); $p->start();
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Output has been disabled.'); $this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Output has been disabled.');
call_user_func(array($p, $fetchMethod)); $p->{$fetchMethod}();
} }
public function provideOutputFetchingMethods() public function provideOutputFetchingMethods()

View File

@ -505,11 +505,11 @@ class PropertyAccessor implements PropertyAccessorInterface
} }
foreach ($itemToRemove as $item) { foreach ($itemToRemove as $item) {
call_user_func(array($object, $removeMethod), $item); $object->{$removeMethod}($item);
} }
foreach ($itemsToAdd as $item) { foreach ($itemsToAdd as $item) {
call_user_func(array($object, $addMethod), $item); $object->{$addMethod}($item);
} }
} }

View File

@ -37,7 +37,7 @@ class ClosureLoader extends Loader
*/ */
public function load($closure, $type = null) public function load($closure, $type = null)
{ {
return call_user_func($closure); return $closure();
} }
/** /**

View File

@ -24,12 +24,12 @@ use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterfac
*/ */
interface AuthenticationProviderInterface extends AuthenticationManagerInterface interface AuthenticationProviderInterface extends AuthenticationManagerInterface
{ {
/** /**
* Checks whether this provider supports the given token. * Checks whether this provider supports the given token.
* *
* @param TokenInterface $token A TokenInterface instance * @param TokenInterface $token A TokenInterface instance
* *
* @return bool true if the implementation supports the Token, false otherwise * @return bool true if the implementation supports the Token, false otherwise
*/ */
public function supports(TokenInterface $token); public function supports(TokenInterface $token);
} }

View File

@ -129,21 +129,21 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
return $data; return $data;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function supportsEncoding($format) public function supportsEncoding($format)
{ {
return 'xml' === $format; return 'xml' === $format;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function supportsDecoding($format) public function supportsDecoding($format)
{ {
return 'xml' === $format; return 'xml' === $format;
} }
/** /**
* Sets the root node name. * Sets the root node name.

View File

@ -50,7 +50,9 @@ class CallbackValidator extends ConstraintValidator
$methods = $constraint->methods ?: array($constraint->callback); $methods = $constraint->methods ?: array($constraint->callback);
foreach ($methods as $method) { foreach ($methods as $method) {
if (is_array($method) || $method instanceof \Closure) { if ($method instanceof \Closure) {
$method($object, $this->context);
} elseif (is_array($method)) {
if (!is_callable($method)) { if (!is_callable($method)) {
throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Callback constraint is not a valid callable', $method[0], $method[1])); throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Callback constraint is not a valid callable', $method[0], $method[1]));
} }

View File

@ -49,13 +49,12 @@ class ChoiceValidator extends ConstraintValidator
} }
if ($constraint->callback) { if ($constraint->callback) {
if (is_callable(array($this->context->getClassName(), $constraint->callback))) { if (!is_callable($choices = array($this->context->getClassName(), $constraint->callback))
$choices = call_user_func(array($this->context->getClassName(), $constraint->callback)); && !is_callable($choices = $constraint->callback)
} elseif (is_callable($constraint->callback)) { ) {
$choices = call_user_func($constraint->callback);
} else {
throw new ConstraintDefinitionException('The Choice constraint expects a valid callback'); throw new ConstraintDefinitionException('The Choice constraint expects a valid callback');
} }
$choices = call_user_func($choices);
} else { } else {
$choices = $constraint->choices; $choices = $constraint->choices;
} }

View File

@ -40,9 +40,9 @@ class TypeValidator extends ConstraintValidator
$isFunction = 'is_'.$type; $isFunction = 'is_'.$type;
$ctypeFunction = 'ctype_'.$type; $ctypeFunction = 'ctype_'.$type;
if (function_exists($isFunction) && call_user_func($isFunction, $value)) { if (function_exists($isFunction) && $isFunction($value)) {
return; return;
} elseif (function_exists($ctypeFunction) && call_user_func($ctypeFunction, $value)) { } elseif (function_exists($ctypeFunction) && $ctypeFunction($value)) {
return; return;
} elseif ($value instanceof $constraint->type) { } elseif ($value instanceof $constraint->type) {
return; return;