bug #34562 [DI] Skip unknown method calls for factories in check types pass (fancyweb)
This PR was merged into the 4.4 branch.
Discussion
----------
[DI] Skip unknown method calls for factories in check types pass
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | https://github.com/symfony/symfony/issues/34559
| License | MIT
| Doc PR | -
Ref https://github.com/symfony/symfony/issues/30885 and https://github.com/symfony/symfony/pull/30889.
Commits
-------
592bff88f2
[DI] Skip unknown method calls for factories in check types pass
This commit is contained in:
commit
8378d958e2
@ -49,6 +49,6 @@ class TestBundle extends Bundle
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$container->addCompilerPass(new CheckTypeDeclarationsPass(true, ['http_client', '.debug.http_client']), PassConfig::TYPE_AFTER_REMOVING, -100);
|
$container->addCompilerPass(new CheckTypeDeclarationsPass(true), PassConfig::TYPE_AFTER_REMOVING, -100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
"ext-xml": "*",
|
"ext-xml": "*",
|
||||||
"symfony/cache": "^4.4|^5.0",
|
"symfony/cache": "^4.4|^5.0",
|
||||||
"symfony/config": "^4.3.4|^5.0",
|
"symfony/config": "^4.3.4|^5.0",
|
||||||
"symfony/dependency-injection": "^4.4|^5.0",
|
"symfony/dependency-injection": "^4.4.1|^5.0.1",
|
||||||
"symfony/http-foundation": "^4.4|^5.0",
|
"symfony/http-foundation": "^4.4|^5.0",
|
||||||
"symfony/http-kernel": "^4.4",
|
"symfony/http-kernel": "^4.4",
|
||||||
"symfony/polyfill-mbstring": "~1.0",
|
"symfony/polyfill-mbstring": "~1.0",
|
||||||
|
@ -16,6 +16,7 @@ use Symfony\Component\DependencyInjection\Container;
|
|||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeException;
|
||||||
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
use Symfony\Component\DependencyInjection\Parameter;
|
use Symfony\Component\DependencyInjection\Parameter;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\ServiceLocator;
|
use Symfony\Component\DependencyInjection\ServiceLocator;
|
||||||
@ -37,16 +38,14 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
|
|||||||
private const SCALAR_TYPES = ['int', 'float', 'bool', 'string'];
|
private const SCALAR_TYPES = ['int', 'float', 'bool', 'string'];
|
||||||
|
|
||||||
private $autoload;
|
private $autoload;
|
||||||
private $ignoredServices;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $autoload Whether services who's class in not loaded should be checked or not.
|
* @param bool $autoload Whether services who's class in not loaded should be checked or not.
|
||||||
* Defaults to false to save loading code during compilation.
|
* Defaults to false to save loading code during compilation.
|
||||||
*/
|
*/
|
||||||
public function __construct(bool $autoload = false, array $ignoredServices = [])
|
public function __construct(bool $autoload = false)
|
||||||
{
|
{
|
||||||
$this->autoload = $autoload;
|
$this->autoload = $autoload;
|
||||||
$this->ignoredServices = array_flip($ignoredServices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,7 +53,7 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
|
|||||||
*/
|
*/
|
||||||
protected function processValue($value, $isRoot = false)
|
protected function processValue($value, $isRoot = false)
|
||||||
{
|
{
|
||||||
if (!$value instanceof Definition || isset($this->ignoredServices[$this->currentId])) {
|
if (!$value instanceof Definition || $value->hasErrors()) {
|
||||||
return parent::processValue($value, $isRoot);
|
return parent::processValue($value, $isRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +70,15 @@ final class CheckTypeDeclarationsPass extends AbstractRecursivePass
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($value->getMethodCalls() as $methodCall) {
|
foreach ($value->getMethodCalls() as $methodCall) {
|
||||||
|
try {
|
||||||
$reflectionMethod = $this->getReflectionMethod($value, $methodCall[0]);
|
$reflectionMethod = $this->getReflectionMethod($value, $methodCall[0]);
|
||||||
|
} catch (RuntimeException $e) {
|
||||||
|
if ($value->getFactory()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
$this->checkTypeDeclarations($value, $reflectionMethod, $methodCall[1]);
|
$this->checkTypeDeclarations($value, $reflectionMethod, $methodCall[1]);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user