From fad7aba3babae65ed1e8ee8472c76c8adef59aa3 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 21 Nov 2014 09:49:35 +0100 Subject: [PATCH 1/6] [2.3] Remove possible call_user_func() --- .../FrameworkBundle/Tests/Functional/app/AppKernel.php | 3 ++- .../SecurityBundle/Tests/Functional/app/AppKernel.php | 3 ++- .../Component/Config/Definition/Builder/ExprBuilder.php | 6 ++++-- src/Symfony/Component/Config/Definition/VariableNode.php | 4 +++- .../FileLoaderImportCircularReferenceException.php | 2 +- src/Symfony/Component/Finder/Shell/Command.php | 4 ++-- .../HttpKernel/Tests/HttpCache/TestHttpKernel.php | 4 ++-- src/Symfony/Component/Process/Process.php | 3 ++- .../Component/Process/Tests/AbstractProcessTest.php | 4 ++-- src/Symfony/Component/Routing/Loader/ClosureLoader.php | 2 +- .../Validator/Constraints/CallbackValidator.php | 4 +++- .../Component/Validator/Constraints/ChoiceValidator.php | 9 ++++----- .../Component/Validator/Constraints/TypeValidator.php | 4 ++-- 13 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php index 12747e6dc2..30bfc56a11 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php @@ -105,7 +105,8 @@ class AppKernel extends Kernel 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() diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php index 57816ccef9..dfce6e4a6c 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AppKernel.php @@ -105,7 +105,8 @@ class AppKernel extends Kernel 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() diff --git a/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php b/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php index 7cbddc6cf3..885863bbb6 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php +++ b/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php @@ -225,8 +225,10 @@ class ExprBuilder { foreach ($expressions as $k => $expr) { if ($expr instanceof ExprBuilder) { - $expressions[$k] = function ($v) use ($expr) { - return call_user_func($expr->ifPart, $v) ? call_user_func($expr->thenPart, $v) : $v; + $if = $expr->ifPart; + $then = $expr->thenPart; + $expressions[$k] = function ($v) use ($if, $then) { + return $if($v) ? $then($v) : $v; }; } } diff --git a/src/Symfony/Component/Config/Definition/VariableNode.php b/src/Symfony/Component/Config/Definition/VariableNode.php index 6d89e49df5..a19dd58bf8 100644 --- a/src/Symfony/Component/Config/Definition/VariableNode.php +++ b/src/Symfony/Component/Config/Definition/VariableNode.php @@ -49,7 +49,9 @@ class VariableNode extends BaseNode implements PrototypeNodeInterface */ public function getDefaultValue() { - return $this->defaultValue instanceof \Closure ? call_user_func($this->defaultValue) : $this->defaultValue; + $v = $this->defaultValue; + + return $v instanceof \Closure ? $v() : $v; } /** diff --git a/src/Symfony/Component/Config/Exception/FileLoaderImportCircularReferenceException.php b/src/Symfony/Component/Config/Exception/FileLoaderImportCircularReferenceException.php index b1ad4420dc..6a3b01cfbe 100644 --- a/src/Symfony/Component/Config/Exception/FileLoaderImportCircularReferenceException.php +++ b/src/Symfony/Component/Config/Exception/FileLoaderImportCircularReferenceException.php @@ -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]); - call_user_func('Exception::__construct', $message, $code, $previous); + \Exception::__construct($message, $code, $previous); } } diff --git a/src/Symfony/Component/Finder/Shell/Command.php b/src/Symfony/Component/Finder/Shell/Command.php index de701ab4e8..7fcb303004 100644 --- a/src/Symfony/Component/Finder/Shell/Command.php +++ b/src/Symfony/Component/Finder/Shell/Command.php @@ -248,14 +248,14 @@ class Command */ public function execute() { - if (null === $this->errorHandler) { + if (null === $errorHandler = $this->errorHandler) { exec($this->join(), $output); } else { $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); if ($error = stream_get_contents($pipes[2])) { - call_user_func($this->errorHandler, $error); + $errorHandler($error); } proc_close($process); diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/TestHttpKernel.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/TestHttpKernel.php index cf23d7bf8a..f84d67a0c7 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/TestHttpKernel.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/TestHttpKernel.php @@ -74,8 +74,8 @@ class TestHttpKernel extends HttpKernel implements ControllerResolverInterface $response = new Response($this->body, $this->status, $this->headers); - if (null !== $this->customizer) { - call_user_func($this->customizer, $request, $response); + if (null !== $customizer = $this->customizer) { + $customizer($request, $response); } return $response; diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 908a126ffa..e163ab8665 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1102,11 +1102,12 @@ class Process $result = $this->processPipes->read($blocking); } + $callback = $this->callback; foreach ($result as $type => $data) { if (3 == $type) { $this->fallbackExitcode = (int) $data; } else { - call_user_func($this->callback, $type === self::STDOUT ? self::OUT : self::ERR, $data); + $callback($type === self::STDOUT ? self::OUT : self::ERR, $data); } } } diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index 5689d34067..2a9e9033d1 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -747,7 +747,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase { $process = $this->getProcess('php -m'); $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() @@ -769,7 +769,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $process = $this->getProcess('php -r "sleep(1);"'); $process->start(); try { - call_user_func(array($process, $method)); + $process->{$method}(); $process->stop(0); $this->fail('A LogicException must have been thrown'); } catch (\Exception $e) { diff --git a/src/Symfony/Component/Routing/Loader/ClosureLoader.php b/src/Symfony/Component/Routing/Loader/ClosureLoader.php index 8212c2916d..9edab1e9e3 100644 --- a/src/Symfony/Component/Routing/Loader/ClosureLoader.php +++ b/src/Symfony/Component/Routing/Loader/ClosureLoader.php @@ -37,7 +37,7 @@ class ClosureLoader extends Loader */ public function load($closure, $type = null) { - return call_user_func($closure); + return $closure(); } /** diff --git a/src/Symfony/Component/Validator/Constraints/CallbackValidator.php b/src/Symfony/Component/Validator/Constraints/CallbackValidator.php index ca5a42bca0..32b20e8a50 100644 --- a/src/Symfony/Component/Validator/Constraints/CallbackValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CallbackValidator.php @@ -43,7 +43,9 @@ class CallbackValidator extends ConstraintValidator $methods = $constraint->methods; 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)) { throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Callback constraint is not a valid callable', $method[0], $method[1])); } diff --git a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php index 93f13c75da..0581d7da74 100644 --- a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php @@ -45,13 +45,12 @@ class ChoiceValidator extends ConstraintValidator } if ($constraint->callback) { - if (is_callable(array($this->context->getClassName(), $constraint->callback))) { - $choices = call_user_func(array($this->context->getClassName(), $constraint->callback)); - } elseif (is_callable($constraint->callback)) { - $choices = call_user_func($constraint->callback); - } else { + if (!is_callable($choices = array($this->context->getClassName(), $constraint->callback)) + && !is_callable($choices = $constraint->callback) + ) { throw new ConstraintDefinitionException('The Choice constraint expects a valid callback'); } + $choices = call_user_func($choices); } else { $choices = $constraint->choices; } diff --git a/src/Symfony/Component/Validator/Constraints/TypeValidator.php b/src/Symfony/Component/Validator/Constraints/TypeValidator.php index b89b5cba1d..979df4ec67 100644 --- a/src/Symfony/Component/Validator/Constraints/TypeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TypeValidator.php @@ -35,9 +35,9 @@ class TypeValidator extends ConstraintValidator $isFunction = 'is_'.$type; $ctypeFunction = 'ctype_'.$type; - if (function_exists($isFunction) && call_user_func($isFunction, $value)) { + if (function_exists($isFunction) && $isFunction($value)) { return; - } elseif (function_exists($ctypeFunction) && call_user_func($ctypeFunction, $value)) { + } elseif (function_exists($ctypeFunction) && $ctypeFunction($value)) { return; } elseif ($value instanceof $constraint->type) { return; From c11535bd6bff6d00ac5a0206e1c8d3f508bba8f3 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 3 Dec 2014 10:22:11 +0100 Subject: [PATCH 2/6] [DependencyInjection] backport perf optim Conflicts: src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php --- .../DependencyInjection/Dumper/PhpDumper.php | 36 ++++--------- .../Tests/Dumper/PhpDumperTest.php | 15 ------ .../Tests/Fixtures/php/services1-1.php | 8 ++- .../Tests/Fixtures/php/services1.php | 8 ++- .../Tests/Fixtures/php/services10.php | 20 +++----- .../Tests/Fixtures/php/services11.php | 51 ------------------- .../Tests/Fixtures/php/services12.php | 22 +++----- .../Tests/Fixtures/php/services8.php | 16 ++---- .../Tests/Fixtures/php/services9.php | 24 ++++----- .../Tests/Fixtures/php/services9_compiled.php | 22 +++----- 10 files changed, 58 insertions(+), 164 deletions(-) delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 5e9208e5cf..58b34e39e9 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -764,6 +764,8 @@ $bagClass */ class $class extends $baseClass { + private \$parameters; + EOF; } @@ -774,7 +776,7 @@ EOF; */ private function addConstructor() { - $arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null; + $parameters = $this->exportParameters($this->container->getParameterBag()->all()); $code = <<parameters = $parameters; + + parent::__construct(new ParameterBag(\$this->parameters)); EOF; @@ -811,6 +815,8 @@ EOF; */ private function addFrozenConstructor() { + $parameters = $this->exportParameters($this->container->getParameterBag()->all()); + $code = <<container->getParameterBag()->all()) { - $code .= "\n \$this->parameters = \$this->getDefaultParameters();\n"; - } - - $code .= <<services = \$this->scopedServices = \$this->scopeStacks = array(); + \$this->parameters = $parameters; \$this->set('service_container', \$this); @@ -913,8 +912,6 @@ EOF; return ''; } - $parameters = $this->exportParameters($this->container->getParameterBag()->all()); - $code = ''; if ($this->container->isFrozen()) { $code .= <<parameterBag; } + EOF; } - $code .= <<setResourceTracking(false); - $container->register('foo', 'stdClass'); - - $container->compile(); - - $dumper = new PhpDumper($container); - - $dumpedString = $dumper->dump(); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services11.php', $dumpedString, '->dump() does not add getDefaultParameters() method call if container have no parameters.'); - $this->assertNotRegexp("/function getDefaultParameters\(/", $dumpedString, '->dump() does not add getDefaultParameters() method definition.'); - } - public function testDumpOptimizationString() { $definition = new Definition(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php index 547941eb95..560da91642 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php @@ -16,11 +16,17 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ class Container extends AbstractContainer { + private $parameters; + /** * Constructor. */ public function __construct() { - parent::__construct(); + $this->parameters = array( + + ); + + parent::__construct(new ParameterBag($this->parameters)); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php index 084e7891af..23d367f1f9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php @@ -16,11 +16,17 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ class ProjectServiceContainer extends Container { + private $parameters; + /** * Constructor. */ public function __construct() { - parent::__construct(); + $this->parameters = array( + + ); + + parent::__construct(new ParameterBag($this->parameters)); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php index 37927a6e70..bf64894f58 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php @@ -16,16 +16,20 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; */ class ProjectServiceContainer extends Container { + private $parameters; + /** * Constructor. */ public function __construct() { - $this->parameters = $this->getDefaultParameters(); - $this->services = $this->scopedServices = $this->scopeStacks = array(); + $this->parameters = array( + 'empty_value' => '', + 'some_string' => '-', + ); $this->set('service_container', $this); @@ -94,16 +98,4 @@ class ProjectServiceContainer extends Container return $this->parameterBag; } - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( - 'empty_value' => '', - 'some_string' => '-', - ); - } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php deleted file mode 100644 index 0dcd83845a..0000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php +++ /dev/null @@ -1,51 +0,0 @@ -services = - $this->scopedServices = - $this->scopeStacks = array(); - - $this->set('service_container', $this); - - $this->scopes = array(); - $this->scopeChildren = array(); - $this->methodMap = array( - 'foo' => 'getFooService', - ); - - $this->aliases = array(); - } - - /** - * Gets the 'foo' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance. - */ - protected function getFooService() - { - return $this->services['foo'] = new \stdClass(); - } -} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php index 52d2702afd..1829818dbc 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php @@ -16,16 +16,21 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; */ class ProjectServiceContainer extends Container { + private $parameters; + /** * Constructor. */ public function __construct() { - $this->parameters = $this->getDefaultParameters(); - $this->services = $this->scopedServices = $this->scopeStacks = array(); + $this->parameters = array( + 'foo' => ('wiz'.dirname(__DIR__)), + 'bar' => __DIR__, + 'baz' => (__DIR__.'/PhpDumperTest.php'), + ); $this->set('service_container', $this); @@ -94,17 +99,4 @@ class ProjectServiceContainer extends Container return $this->parameterBag; } - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( - 'foo' => ('wiz'.dirname(__DIR__)), - 'bar' => __DIR__, - 'baz' => (__DIR__.'/PhpDumperTest.php'), - ); - } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php index f922d2000c..a6de38e381 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php @@ -16,22 +16,14 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ class ProjectServiceContainer extends Container { + private $parameters; + /** * Constructor. */ public function __construct() { - parent::__construct(new ParameterBag($this->getDefaultParameters())); - } - - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( + $this->parameters = array( 'foo' => '%baz%', 'baz' => 'bar', 'bar' => 'foo is %%foo bar', @@ -47,5 +39,7 @@ class ProjectServiceContainer extends Container 7 => 'null', ), ); + + parent::__construct(new ParameterBag($this->parameters)); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index a4b42d78ad..90b5476776 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -16,12 +16,20 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ class ProjectServiceContainer extends Container { + private $parameters; + /** * Constructor. */ public function __construct() { - parent::__construct(new ParameterBag($this->getDefaultParameters())); + $this->parameters = array( + 'baz_class' => 'BazClass', + 'foo_class' => 'FooClass', + 'foo' => 'bar', + ); + + parent::__construct(new ParameterBag($this->parameters)); $this->methodMap = array( 'bar' => 'getBarService', 'baz' => 'getBazService', @@ -245,18 +253,4 @@ class ProjectServiceContainer extends Container return $instance; } - - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( - 'baz_class' => 'BazClass', - 'foo_class' => 'FooClass', - 'foo' => 'bar', - ); - } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index b881b5e300..97fe3ad8a0 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -16,16 +16,21 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; */ class ProjectServiceContainer extends Container { + private $parameters; + /** * Constructor. */ public function __construct() { - $this->parameters = $this->getDefaultParameters(); - $this->services = $this->scopedServices = $this->scopeStacks = array(); + $this->parameters = array( + 'baz_class' => 'BazClass', + 'foo_class' => 'FooClass', + 'foo' => 'bar', + ); $this->set('service_container', $this); @@ -272,17 +277,4 @@ class ProjectServiceContainer extends Container 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' => 'FooClass', - 'foo' => 'bar', - ); - } } From fcd8ff9b67fd63159e5e37dd529de38ff73d6431 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 4 Dec 2014 19:27:52 +0100 Subject: [PATCH 3/6] [DependencyInjection] perf optim: call dirname() at most 5x --- .../DependencyInjection/Dumper/PhpDumper.php | 33 ++++++++++++++----- .../Tests/Dumper/PhpDumperTest.php | 3 +- .../Tests/Fixtures/php/services1-1.php | 1 + .../Tests/Fixtures/php/services1.php | 1 + .../Tests/Fixtures/php/services10.php | 1 + .../Tests/Fixtures/php/services12.php | 10 ++++-- .../Tests/Fixtures/php/services8.php | 1 + .../Tests/Fixtures/php/services9.php | 1 + .../Tests/Fixtures/php/services9_compiled.php | 1 + 9 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 58b34e39e9..0c7ac26cb8 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -104,17 +104,19 @@ class PhpDumper extends Dumper ), $options); 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 + // Mandate at least 2 root dirs and not more that 5 optional dirs. $dir = explode(DIRECTORY_SEPARATOR, realpath($dir)); $i = count($dir); if (3 <= $i) { $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); } @@ -765,6 +767,7 @@ $bagClass class $class extends $baseClass { private \$parameters; + private \$targetDirs; EOF; } @@ -777,6 +780,7 @@ EOF; private function addConstructor() { $parameters = $this->exportParameters($this->container->getParameterBag()->all()); + $targetDirs = $this->exportTargetDirs(); $code = <<parameters = $parameters; parent::__construct(new ParameterBag(\$this->parameters)); @@ -816,6 +820,7 @@ EOF; private function addFrozenConstructor() { $parameters = $this->exportParameters($this->container->getParameterBag()->all()); + $targetDirs = $this->exportTargetDirs(); $code = <<services = \$this->scopedServices = \$this->scopeStacks = array(); @@ -1335,16 +1340,28 @@ EOF; } } + private function exportTargetDirs() + { + return null === $this->targetDirRegex ? '' : <<targetDirMaxMatches}; ++\$i) { + \$this->targetDirs[\$i] = \$dir = dirname(\$dir); + } +EOF; + } + private function export($value) { if (null !== $this->targetDirRegex && is_string($value) && preg_match($this->targetDirRegex, $value, $matches, PREG_OFFSET_CAPTURE)) { $prefix = $matches[0][1] ? var_export(substr($value, 0, $matches[0][1]), true).'.' : ''; $suffix = $matches[0][1] + strlen($matches[0][0]); $suffix = isset($value[$suffix]) ? '.'.var_export(substr($value, $suffix), true) : ''; - $dirname = '__DIR__'; - for ($i = $this->targetDirMaxMatches - count($matches); 0 <= $i; --$i) { - $dirname = sprintf('dirname(%s)', $dirname); + if (0 < $dirname = 1 + $this->targetDirMaxMatches - count($matches)) { + $dirname = sprintf('$this->targetDirs[%d]', $dirname); + } else { + $dirname = '__DIR__'; } if ($prefix || $suffix) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index 4eca6aa849..e240376fd2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -70,13 +70,14 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase $definition = new Definition(); $definition->setClass('stdClass'); $definition->addArgument('%foo%'); - $definition->addArgument(array('%foo%' => '%foo%')); + $definition->addArgument(array('%foo%' => '%buz%/')); $container = new ContainerBuilder(); $container->setDefinition('test', $definition); $container->setParameter('foo', 'wiz'.dirname(dirname(__FILE__))); $container->setParameter('bar', dirname(__FILE__)); $container->setParameter('baz', '%bar%/PhpDumperTest.php'); + $container->setParameter('buz', dirname(dirname(__DIR__))); $container->compile(); $dumper = new PhpDumper($container); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php index 560da91642..2834baef42 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php @@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; class Container extends AbstractContainer { private $parameters; + private $targetDirs; /** * Constructor. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php index 23d367f1f9..aa4e70f51e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php @@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; class ProjectServiceContainer extends Container { private $parameters; + private $targetDirs; /** * Constructor. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php index bf64894f58..55196f882a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php @@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; class ProjectServiceContainer extends Container { private $parameters; + private $targetDirs; /** * Constructor. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php index 1829818dbc..f38d7d9eaa 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php @@ -17,19 +17,25 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; class ProjectServiceContainer extends Container { private $parameters; + private $targetDirs; /** * Constructor. */ public function __construct() { + $dir = __DIR__; + for ($i = 1; $i <= 5; ++$i) { + $this->targetDirs[$i] = $dir = dirname($dir); + } $this->services = $this->scopedServices = $this->scopeStacks = array(); $this->parameters = array( - 'foo' => ('wiz'.dirname(__DIR__)), + 'foo' => ('wiz'.$this->targetDirs[1]), 'bar' => __DIR__, 'baz' => (__DIR__.'/PhpDumperTest.php'), + 'buz' => $this->targetDirs[2], ); $this->set('service_container', $this); @@ -53,7 +59,7 @@ class ProjectServiceContainer extends Container */ 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].'/'))); } /** diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php index a6de38e381..558c284e8b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php @@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; class ProjectServiceContainer extends Container { private $parameters; + private $targetDirs; /** * Constructor. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index 90b5476776..c993d96ec7 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; class ProjectServiceContainer extends Container { private $parameters; + private $targetDirs; /** * Constructor. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index 97fe3ad8a0..12a0653c48 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; class ProjectServiceContainer extends Container { private $parameters; + private $targetDirs; /** * Constructor. From 055129c1c2843a73a00d793290e34b73d4fd2235 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Mon, 8 Dec 2014 10:32:45 +0000 Subject: [PATCH 4/6] [FrameworkBundle][Template name] avoid error message for the shortcut notation. --- .../Templating/TemplateNameParser.php | 6 +++--- .../Templating/TemplateNameParserTest.php | 19 ++++++------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php index ef2ae08008..4777fbeadb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php @@ -11,9 +11,9 @@ namespace Symfony\Bundle\FrameworkBundle\Templating; -use Symfony\Component\Templating\TemplateNameParserInterface; use Symfony\Component\Templating\TemplateReferenceInterface; use Symfony\Component\HttpKernel\KernelInterface; +use Symfony\Component\Templating\TemplateNameParser as BaseTemplateNameParser; /** * TemplateNameParser converts template names from the short notation @@ -22,7 +22,7 @@ use Symfony\Component\HttpKernel\KernelInterface; * * @author Fabien Potencier */ -class TemplateNameParser implements TemplateNameParserInterface +class TemplateNameParser extends BaseTemplateNameParser { protected $kernel; protected $cache; @@ -57,7 +57,7 @@ class TemplateNameParser implements TemplateNameParserInterface } 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]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php index 2a1544c91b..ca10c3a8fe 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php @@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser; use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; +use Symfony\Component\Templating\TemplateReference as BaseTemplateReference; class TemplateNameParserTest extends TestCase { @@ -63,25 +64,17 @@ class TemplateNameParserTest extends TestCase array(':Post:index.html.php', new TemplateReference('', 'Post', '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('/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 */ - public function testParseInvalidName($name) + public function testParseValidNameWithNotFoundBundle() { - $this->parser->parse($name); - } - - public function getInvalidLogicalNameProvider() - { - return array( - array('BarBundle:Post:index.html.php'), - array('FooBundle:Post:index'), - array('FooBundle:Post'), - array('FooBundle:Post:foo:bar'), - ); + $this->parser->parse('BarBundle:Post:index.html.php'); } } From 123e054087fc3ee98a3e094277b51d8a09b6d61d Mon Sep 17 00:00:00 2001 From: Hugo Hamon Date: Wed, 10 Dec 2014 08:57:07 +0100 Subject: [PATCH 5/6] [WebProfilerBundle] replaced pattern to path attribute in routes definitions. --- .../Resources/config/routing/profiler.xml | 22 +++++++++---------- .../Resources/config/routing/wdt.xml | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml index 69f934e53f..d9708f9c50 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml @@ -4,47 +4,47 @@ 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"> - + web_profiler.controller.profiler:homeAction - + web_profiler.controller.profiler:searchAction - + web_profiler.controller.profiler:searchBarAction - + web_profiler.controller.profiler:purgeAction - + web_profiler.controller.profiler:infoAction - + web_profiler.controller.profiler:phpinfoAction - + web_profiler.controller.profiler:searchResultsAction - + web_profiler.controller.profiler:panelAction - + web_profiler.controller.router:panelAction - + web_profiler.controller.exception:showAction - + web_profiler.controller.exception:cssAction diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.xml b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.xml index 5f6851c9ff..1027ce42f6 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.xml +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.xml @@ -4,7 +4,7 @@ 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"> - + web_profiler.controller.profiler:toolbarAction From 375f83ece49e616f595a5f2b6bb6880e9c871ebc Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 4 Dec 2014 21:13:58 +0100 Subject: [PATCH 6/6] Revert "[DependencyInjection] backport perf optim" This reverts commit c11535bd6bff6d00ac5a0206e1c8d3f508bba8f3. 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/services10.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 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php --- .../DependencyInjection/Dumper/PhpDumper.php | 42 ++++++++++----- .../Tests/Dumper/PhpDumperTest.php | 15 ++++++ .../Tests/Fixtures/php/services1-1.php | 8 +-- .../Tests/Fixtures/php/services1.php | 8 +-- .../Tests/Fixtures/php/services10.php | 20 +++++-- .../Tests/Fixtures/php/services11.php | 54 +++++++++++++++++++ .../Tests/Fixtures/php/services12.php | 24 ++++++--- .../Tests/Fixtures/php/services8.php | 16 ++++-- .../Tests/Fixtures/php/services9.php | 24 ++++++--- .../Tests/Fixtures/php/services9_compiled.php | 22 +++++--- 10 files changed, 179 insertions(+), 54 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 0c7ac26cb8..f3e5fdb3cf 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -767,7 +767,7 @@ $bagClass class $class extends $baseClass { private \$parameters; - private \$targetDirs; + private \$targetDirs = array(); EOF; } @@ -779,8 +779,8 @@ EOF; */ private function addConstructor() { - $parameters = $this->exportParameters($this->container->getParameterBag()->all()); $targetDirs = $this->exportTargetDirs(); + $arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null; $code = <<parameters = $parameters; - - parent::__construct(new ParameterBag(\$this->parameters)); + parent::__construct($arguments); EOF; @@ -819,7 +817,6 @@ EOF; */ private function addFrozenConstructor() { - $parameters = $this->exportParameters($this->container->getParameterBag()->all()); $targetDirs = $this->exportTargetDirs(); $code = <<container->getParameterBag()->all()) { + $code .= "\n \$this->parameters = \$this->getDefaultParameters();\n"; + } + + $code .= <<services = \$this->scopedServices = \$this->scopeStacks = array(); - \$this->parameters = $parameters; \$this->set('service_container', \$this); @@ -917,6 +921,8 @@ EOF; return ''; } + $parameters = $this->exportParameters($this->container->getParameterBag()->all()); + $code = ''; if ($this->container->isFrozen()) { $code .= <<parameterBag; } - EOF; } + $code .= <<targetDirMaxMatches - count($matches)) { - $dirname = sprintf('$this->targetDirs[%d]', $dirname); - } else { - $dirname = '__DIR__'; + if (0 < $offset = 1 + $this->targetDirMaxMatches - count($matches)) { + $dirname = sprintf('$this->targetDirs[%d]', $offset); } if ($prefix || $suffix) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index e240376fd2..905e600e78 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -37,6 +37,21 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase new PhpDumper($container); } + public function testDumpFrozenContainerWithNoParameter() + { + $container = new ContainerBuilder(); + $container->setResourceTracking(false); + $container->register('foo', 'stdClass'); + + $container->compile(); + + $dumper = new PhpDumper($container); + + $dumpedString = $dumper->dump(); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services11.php', $dumpedString, '->dump() does not add getDefaultParameters() method call if container have no parameters.'); + $this->assertNotRegexp("/function getDefaultParameters\(/", $dumpedString, '->dump() does not add getDefaultParameters() method definition.'); + } + public function testDumpOptimizationString() { $definition = new Definition(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php index 2834baef42..e83498f2c5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php @@ -17,17 +17,13 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; class Container extends AbstractContainer { private $parameters; - private $targetDirs; + private $targetDirs = array(); /** * Constructor. */ public function __construct() { - $this->parameters = array( - - ); - - parent::__construct(new ParameterBag($this->parameters)); + parent::__construct(); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php index aa4e70f51e..90b59ff4eb 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php @@ -17,17 +17,13 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs; + private $targetDirs = array(); /** * Constructor. */ public function __construct() { - $this->parameters = array( - - ); - - parent::__construct(new ParameterBag($this->parameters)); + parent::__construct(); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php index 55196f882a..43a56eec51 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php @@ -17,20 +17,18 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs; + private $targetDirs = array(); /** * Constructor. */ public function __construct() { + $this->parameters = $this->getDefaultParameters(); + $this->services = $this->scopedServices = $this->scopeStacks = array(); - $this->parameters = array( - 'empty_value' => '', - 'some_string' => '-', - ); $this->set('service_container', $this); @@ -99,4 +97,16 @@ class ProjectServiceContainer extends Container return $this->parameterBag; } + /** + * Gets the default parameters. + * + * @return array An array of the default parameters + */ + protected function getDefaultParameters() + { + return array( + 'empty_value' => '', + 'some_string' => '-', + ); + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php new file mode 100644 index 0000000000..23bae47920 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php @@ -0,0 +1,54 @@ +services = + $this->scopedServices = + $this->scopeStacks = array(); + + $this->set('service_container', $this); + + $this->scopes = array(); + $this->scopeChildren = array(); + $this->methodMap = array( + 'foo' => 'getFooService', + ); + + $this->aliases = array(); + } + + /** + * Gets the 'foo' service. + * + * This service is shared. + * This method always returns the same instance of the service. + * + * @return \stdClass A stdClass instance. + */ + protected function getFooService() + { + return $this->services['foo'] = new \stdClass(); + } +} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php index f38d7d9eaa..3081abd6b0 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php @@ -17,7 +17,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs; + private $targetDirs = array(); /** * Constructor. @@ -28,15 +28,11 @@ class ProjectServiceContainer extends Container for ($i = 1; $i <= 5; ++$i) { $this->targetDirs[$i] = $dir = dirname($dir); } + $this->parameters = $this->getDefaultParameters(); + $this->services = $this->scopedServices = $this->scopeStacks = array(); - $this->parameters = array( - 'foo' => ('wiz'.$this->targetDirs[1]), - 'bar' => __DIR__, - 'baz' => (__DIR__.'/PhpDumperTest.php'), - 'buz' => $this->targetDirs[2], - ); $this->set('service_container', $this); @@ -105,4 +101,18 @@ class ProjectServiceContainer extends Container 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], + ); + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php index 558c284e8b..1b86dfc3f8 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php @@ -17,14 +17,24 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs; + private $targetDirs = array(); /** * Constructor. */ 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%', 'baz' => 'bar', 'bar' => 'foo is %%foo bar', @@ -40,7 +50,5 @@ class ProjectServiceContainer extends Container 7 => 'null', ), ); - - parent::__construct(new ParameterBag($this->parameters)); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index c993d96ec7..ecbd626abe 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -17,20 +17,14 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs; + private $targetDirs = array(); /** * Constructor. */ public function __construct() { - $this->parameters = array( - 'baz_class' => 'BazClass', - 'foo_class' => 'FooClass', - 'foo' => 'bar', - ); - - parent::__construct(new ParameterBag($this->parameters)); + parent::__construct(new ParameterBag($this->getDefaultParameters())); $this->methodMap = array( 'bar' => 'getBarService', 'baz' => 'getBazService', @@ -254,4 +248,18 @@ class ProjectServiceContainer extends Container return $instance; } + + /** + * Gets the default parameters. + * + * @return array An array of the default parameters + */ + protected function getDefaultParameters() + { + return array( + 'baz_class' => 'BazClass', + 'foo_class' => 'FooClass', + 'foo' => 'bar', + ); + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index 12a0653c48..2e7e10480b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -17,21 +17,18 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; class ProjectServiceContainer extends Container { private $parameters; - private $targetDirs; + private $targetDirs = array(); /** * Constructor. */ public function __construct() { + $this->parameters = $this->getDefaultParameters(); + $this->services = $this->scopedServices = $this->scopeStacks = array(); - $this->parameters = array( - 'baz_class' => 'BazClass', - 'foo_class' => 'FooClass', - 'foo' => 'bar', - ); $this->set('service_container', $this); @@ -278,4 +275,17 @@ class ProjectServiceContainer extends Container 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' => 'FooClass', + 'foo' => 'bar', + ); + } }