-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from neos/feature/frontend-route-node-part-ha…
…ndler FEATURE: Replace FrontendNodeRoutePartHandler with interface
- Loading branch information
Showing
6 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/ContentRepository90/Rules/YamlRoutePartHandlerRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
tests/ContentRepository90/Rules/YamlRoutePartHandlerRector/Fixture/Routes.yaml.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
31 changes: 31 additions & 0 deletions
31
...s/ContentRepository90/Rules/YamlRoutePartHandlerRector/YamlRoutePartHandlerRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ContentRepository90/Rules/YamlRoutePartHandlerRector/config/configured_rule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
23 changes: 23 additions & 0 deletions
23
tests/Sets/ContentRepository90/Fixture/frontend-node-route-part-handler.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
||
} | ||
|