diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index 338d58e..798c236 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -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; @@ -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, [ @@ -511,6 +513,7 @@ ]); $rectorConfig->rule(YamlDimensionConfigRector::class); + $rectorConfig->rule(YamlRoutePartHandlerRector::class); /** * CLEAN UP / END GLOBAL RULES diff --git a/src/ContentRepository90/Rules/YamlRoutePartHandlerRector.php b/src/ContentRepository90/Rules/YamlRoutePartHandlerRector.php new file mode 100644 index 0000000..a7b33a0 --- /dev/null +++ b/src/ContentRepository90/Rules/YamlRoutePartHandlerRector.php @@ -0,0 +1,49 @@ + $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); + } +} diff --git a/tests/ContentRepository90/Rules/YamlRoutePartHandlerRector/Fixture/Routes.yaml.inc b/tests/ContentRepository90/Rules/YamlRoutePartHandlerRector/Fixture/Routes.yaml.inc new file mode 100644 index 0000000..332bc17 --- /dev/null +++ b/tests/ContentRepository90/Rules/YamlRoutePartHandlerRector/Fixture/Routes.yaml.inc @@ -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: '' + 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: '' + appendExceedingArguments: true diff --git a/tests/ContentRepository90/Rules/YamlRoutePartHandlerRector/YamlRoutePartHandlerRectorTest.php b/tests/ContentRepository90/Rules/YamlRoutePartHandlerRector/YamlRoutePartHandlerRectorTest.php new file mode 100644 index 0000000..60160f9 --- /dev/null +++ b/tests/ContentRepository90/Rules/YamlRoutePartHandlerRector/YamlRoutePartHandlerRectorTest.php @@ -0,0 +1,31 @@ +doTestFile($fileInfo); + } + + /** + * @return \Iterator + */ + public function provideData(): \Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.yaml.inc'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/ContentRepository90/Rules/YamlRoutePartHandlerRector/config/configured_rule.php b/tests/ContentRepository90/Rules/YamlRoutePartHandlerRector/config/configured_rule.php new file mode 100644 index 0000000..7c5d4d1 --- /dev/null +++ b/tests/ContentRepository90/Rules/YamlRoutePartHandlerRector/config/configured_rule.php @@ -0,0 +1,17 @@ +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); +}; diff --git a/tests/Sets/ContentRepository90/Fixture/frontend-node-route-part-handler.php.inc b/tests/Sets/ContentRepository90/Fixture/frontend-node-route-part-handler.php.inc new file mode 100644 index 0000000..b7ab91e --- /dev/null +++ b/tests/Sets/ContentRepository90/Fixture/frontend-node-route-part-handler.php.inc @@ -0,0 +1,23 @@ +