mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 19:53:14 +01:00
add RectorProviderInterface + CompilerPass to load it
This commit is contained in:
parent
07d3641cbd
commit
38443547ec
@ -4,15 +4,24 @@ namespace Rector\RectorBuilder;
|
||||
|
||||
use PhpParser\Node;
|
||||
use Rector\Contract\Rector\RectorInterface;
|
||||
use Rector\NodeAnalyzer\MethodCallAnalyzer;
|
||||
|
||||
final class CaseRector implements RectorInterface
|
||||
{
|
||||
public function __construct()
|
||||
/**
|
||||
* @var MethodCallAnalyzer
|
||||
*/
|
||||
private $methodCallAnalyzer;
|
||||
|
||||
public function __construct(MethodCallAnalyzer $methodCallAnalyzer)
|
||||
{
|
||||
$this->methodCallAnalyzer = $methodCallAnalyzer;
|
||||
}
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
dump('EE');
|
||||
die;
|
||||
// TODO: Implement isCandidate() method.
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,16 @@ final class CaseRectorBuilder
|
||||
*/
|
||||
private $newArguments = [];
|
||||
|
||||
/**
|
||||
* @var CaseRector
|
||||
*/
|
||||
private $caseRector;
|
||||
|
||||
public function __construct(CaseRector $caseRector)
|
||||
{
|
||||
$this->caseRector = $caseRector;
|
||||
}
|
||||
|
||||
public function matchMethodCallByType(string $type): self
|
||||
{
|
||||
$this->type = $type;
|
||||
@ -56,9 +66,10 @@ final class CaseRectorBuilder
|
||||
|
||||
public function create(): RectorInterface
|
||||
{
|
||||
// $caseRector = new CaseRector()
|
||||
$caseRector = clone $this->caseRector;
|
||||
|
||||
dump('the work :)');
|
||||
die;
|
||||
// @todo: configure by all that has been setup here
|
||||
|
||||
return $caseRector;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\RectorBuilder\Contract;
|
||||
|
||||
use Rector\Contract\Rector\RectorInterface;
|
||||
|
||||
interface RectorProviderInterface
|
||||
{
|
||||
public function provide(): RectorInterface;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\RectorBuilder\DependencyInjection\CompilerPass;
|
||||
|
||||
use Rector\Rector\RectorCollector;
|
||||
use Rector\RectorBuilder\Contract\RectorProviderInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symplify\PackageBuilder\DependencyInjection\DefinitionFinder;
|
||||
|
||||
final class RectorProvidersCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $containerBuilder): void
|
||||
{
|
||||
$rectorCollectorDefinition = DefinitionFinder::getByType($containerBuilder, RectorCollector::class);
|
||||
$rectorProviderDefinitions = DefinitionFinder::findAllByType($containerBuilder, RectorProviderInterface::class);
|
||||
|
||||
foreach ($rectorProviderDefinitions as $rectorProviderDefinition) {
|
||||
$methodCallArgument = sprintf("@=service('%s').provide()", $rectorProviderDefinition->getClass());
|
||||
$rectorCollectorDefinition->addMethodCall('addRector', [$methodCallArgument]);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,5 +3,5 @@ services:
|
||||
autowire: true
|
||||
|
||||
Rector\RectorBuilder\:
|
||||
resource: '../'
|
||||
exclude: '../{BuilderRector.php}'
|
||||
resource: ..
|
||||
exclude: ../{CaseRector.php}
|
||||
|
@ -4,6 +4,7 @@ namespace Rector\DependencyInjection;
|
||||
|
||||
use Rector\DependencyInjection\CompilerPass\CollectorCompilerPass;
|
||||
use Rector\NodeTypeResolver\DependencyInjection\CompilerPass\NodeTypeResolverCollectorCompilerPass;
|
||||
use Rector\RectorBuilder\DependencyInjection\CompilerPass\RectorProvidersCompilerPass;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
|
||||
@ -58,6 +59,7 @@ final class RectorKernel extends Kernel
|
||||
protected function build(ContainerBuilder $containerBuilder): void
|
||||
{
|
||||
$containerBuilder->addCompilerPass(new CollectorCompilerPass());
|
||||
$containerBuilder->addCompilerPass(new RectorProvidersCompilerPass());
|
||||
$containerBuilder->addCompilerPass(new NodeTypeResolverCollectorCompilerPass());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Contrib\Nette\Application\ValidateControlRector;
|
||||
|
||||
use Rector\Contract\Rector\RectorInterface;
|
||||
use Rector\RectorBuilder\CaseRectorBuilder;
|
||||
use Rector\RectorBuilder\Contract\RectorProviderInterface;
|
||||
|
||||
final class RectorProvider implements RectorProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var CaseRectorBuilder
|
||||
*/
|
||||
private $caseRectorBuilder;
|
||||
|
||||
public function __construct(CaseRectorBuilder $caseRectorBuilder)
|
||||
{
|
||||
$this->caseRectorBuilder = $caseRectorBuilder;
|
||||
}
|
||||
|
||||
public function provide(): RectorInterface
|
||||
{
|
||||
return $this->caseRectorBuilder->matchMethodCallByType('@todo')
|
||||
->matchMethodName('@todo')
|
||||
->changeMethodNameTo('@todo')
|
||||
->addArgument(2, '@todo')
|
||||
->create();
|
||||
}
|
||||
}
|
@ -1,5 +1,2 @@
|
||||
rectors:
|
||||
|
||||
factory: [
|
||||
'@RectorBuilder
|
||||
]
|
||||
services:
|
||||
Rector\Tests\Rector\Contrib\Nette\Application\ValidateControlRector\RectorProvider: ~
|
||||
|
Loading…
x
Reference in New Issue
Block a user