Skip to content

Commit

Permalink
bug #27025 [DI] Add check of internal type to ContainerBuilder::getRe…
Browse files Browse the repository at this point in the history
…flectionClass (upyx)

This PR was submitted for the 4.0 branch but it was merged into the 3.4 branch instead (closes #27025).

Discussion
----------

[DI] Add check of internal type to ContainerBuilder::getReflectionClass

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27018
| License       | MIT
| Doc PR        | no

This PR fixes bug described in #27018 issue.
I think that `getReflectionClass` should return `NULL` when internal type was used instead class name but not throws exception. As well as it does when class is empty. If someone have other opinion we can discuss it.

Commits
-------

314e881 [DI] Add check of internal type to ContainerBuilder::getReflectionClass
  • Loading branch information
stof committed Apr 24, 2018
2 parents ea25fec + 314e881 commit aec5cd0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Expand Up @@ -124,6 +124,20 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
private $removedIds = array();
private $alreadyLoading = array();

private static $internalTypes = array(
'int' => true,
'float' => true,
'string' => true,
'bool' => true,
'resource' => true,
'object' => true,
'array' => true,
'null' => true,
'callable' => true,
'iterable' => true,
'mixed' => true,
);

public function __construct(ParameterBagInterface $parameterBag = null)
{
parent::__construct($parameterBag);
Expand Down Expand Up @@ -341,6 +355,11 @@ public function getReflectionClass($class, $throw = true)
if (!$class = $this->getParameterBag()->resolveValue($class)) {
return;
}

if (isset(self::$internalTypes[$class])) {
return null;
}

$resource = null;

try {
Expand Down
Expand Up @@ -906,6 +906,23 @@ public function testGetReflectionClass()
$this->assertSame('BarMissingClass', (string) end($resources));
}

public function testGetReflectionClassOnInternalTypes()
{
$container = new ContainerBuilder();

$this->assertNull($container->getReflectionClass('int'));
$this->assertNull($container->getReflectionClass('float'));
$this->assertNull($container->getReflectionClass('string'));
$this->assertNull($container->getReflectionClass('bool'));
$this->assertNull($container->getReflectionClass('resource'));
$this->assertNull($container->getReflectionClass('object'));
$this->assertNull($container->getReflectionClass('array'));
$this->assertNull($container->getReflectionClass('null'));
$this->assertNull($container->getReflectionClass('callable'));
$this->assertNull($container->getReflectionClass('iterable'));
$this->assertNull($container->getReflectionClass('mixed'));
}

public function testCompilesClassDefinitionsOfLazyServices()
{
$container = new ContainerBuilder();
Expand Down

0 comments on commit aec5cd0

Please sign in to comment.