1 | <?php |
||
34 | class CacheKeyUtil implements CacheKeyUtilInterface |
||
35 | { |
||
36 | |||
37 | /** |
||
38 | * The separator for cache key elements. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | const SEPARATOR = '-'; |
||
43 | |||
44 | /** |
||
45 | * The prefix to use. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $prefix; |
||
50 | |||
51 | /** |
||
52 | * Initializes the cache key util with the passed configuration. |
||
53 | * |
||
54 | * @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
||
55 | */ |
||
56 | 20 | public function __construct(ConfigurationInterface $configuration) |
|
60 | |||
61 | /** |
||
62 | * Creates a unique cache key from the passed data. |
||
63 | * |
||
64 | * @param mixed $data The date to create the cache key from |
||
65 | * |
||
66 | * @return string The generated cache key |
||
67 | * @throws \Exception Is thrown if the passed data is not supported to create a cache key from |
||
68 | */ |
||
69 | 20 | public function cacheKey($data) |
|
92 | |||
93 | /** |
||
94 | * Prefixes the cache key, e. g. with the products serial. |
||
95 | * |
||
96 | * @param string $cacheKey The cache key to prefix |
||
97 | * |
||
98 | * @return string The prefixed cache key |
||
99 | */ |
||
100 | 20 | protected function prefix($cacheKey) |
|
104 | |||
105 | /** |
||
106 | * Creates a cache key for a scalar values. |
||
107 | * |
||
108 | * @param mixed $data The scalar value to c |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | 20 | protected function scalarKey($data) |
|
116 | |||
117 | /** |
||
118 | * Creates a cache key from the passed object. |
||
119 | * |
||
120 | * The object MUST implement the __toString method, else an exception will be thrown. |
||
121 | * |
||
122 | * @param object $data The object to create the cache key for |
||
123 | * |
||
124 | * @return string The cache key from the object's __toString method |
||
125 | * @throws \Exception Is thrown, if the object doesn't implement the __toString method |
||
126 | */ |
||
127 | protected function objectKey($data) |
||
140 | |||
141 | /** |
||
142 | * Creates a cache key from the passed array. |
||
143 | * |
||
144 | * @param array $data The array to create the cache key for |
||
145 | * |
||
146 | * @return string The cache key created from the array's key => value pairs |
||
147 | * @throws \Exception Is thrown, if the array contains unsupported values or the array is empty |
||
148 | */ |
||
149 | protected function arrayKey(array $data) |
||
178 | } |
||
179 |