Skip to content

Commit

Permalink
Merge pull request #112 from neos/feature/frontend-route-node-part-ha…
Browse files Browse the repository at this point in the history
…ndler

FEATURE: Replace FrontendNodeRoutePartHandler  with interface
  • Loading branch information
ahaeslich authored Dec 18, 2024
2 parents d400249 + f753ce3 commit 25d62b6
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/set/contentrepository-90.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
use Neos\Rector\ContentRepository90\Rules\WorkspaceGetNameRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceRepositoryCountByNameRector;
use Neos\Rector\ContentRepository90\Rules\YamlDimensionConfigRector;
use Neos\Rector\ContentRepository90\Rules\YamlRoutePartHandlerRector;
use Neos\Rector\Generic\Rules\FusionFlowQueryNodePropertyToWarningCommentRector;
use Neos\Rector\Generic\Rules\FusionNodePropertyPathToWarningCommentRector;
use Neos\Rector\Generic\Rules\FusionPrototypeNameAddCommentRector;
Expand Down Expand Up @@ -121,6 +122,7 @@
\Neos\ContentRepository\Domain\NodeType\NodeTypeName::class => \Neos\ContentRepository\Core\NodeType\NodeTypeName::class,
\Neos\ContentRepository\Domain\Projection\Content\PropertyCollectionInterface::class => \Neos\ContentRepository\Core\Projection\ContentGraph\PropertyCollection::class,
\Neos\ContentRepository\Domain\Model\ArrayPropertyCollection::class => \Neos\ContentRepository\Core\Projection\ContentGraph\PropertyCollection::class,
\Neos\Neos\Routing\FrontendNodeRoutePartHandlerInterface::class => \Neos\Neos\FrontendRouting\FrontendNodeRoutePartHandlerInterface::class,
]);

$rectorConfig->ruleWithConfiguration(FusionReplacePrototypeNameRector::class, [
Expand Down Expand Up @@ -511,6 +513,7 @@
]);

$rectorConfig->rule(YamlDimensionConfigRector::class);
$rectorConfig->rule(YamlRoutePartHandlerRector::class);

/**
* CLEAN UP / END GLOBAL RULES
Expand Down
49 changes: 49 additions & 0 deletions src/ContentRepository90/Rules/YamlRoutePartHandlerRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Neos\Rector\ContentRepository90\Rules;

use Neos\Rector\Core\YamlProcessing\YamlRectorInterface;
use Neos\Rector\Core\YamlProcessing\YamlWithComments;
use Neos\Rector\Utility\CodeSampleLoader;
use Neos\Utility\Arrays;
use Symfony\Component\Yaml\Yaml;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

class YamlRoutePartHandlerRector implements YamlRectorInterface
{

public function getRuleDefinition(): RuleDefinition
{
return CodeSampleLoader::fromFile('Fusion: Rewrite Routes.yaml config to use Neos\Neos\FrontendRouting\FrontendNodeRoutePartHandlerInterface as route part handler', __CLASS__);
}

public function refactorFileContent(string $fileContent): string
{
$parsed = Yaml::parse($fileContent);
if (!is_array($parsed)) {
return $fileContent;
}

foreach ($parsed as $routeConfigKey => $routeConfig) {
if (!is_array($routeConfig)) {
continue;
}
if (!isset($routeConfig['routeParts']) || !is_array($routeConfig['routeParts'])) {
continue;
}

$handlerToReplace = [
\Neos\Neos\Routing\FrontendNodeRoutePartHandler::class,
\Neos\Neos\Routing\FrontendNodeRoutePartHandlerInterface::class,
];

foreach ($routeConfig['routeParts'] as $routePartKey => $routePart) {
if (isset($routePart['handler']) && in_array($routePart['handler'], $handlerToReplace)) {
$parsed[$routeConfigKey]['routeParts'][$routePartKey]['handler'] = \Neos\Neos\FrontendRouting\FrontendNodeRoutePartHandlerInterface::class;
}
}
}

return YamlWithComments::dump($parsed);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
- name: 'ATOM Package Feed'
uriPattern: '{node}.atom'
defaults:
'@package': 'Neos.Neos'
'@controller': 'Frontend\Node'
'@action': 'show'
'@format': 'atom'
routeParts:
'node':
handler: 'Neos\Neos\Routing\FrontendNodeRoutePartHandler'
-
name: Preview
uriPattern: neos/preview
defaults:
'@action': preview
appendExceedingArguments: true
-
name: 'Default Frontend'
uriPattern: '{node}'
routeParts:
'node':
handler: 'Neos\Neos\Routing\FrontendNodeRoutePartHandlerInterface'
options:
uriPathSuffix: '<defaultUriSuffix>'
appendExceedingArguments: true
-----
-
name: 'ATOM Package Feed'
uriPattern: '{node}.atom'
defaults:
'@package': Neos.Neos
'@controller': Frontend\Node
'@action': show
'@format': atom
routeParts:
node:
handler: Neos\Neos\FrontendRouting\FrontendNodeRoutePartHandlerInterface
-
name: Preview
uriPattern: neos/preview
defaults:
'@action': preview
appendExceedingArguments: true
-
name: 'Default Frontend'
uriPattern: '{node}'
routeParts:
node:
handler: Neos\Neos\FrontendRouting\FrontendNodeRoutePartHandlerInterface
options:
uriPathSuffix: '<defaultUriSuffix>'
appendExceedingArguments: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Neos\Rector\Tests\ContentRepository90\Rules\YamlDimensionConfigRector;

use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class YamlRoutePartHandlerRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(string $fileInfo): void
{
$this->doTestFile($fileInfo);
}

/**
* @return \Iterator<string>
*/
public function provideData(): \Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.yaml.inc');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare (strict_types=1);

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$services = $rectorConfig->services();
$services->defaults()
->public()
->autowire()
->autoconfigure();
$services->set(\Neos\Rector\Core\YamlProcessing\YamlFileProcessor::class);
$rectorConfig->disableParallel(); // does not work for yaml files - see https://github.com/rectorphp/rector-src/pull/2597#issuecomment-1190120688

$rectorConfig->rule(Neos\Rector\ContentRepository90\Rules\YamlRoutePartHandlerRector::class);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Neos\Rector\Test;

use Neos\Neos\Routing\FrontendNodeRoutePartHandlerInterface;

class SomeClass implements FrontendNodeRoutePartHandlerInterface
{

}

-----
<?php

namespace Neos\Rector\Test;

use Neos\Neos\Routing\FrontendNodeRoutePartHandlerInterface;

class SomeClass implements \Neos\Neos\FrontendRouting\FrontendNodeRoutePartHandlerInterface
{

}

0 comments on commit 25d62b6

Please sign in to comment.