-
-
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 #113 from neos/feature/comment-cache-lifetime
FEATURE: Add comment on usage of cacheLifetime in Fusion
- Loading branch information
Showing
6 changed files
with
118 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
28 changes: 28 additions & 0 deletions
28
src/ContentRepository90/Rules/FusionCacheLifetimeRector.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Rector\ContentRepository90\Rules; | ||
|
||
use Neos\Rector\Core\FusionProcessing\EelExpressionTransformer; | ||
use Neos\Rector\Core\FusionProcessing\FusionRectorInterface; | ||
use Neos\Rector\Utility\CodeSampleLoader; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
class FusionCacheLifetimeRector implements FusionRectorInterface | ||
{ | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return CodeSampleLoader::fromFile('Fusion: Add comment if .cacheLifetime() is used.', __CLASS__); | ||
} | ||
|
||
public function refactorFileContent(string $fileContent): string | ||
{ | ||
return EelExpressionTransformer::parse($fileContent) | ||
->addCommentsIfRegexMatches( | ||
'/\.cacheLifetime()/', | ||
'// TODO 9.0 migration: Line %LINE: You may need to remove ".cacheLifetime()" as this FlowQuery Operation has been removed. This is not needed anymore as the concept of timeable node visibility has changed. See https://github.com/neos/timeable-node-visibility' | ||
)->getProcessedContent(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ContentRepository90/Rules/FusionCacheLifetimeRector/Fixture/some_file.fusion.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,17 @@ | ||
prototype(My.Namespace:Value) < prototype(Neos.Fusion:Value) { | ||
|
||
lifetime = ${q(node).cacheLifetime()} | ||
|
||
@cache.maximumLifetime = ${q(node).context({'invisibleContentShown': true}).find('[instanceof Neos.Neos:Content]').cacheLifetime()} | ||
|
||
} | ||
----- | ||
// TODO 9.0 migration: Line 5: You may need to remove ".cacheLifetime()" as this FlowQuery Operation has been removed. This is not needed anymore as the concept of timeable node visibility has changed. See https://github.com/neos/timeable-node-visibility | ||
// TODO 9.0 migration: Line 7: You may need to remove ".cacheLifetime()" as this FlowQuery Operation has been removed. This is not needed anymore as the concept of timeable node visibility has changed. See https://github.com/neos/timeable-node-visibility | ||
prototype(My.Namespace:Value) < prototype(Neos.Fusion:Value) { | ||
|
||
lifetime = ${q(node).cacheLifetime()} | ||
|
||
@cache.maximumLifetime = ${q(node).context({'invisibleContentShown': true}).find('[instanceof Neos.Neos:Content]').cacheLifetime()} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
tests/ContentRepository90/Rules/FusionCacheLifetimeRector/FusionCacheLifetimeRectorTest.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\FusionNodeDepthRector; | ||
|
||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class FusionCacheLifetimeRectorTest 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', '*.fusion.inc'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/ContentRepository90/Rules/FusionCacheLifetimeRector/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,19 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
use Neos\Rector\ContentRepository90\Rules\FusionCacheLifetimeRector; | ||
use Neos\Rector\Core\FusionProcessing\FusionFileProcessor; | ||
use Rector\Config\RectorConfig; | ||
|
||
return static function (RectorConfig $rectorConfig) : void { | ||
$services = $rectorConfig->services(); | ||
$services->defaults() | ||
->public() | ||
->autowire() | ||
->autoconfigure(); | ||
$services->set(FusionFileProcessor::class); | ||
$rectorConfig->disableParallel(); // does not work for fusion files - see https://github.com/rectorphp/rector-src/pull/2597#issuecomment-1190120688 | ||
|
||
$rectorConfig->rule(FusionCacheLifetimeRector::class); | ||
}; |
17 changes: 17 additions & 0 deletions
17
tests/Sets/ContentRepository90/Fixture/Fusion/cache-lifetime.fusion.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,17 @@ | ||
prototype(My.Namespace:Value) < prototype(Neos.Fusion:Value) { | ||
|
||
lifetime = ${q(node).cacheLifetime()} | ||
|
||
@cache.maximumLifetime = ${q(node).context({'invisibleContentShown': true}).find('[instanceof Neos.Neos:Content]').cacheLifetime()} | ||
|
||
} | ||
----- | ||
// TODO 9.0 migration: Line 5: You may need to remove ".cacheLifetime()" as this FlowQuery Operation has been removed. This is not needed anymore as the concept of timeable node visibility has changed. See https://github.com/neos/timeable-node-visibility | ||
// TODO 9.0 migration: Line 7: You may need to remove ".cacheLifetime()" as this FlowQuery Operation has been removed. This is not needed anymore as the concept of timeable node visibility has changed. See https://github.com/neos/timeable-node-visibility | ||
prototype(My.Namespace:Value) < prototype(Neos.Fusion:Value) { | ||
|
||
lifetime = ${q(node).cacheLifetime()} | ||
|
||
@cache.maximumLifetime = ${q(node).context({'invisibleContentShown': true}).find('[instanceof Neos.Neos:Content]').cacheLifetime()} | ||
|
||
} |