From 1d5230b49425d989041fc3b14df7c32fb78499b3 Mon Sep 17 00:00:00 2001 From: Philipp Kitzberger Date: Mon, 17 Jul 2023 11:33:02 +0200 Subject: [PATCH] [FEATURE] Provide rules to migrate v:extension.path.absolute and .relative --- config/replace-vhs.php | 4 ++ ...eplaceExtensionPathAbsoluteFluidRector.php | 56 +++++++++++++++++++ ...eplaceExtensionPathRelativeFluidRector.php | 56 +++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathAbsoluteFluidRector.php create mode 100644 src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathRelativeFluidRector.php diff --git a/config/replace-vhs.php b/config/replace-vhs.php index 62cf604a8..edb2d13a7 100644 --- a/config/replace-vhs.php +++ b/config/replace-vhs.php @@ -3,6 +3,8 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceExtensionPathAbsoluteFluidRector; +use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceExtensionPathRelativeFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceFormatJsonEncodeFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceLFluidRector; use Ssch\TYPO3Rector\FileProcessor\Fluid\Rector\vhs\ReplaceMediaImageFluidRector; @@ -12,6 +14,8 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->import(__DIR__ . '/config.php'); + $rectorConfig->rule(ReplaceExtensionPathAbsoluteFluidRector::class); + $rectorConfig->rule(ReplaceExtensionPathRelativeFluidRector::class); $rectorConfig->rule(ReplaceFormatJsonEncodeFluidRector::class); $rectorConfig->rule(ReplaceLFluidRector::class); $rectorConfig->rule(ReplaceMediaImageFluidRector::class); diff --git a/src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathAbsoluteFluidRector.php b/src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathAbsoluteFluidRector.php new file mode 100644 index 000000000..e77e1761f --- /dev/null +++ b/src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathAbsoluteFluidRector.php @@ -0,0 +1,56 @@ +getFileContent(); + + $content = Strings::replace( + $content, + self::PATTERN_INLINE, + '{f:uri.resource(extensionName:\'\3\',path:\'\4.\5\',absolute:1)}' + ); + + if (Strings::matchAll($content, self::PATTERN_LEFTOVERS)) { + $this->rectorOutputStyle->warning('There\'s occurrences of v:extension.path.absolute that couldn\'t be migrated automatically. Migrate them manually!'); + } + + $file->changeFileContent($content); + } + + public function getRuleDefinition(): RuleDefinition + { + return new RuleDefinition('Use instead of ', [ + new CodeSample( + <<<'CODE_SAMPLE' +{v:extension.path.absolute(extensionName:'my_extension')}Resources/Public/Css/style.css +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +{f:uri.resource(extensionName:'my_extension',path:'Css/style.css',absolute:1)} +CODE_SAMPLE + ), + ]); + } +} diff --git a/src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathRelativeFluidRector.php b/src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathRelativeFluidRector.php new file mode 100644 index 000000000..2e2b16632 --- /dev/null +++ b/src/FileProcessor/Fluid/Rector/vhs/ReplaceExtensionPathRelativeFluidRector.php @@ -0,0 +1,56 @@ +getFileContent(); + + $content = Strings::replace( + $content, + self::PATTERN_INLINE, + '{f:uri.resource(extensionName:\'\3\',path:\'\4.\5\')}' + ); + + if (Strings::matchAll($content, self::PATTERN_LEFTOVERS)) { + $this->rectorOutputStyle->warning('There\'s occurrences of v:extension.path.relative that couldn\'t be migrated automatically. Migrate them manually!'); + } + + $file->changeFileContent($content); + } + + public function getRuleDefinition(): RuleDefinition + { + return new RuleDefinition('Use instead of ', [ + new CodeSample( + <<<'CODE_SAMPLE' +{v:extension.path.relative(extensionName:'my_extension')}Resources/Public/Css/style.css +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +{f:uri.resource(extensionName:'my_extension',path:'Css/style.css')} +CODE_SAMPLE + ), + ]); + } +}