make use of ConfigurableCollector

This commit is contained in:
Tomas Votruba 2018-10-01 12:27:56 +08:00
parent 07913d30ac
commit 02dc77215e
9 changed files with 24 additions and 136 deletions

View File

@ -1,2 +1,9 @@
imports:
- { resource: 'services.yml' }
parameters:
collectors:
-
main_type: 'Rector\FileSystemRector\FileSystemFileProcessor'
collected_type: 'Rector\FileSystemRector\Contract\FileSystemRectorInterface'
add_method: 'addFileSystemRector'

View File

@ -1,33 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\FileSystemRector\DependencyInjection;
use Rector\FileSystemRector\Contract\FileSystemRectorInterface;
use Rector\FileSystemRector\FileSystemFileProcessor;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symplify\PackageBuilder\DependencyInjection\DefinitionCollector;
use Symplify\PackageBuilder\DependencyInjection\DefinitionFinder;
final class FileSystemRectorCollectorCompilerPass implements CompilerPassInterface
{
/**
* @var DefinitionCollector
*/
private $definitionCollector;
public function __construct()
{
$this->definitionCollector = (new DefinitionCollector(new DefinitionFinder()));
}
public function process(ContainerBuilder $containerBuilder): void
{
$this->definitionCollector->loadCollectorWithType(
$containerBuilder,
FileSystemFileProcessor::class,
FileSystemRectorInterface::class,
'addFileSystemRector'
);
}
}

View File

@ -1,33 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\YamlRector\DependencyInjection;
use Rector\YamlRector\Contract\YamlRectorInterface;
use Rector\YamlRector\YamlFileProcessor;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symplify\PackageBuilder\DependencyInjection\DefinitionCollector;
use Symplify\PackageBuilder\DependencyInjection\DefinitionFinder;
final class YamlRectorCollectorCompilerPass implements CompilerPassInterface
{
/**
* @var DefinitionCollector
*/
private $definitionCollector;
public function __construct()
{
$this->definitionCollector = (new DefinitionCollector(new DefinitionFinder()));
}
public function process(ContainerBuilder $containerBuilder): void
{
$this->definitionCollector->loadCollectorWithType(
$containerBuilder,
YamlFileProcessor::class,
YamlRectorInterface::class,
'addYamlRector'
);
}
}

View File

@ -1,2 +1,9 @@
imports:
- { resource: 'services.yml' }
- { resource: 'services.yml' }
parameters:
collectors:
-
main_type: 'Rector\YamlRector\YamlFileProcessor'
collected_type: 'Rector\YamlRector\Contract\YamlRectorInterface'
add_method: 'addYamlRector'

View File

@ -19,7 +19,7 @@ parameters:
# missuse of interface and class
- '#Parameter \#1 (.*?) expects Symfony\\Component\\DependencyInjection\\ContainerBuilder, Symfony\\Component\\DependencyInjection\\ContainerInterface given#' # 2
- '#Method Rector\\Symfony\\Bridge\\DefaultAnalyzedSymfonyApplicationContainer::getContainer\(\) should return Symfony\\Component\\DependencyInjection\\ContainerBuilder but returns Symfony\\Component\\DependencyInjection\\Container#' # 1
- '#Rector\\NodeTypeResolver\\DependencyInjection\\NodeTypeResolverContainerFactory::(.*?)\(\) should return Psr\\Container\\ContainerInterface but returns Symfony\\Component\\DependencyInjection\\ContainerInterface\|null#'
- '#(.*?)\(\) should return Psr\\Container\\ContainerInterface but returns Symfony\\Component\\DependencyInjection\\ContainerInterface\|null#'
# 0.10.2
# false positives & ->toString() methods

View File

@ -1,46 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\DependencyInjection\CompilerPass;
use Rector\Contract\Rector\PhpRectorInterface;
use Rector\NodeTraverser\RectorNodeTraverser;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symplify\PackageBuilder\DependencyInjection\DefinitionCollector;
use Symplify\PackageBuilder\DependencyInjection\DefinitionFinder;
final class CollectorCompilerPass implements CompilerPassInterface
{
/**
* @var DefinitionCollector
*/
private $definitionCollector;
public function __construct()
{
$this->definitionCollector = new DefinitionCollector(new DefinitionFinder());
}
public function process(ContainerBuilder $containerBuilder): void
{
$this->collectCommandsToConsoleApplication($containerBuilder);
$this->collectRectorsToMainNodeTraverser($containerBuilder);
}
private function collectCommandsToConsoleApplication(ContainerBuilder $containerBuilder): void
{
$this->definitionCollector->loadCollectorWithType($containerBuilder, Application::class, Command::class, 'add');
}
private function collectRectorsToMainNodeTraverser(ContainerBuilder $containerBuilder): void
{
$this->definitionCollector->loadCollectorWithType(
$containerBuilder,
RectorNodeTraverser::class,
PhpRectorInterface::class,
'addRector'
);
}
}

View File

@ -1,15 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\DependencyInjection\CompilerPass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
final class CollectorConfigCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $containerBuilder): void
{
// @todo
// configure collector via params
}
}

View File

@ -4,11 +4,8 @@ namespace Rector\DependencyInjection;
use Rector\Contract\Rector\PhpRectorInterface;
use Rector\DependencyInjection\CompilerPass\AutowireInterfacesCompilerPass;
use Rector\DependencyInjection\CompilerPass\CollectorCompilerPass;
use Rector\FileSystemRector\Contract\FileSystemRectorInterface;
use Rector\FileSystemRector\DependencyInjection\FileSystemRectorCollectorCompilerPass;
use Rector\YamlRector\Contract\YamlRectorInterface;
use Rector\YamlRector\DependencyInjection\YamlRectorCollectorCompilerPass;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Symfony\Component\Config\Loader\GlobFileLoader;
use Symfony\Component\Config\Loader\LoaderInterface;
@ -73,9 +70,7 @@ final class RectorKernel extends Kernel
protected function build(ContainerBuilder $containerBuilder): void
{
// collect all Rector services to its runners
$containerBuilder->addCompilerPass(new CollectorCompilerPass());
$containerBuilder->addCompilerPass(new YamlRectorCollectorCompilerPass());
$containerBuilder->addCompilerPass(new FileSystemRectorCollectorCompilerPass());
$containerBuilder->addCompilerPass(new ConfigurableCollectorCompilerPass());
// for defaults
$containerBuilder->addCompilerPass(new AutowireSinglyImplementedCompilerPass());
@ -88,7 +83,6 @@ final class RectorKernel extends Kernel
]));
$containerBuilder->addCompilerPass(new AutoBindParametersCompilerPass());
$containerBuilder->addCompilerPass(new ConfigurableCollectorCompilerPass());
}
/**

View File

@ -8,3 +8,10 @@ imports:
parameters:
exclude_paths: []
autoload_paths: []
# see https://github.com/symplify/packagebuilder#collect-services-in-short-configs
collectors:
-
main_type: 'Rector\NodeTraverser\RectorNodeTraverser'
collected_type: 'Rector\Contract\Rector\PhpRectorInterface'
add_method: 'addRector'