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 | * @param boolean $usePrefix Flag to signal using the prefix or not |
||
66 | * |
||
67 | * @return string The generated cache key |
||
68 | * @throws \Exception Is thrown if the passed data is not supported to create a cache key from |
||
69 | */ |
||
70 | 20 | public function cacheKey($data, $usePrefix = true) |
|
93 | |||
94 | /** |
||
95 | * Prefixes the cache key, e. g. with the products serial. |
||
96 | * |
||
97 | * @param string $cacheKey The cache key to prefix |
||
98 | * @param boolean $usePrefix Flag to signal using the prefix or not |
||
99 | * |
||
100 | * @return string The prefixed cache key |
||
101 | */ |
||
102 | 20 | protected function prefix($cacheKey, $usePrefix) |
|
106 | |||
107 | /** |
||
108 | * Creates a cache key for a scalar values. |
||
109 | * |
||
110 | * @param mixed $data The scalar value to c |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | 20 | protected function scalarKey($data) |
|
118 | |||
119 | /** |
||
120 | * Creates a cache key from the passed object. |
||
121 | * |
||
122 | * The object MUST implement the __toString method, else an exception will be thrown. |
||
123 | * |
||
124 | * @param object $data The object to create the cache key for |
||
125 | * |
||
126 | * @return string The cache key from the object's __toString method |
||
127 | * @throws \Exception Is thrown, if the object doesn't implement the __toString method |
||
128 | */ |
||
129 | protected function objectKey($data) |
||
142 | |||
143 | /** |
||
144 | * Creates a cache key from the passed array. |
||
145 | * |
||
146 | * @param array $data The array to create the cache key for |
||
147 | * |
||
148 | * @return string The cache key created from the array's key => value pairs |
||
149 | * @throws \Exception Is thrown, if the array contains unsupported values or the array is empty |
||
150 | */ |
||
151 | protected function arrayKey(array $data) |
||
180 | } |
||
181 |