1111use Yiisoft \Cache \Dependency \Dependency ;
1212
1313use function array_merge ;
14- use function get_class ;
15- use function gettype ;
1614use function is_string ;
17- use function is_object ;
1815use function sprintf ;
1916use function strtr ;
2017
2320 */
2421final class CachedContent
2522{
26- private string $ id ;
27- private CacheInterface $ cache ;
2823 private CacheKeyNormalizer $ cacheKeyNormalizer ;
2924
3025 /**
@@ -43,10 +38,12 @@ final class CachedContent
4338 * @param DynamicContent[] $dynamicContents The dynamic content instances.
4439 * @param string[] $variations List of string factors that would cause the variation of the content being cached.
4540 */
46- public function __construct (string $ id , CacheInterface $ cache , array $ dynamicContents = [], array $ variations = [])
47- {
48- $ this ->id = $ id ;
49- $ this ->cache = $ cache ;
41+ public function __construct (
42+ private string $ id ,
43+ private CacheInterface $ cache ,
44+ array $ dynamicContents = [],
45+ array $ variations = []
46+ ) {
5047 $ this ->cacheKeyNormalizer = new CacheKeyNormalizer ();
5148 $ this ->setDynamicContents ($ dynamicContents );
5249 $ this ->setVariations ($ variations );
@@ -98,7 +95,7 @@ public function get(): ?string
9895 */
9996 private function cacheKey (): string
10097 {
101- return $ this ->cacheKeyNormalizer ->normalize (array_merge ([__CLASS__ , $ this ->id ], $ this ->variations ));
98+ return $ this ->cacheKeyNormalizer ->normalize (array_merge ([self ::class , $ this ->id ], $ this ->variations ));
10299 }
103100
104101 /**
@@ -134,7 +131,7 @@ private function setDynamicContents(array $dynamicContents): void
134131 if (!($ dynamicContent instanceof DynamicContent)) {
135132 throw new InvalidArgumentException (sprintf (
136133 'Invalid dynamic content "%s" specified. It must be a "%s" instance. ' ,
137- is_object ( $ dynamicContent ) ? get_class ( $ dynamicContent ) : gettype ($ dynamicContent ),
134+ get_debug_type ($ dynamicContent ),
138135 DynamicContent::class,
139136 ));
140137 }
@@ -154,7 +151,7 @@ private function setVariations(array $variations): void
154151 if (!is_string ($ variation )) {
155152 throw new InvalidArgumentException (sprintf (
156153 'Invalid variation "%s" specified. It must be a string type. ' ,
157- is_object ( $ variation ) ? get_class ( $ variation ) : gettype ($ variation ),
154+ get_debug_type ($ variation ),
158155 ));
159156 }
160157
0 commit comments