bug #26427 [DependencyInjection] fix regression when extending the Container class without a constructor (lsmith77)

This PR was merged into the 3.4 branch.

Discussion
----------

[DependencyInjection] fix regression when extending the Container class without a constructor

| Q             | A
| ------------- | ---
| Branch?       | 3.4+
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | https://github.com/symfony/symfony/issues/26397
| License       | MIT
| Doc PR        | -

fix regression introduced in c026ec63e3 (diff-f7b23d463cba27ac5e4cb677f2be7623R985)

Commits
-------

0beb64a fix regression when extending the Container class without a constructor
This commit is contained in:
Nicolas Grekas 2018-03-19 17:17:44 +01:00
commit ba2e6edb8a
4 changed files with 12 additions and 4 deletions

View File

@ -981,9 +981,13 @@ EOF;
if ($this->container->isCompiled()) {
if (Container::class !== $baseClassWithNamespace) {
$r = $this->container->getReflectionClass($baseClassWithNamespace, false);
if (null !== $r && (null !== $constructor = $r->getConstructor()) && 0 === $constructor->getNumberOfRequiredParameters()) {
$code .= " parent::__construct();\n\n";
if (null !== $r
&& (null !== $constructor = $r->getConstructor())
&& 0 === $constructor->getNumberOfRequiredParameters()
&& Container::class !== $constructor->getDeclaringClass()->name
) {
$code .= " parent::__construct();\n";
$code .= " \$this->parameterBag = null;\n\n";
}
}

View File

@ -2,6 +2,8 @@
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Container;
class NoConstructorContainer
use Symfony\Component\DependencyInjection\Container;
class NoConstructorContainer extends Container
{
}

View File

@ -24,6 +24,7 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tes
public function __construct()
{
parent::__construct();
$this->parameterBag = null;
$this->services = array();

View File

@ -24,6 +24,7 @@ class ProjectServiceContainer extends \Symfony\Component\DependencyInjection\Tes
public function __construct()
{
parent::__construct();
$this->parameterBag = null;
$this->services = array();