Use AutowireArrayParameterCompilerPass

This commit is contained in:
Tomas Votruba 2018-10-06 12:23:21 +08:00
parent e475b0301b
commit bca4d5eadc
7 changed files with 26 additions and 51 deletions

View File

@ -19,17 +19,17 @@
"symfony/dependency-injection": "^3.4|^4.1",
"symfony/finder": "^3.4|^4.1",
"symfony/process": "^3.4|^4.1",
"symplify/better-phpdoc-parser": "^5.1",
"symplify/easy-coding-standard": "^5.1",
"symplify/package-builder": "^5.1",
"symplify/better-phpdoc-parser": "^5.2",
"symplify/easy-coding-standard": "^5.2",
"symplify/package-builder": "^5.2",
"thecodingmachine/safe": "^0.1.4"
},
"require-dev": {
"humbug/php-scoper": "^0.9.2",
"phpunit/phpunit": "^7.3",
"symplify/changelog-linker": "^5.1",
"symplify/monorepo-builder": "^5.1",
"symplify/phpstan-extensions": "^5.1",
"symplify/changelog-linker": "^5.2",
"symplify/monorepo-builder": "^5.2",
"symplify/phpstan-extensions": "^5.2",
"thecodingmachine/phpstan-safe-rule": "^0.1.0",
"thecodingmachine/phpstan-strict-rules": "^0.10.3",
"tracy/tracy": "^2.5"
@ -216,5 +216,7 @@
"bin": ["bin/rector"],
"config": {
"sort-packages": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}

View File

@ -37,7 +37,8 @@ final class NodeTypeResolver
public function __construct(
TypeToStringResolver $typeToStringResolver,
Broker $broker,
ClassReflectionTypesResolver $classReflectionTypesResolver
ClassReflectionTypesResolver $classReflectionTypesResolver,
array $perNodeTypeResolvers = []
) {
$this->typeToStringResolver = $typeToStringResolver;
$this->broker = $broker;

View File

@ -55,8 +55,6 @@ parameters:
- '#Cannot call method getAttribute\(\) on PhpParser\\Node\\Name\|null#'
- '#Cannot call method getText\(\) on PhpParser\\Comment\\Doc\|null#'
# Error php-parser token
- '#Access to an undefined property PhpParser\\Node\\Expr\\Error\|PhpParser\\Node\\Expr\\Variable::\$name#'

View File

@ -4,6 +4,7 @@ namespace Rector\Console;
use Jean85\PrettyVersions;
use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use function Safe\getcwd;
@ -15,9 +16,14 @@ final class Application extends SymfonyApplication
*/
private const NAME = 'Rector';
public function __construct()
/**
* @param Command[] $commands
*/
public function __construct(array $commands = [])
{
parent::__construct(self::NAME, PrettyVersions::getVersion('rector/rector')->getPrettyVersion());
$this->addCommands($commands);
}
protected function getDefaultInputDefinition(): InputDefinition

View File

@ -1,34 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\DependencyInjection\CompilerPass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
final class AutowireInterfacesCompilerPass implements CompilerPassInterface
{
/**
* @var array|string[]
*/
private $typesToAutowire = [];
/**
* @param string[] $typesToAutowire
*/
public function __construct(array $typesToAutowire)
{
$this->typesToAutowire = $typesToAutowire;
}
public function process(ContainerBuilder $containerBuilder): void
{
foreach ($containerBuilder->getDefinitions() as $definition) {
foreach ($this->typesToAutowire as $typeToAutowire) {
if (is_a((string) $definition->getClass(), $typeToAutowire, true)) {
$definition->setAutowired(true);
continue 2;
}
}
}
}
}

View File

@ -3,7 +3,6 @@
namespace Rector\DependencyInjection;
use Rector\Contract\Rector\PhpRectorInterface;
use Rector\DependencyInjection\CompilerPass\AutowireInterfacesCompilerPass;
use Rector\DependencyInjection\Loader\TolerantRectorYamlFileLoader;
use Rector\FileSystemRector\Contract\FileSystemRectorInterface;
use Rector\YamlRector\Contract\YamlRectorInterface;
@ -16,6 +15,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Config\FileLocator;
use Symfony\Component\HttpKernel\Kernel;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutoBindParametersCompilerPass;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutowireArrayParameterCompilerPass;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutowireInterfacesCompilerPass;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutowireSinglyImplementedCompilerPass;
use Symplify\PackageBuilder\DependencyInjection\CompilerPass\ConfigurableCollectorCompilerPass;
use Symplify\PackageBuilder\HttpKernel\SimpleKernelTrait;
@ -58,6 +59,7 @@ final class RectorKernel extends Kernel
// for defaults
$containerBuilder->addCompilerPass(new AutowireSinglyImplementedCompilerPass());
$containerBuilder->addCompilerPass(new AutowireArrayParameterCompilerPass());
// autowire Rectors by default (mainly for 3rd party code)
$containerBuilder->addCompilerPass(new AutowireInterfacesCompilerPass([

View File

@ -1,9 +1,9 @@
imports:
- { resource: '../../packages/**/src/config/config.yml' }
# new config location
- { resource: '../../packages/**/config/config.yml' }
- { resource: 'services.yml' }
- { resource: 'external-services.yml' }
- { resource: '../../packages/**/src/config/config.yml' }
# new config location
- { resource: '../../packages/**/config/config.yml' }
- { resource: 'services.yml' }
- { resource: 'external-services.yml' }
parameters:
exclude_paths: []