1313 */
1414class MetadataAwareStringFrontend extends StringFrontend
1515{
16- const SEPARATOR = '| ' ;
16+ protected const SEPARATOR = '| ' ;
1717
1818 /**
1919 * Store metadata of all loaded cache entries indexed by identifier
20- *
21- * @var array
2220 */
23- protected $ metadata = [];
21+ protected array $ metadata = [];
2422
25- /**
26- * @Flow\Inject
27- * @var Environment
28- */
29- protected $ environment ;
23+ #[Flow \Inject]
24+ protected Environment $ environment ;
3025
31- /**
32- * @Flow\Inject
33- * @var LoggerInterface
34- */
35- protected $ logger ;
26+ #[Flow \Inject]
27+ protected LoggerInterface $ logger ;
3628
3729 /**
3830 * Set a cache entry and store additional metadata (tags and lifetime)
3931 *
4032 * {@inheritdoc}
4133 */
42- public function set (string $ entryIdentifier , $ content , array $ tags = [], int $ lifetime = null )
34+ public function set (string $ entryIdentifier , $ string , array $ tags = [], int $ lifetime = null ): void
4335 {
44- $ content = $ this ->insertMetadata ($ content , $ entryIdentifier , $ tags , $ lifetime );
36+ $ content = $ this ->insertMetadata ($ string , $ entryIdentifier , $ tags , $ lifetime );
4537 parent ::set ($ entryIdentifier , $ content , $ tags , $ lifetime );
4638 }
4739
4840 /**
4941 * {@inheritdoc}
42+ * @throws InvalidDataTypeException
5043 */
51- public function get (string $ entryIdentifier )
44+ public function get (string $ entryIdentifier ): bool | string
5245 {
5346 $ content = parent ::get ($ entryIdentifier );
5447 if ($ content !== false ) {
@@ -60,6 +53,7 @@ public function get(string $entryIdentifier)
6053
6154 /**
6255 * {@inheritdoc}
56+ * @throws InvalidDataTypeException
6357 */
6458 public function getByTag (string $ tag ): array
6559 {
@@ -74,18 +68,13 @@ public function getByTag(string $tag): array
7468 /**
7569 * Insert metadata into the content
7670 *
77- * @param string $content
7871 * @param string $entryIdentifier The identifier metadata
7972 * @param array $tags The tags metadata
80- * @param integer $lifetime The lifetime metadata
73+ * @param integer|null $lifetime The lifetime metadata
8174 * @return string The content including the serialized metadata
82- * @throws InvalidDataTypeException
8375 */
84- protected function insertMetadata ($ content , $ entryIdentifier , array $ tags , $ lifetime)
76+ protected function insertMetadata (string $ content , string $ entryIdentifier , array $ tags , int $ lifetime = null ): string
8577 {
86- if (!is_string ($ content )) {
87- throw new InvalidDataTypeException ('Given data is of type " ' . gettype ($ content ) . '", but a string is expected for string cache. ' , 1433155737 );
88- }
8978 $ metadata = [
9079 'identifier ' => $ entryIdentifier ,
9180 'tags ' => $ tags ,
@@ -105,7 +94,7 @@ protected function insertMetadata($content, $entryIdentifier, array $tags, $life
10594 * @return string The content without metadata
10695 * @throws InvalidDataTypeException
10796 */
108- protected function extractMetadata ($ entryIdentifier , $ content )
97+ protected function extractMetadata (string $ entryIdentifier , string $ content ): string
10998 {
11099 $ separatorIndex = strpos ($ content , self ::SEPARATOR );
111100 if ($ separatorIndex === false ) {
@@ -136,7 +125,7 @@ protected function extractMetadata($entryIdentifier, $content)
136125 /**
137126 * @return array Metadata of all loaded entries (indexed by identifier)
138127 */
139- public function getAllMetadata ()
128+ public function getAllMetadata (): array
140129 {
141130 return $ this ->metadata ;
142131 }
0 commit comments