Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/sets/contao/contao-53.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Contao\CoreBundle\File\ModelMetadataTrait;
use Contao\CoreBundle\Security\ContaoCorePermissions;
use Contao\Model\MetadataTrait;
use Contao\Rector\Rector\PageGlobalToPageFinderServiceRector;
use Contao\Rector\Rector\StringReplaceRector;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
Expand All @@ -24,4 +25,6 @@
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
ModelMetadataTrait::class => MetadataTrait::class
]);

$rectorConfig->rule(PageGlobalToPageFinderServiceRector::class);
};
44 changes: 44 additions & 0 deletions src/Rector/PageGlobalToPageFinderServiceRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Contao\Rector\Rector;

use Contao\System;
use PhpParser\Node;
use Rector\Rector\AbstractRector;

final class PageGlobalToPageFinderServiceRector extends AbstractRector
{
public function getNodeTypes(): array
{
return [Node\Stmt\Global_::class];
}

public function refactor(Node $node): Node|null
{
assert($node instanceof Node\Stmt\Global_);

foreach ($node->vars as $var) {
if (!$this->isName($var, 'objPage')) {
continue;
}

$variable = new Node\Expr\Variable('objPage');

$container = new Node\Expr\StaticCall(new Node\Name\FullyQualified(System::class), 'getContainer');
$service = new Node\Expr\MethodCall($container, 'get', [new Node\Arg(new Node\Scalar\String_('contao.routing.page_finder'))]);
$call = new Node\Expr\MethodCall($service, 'getCurrentPage');


return new Node\Stmt\Expression(
new Node\Expr\Assign(
$variable,
$call
)
);
}

return null;
}
}