fix regression when extending the Container class without a constructor

regression introduced in c026ec63e3 (diff-f7b23d463cba27ac5e4cb677f2be7623R985)
This commit is contained in:
Lukas Kahwe Smith 2018-03-06 12:22:04 +01:00
parent 07cccd53df
commit 0beb64a77c
No known key found for this signature in database
GPG Key ID: D859E62434DF44F7
4 changed files with 12 additions and 4 deletions

View File

@ -981,9 +981,13 @@ EOF;
if ($this->container->isCompiled()) { if ($this->container->isCompiled()) {
if (Container::class !== $baseClassWithNamespace) { if (Container::class !== $baseClassWithNamespace) {
$r = $this->container->getReflectionClass($baseClassWithNamespace, false); $r = $this->container->getReflectionClass($baseClassWithNamespace, false);
if (null !== $r
if (null !== $r && (null !== $constructor = $r->getConstructor()) && 0 === $constructor->getNumberOfRequiredParameters()) { && (null !== $constructor = $r->getConstructor())
$code .= " parent::__construct();\n\n"; && 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; 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() public function __construct()
{ {
parent::__construct(); parent::__construct();
$this->parameterBag = null;
$this->services = array(); $this->services = array();

View File

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