-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Add
Flow\InjectCache
Annotation and Attribute
The `#[Flow\InjectCache]` attribute resp. the`@Flow\InjectCache` annotation allows to assign a cache frontend of a configured cache directly into a property without having to configure the Objects.yaml.
- Loading branch information
Showing
6 changed files
with
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
namespace Neos\Flow\Annotations; | ||
|
||
/* | ||
* This file is part of the Neos.Flow package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; | ||
|
||
/** | ||
* Used to enable property injection for cache frontends. | ||
* | ||
* Flow will build Dependency Injection code for the property and try | ||
* to inject the specified cache. | ||
* | ||
* @Annotation | ||
* @NamedArgumentConstructor | ||
* @Target("PROPERTY") | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
final class InjectCache | ||
{ | ||
/** | ||
* Identifier for the Cache that will be injected. | ||
* | ||
* Example: Neos_Fusion_Content | ||
* | ||
* @var string | ||
*/ | ||
public $identifier; | ||
|
||
public function __construct(string $identifier) | ||
{ | ||
$this->identifier = $identifier; | ||
} | ||
} |
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
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
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
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
40 changes: 40 additions & 0 deletions
40
Neos.Flow/Tests/Functional/ObjectManagement/Fixtures/ClassWithInjectedCache.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,40 @@ | ||
<?php | ||
namespace Neos\Flow\Tests\Functional\ObjectManagement\Fixtures; | ||
|
||
/* | ||
* This file is part of the Neos.Flow package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Cache\Frontend\StringFrontend; | ||
use Neos\Flow\Annotations as Flow; | ||
|
||
/** | ||
* A class for testing setting injection | ||
*/ | ||
class ClassWithInjectedCache | ||
{ | ||
/** | ||
* @Flow\InjectCache(identifier="Flow_Monitor") | ||
* @var StringFrontend | ||
*/ | ||
protected $cacheByAnnotation; | ||
|
||
#[Flow\InjectCache(identifier: 'Flow_Monitor')] | ||
protected StringFrontend $cacheByAttribute; | ||
|
||
public function getCacheInjectedViaAnnotation() | ||
{ | ||
return $this->cacheByAnnotation; | ||
} | ||
|
||
public function getCacheInjectedViaAttribute() | ||
{ | ||
return $this->cacheByAttribute; | ||
} | ||
} |