@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public static function getInstance() |
50 | 50 | { |
51 | - return (self::$instance ?: self::$instance = new self); |
|
51 | + return (self::$instance ?: self::$instance = new self); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | public function dispatch($eventName, ...$args) |
66 | 66 | { |
67 | 67 | $eventName = 'on' . ucfirst($eventName); |
68 | - if(array_key_exists($eventName, $this->events)){ |
|
69 | - foreach ($this->events[ $eventName ] as $event) { |
|
68 | + if (array_key_exists($eventName, $this->events)) { |
|
69 | + foreach ($this->events[$eventName] as $event) { |
|
70 | 70 | call_user_func_array($event, $args); |
71 | 71 | } |
72 | 72 | } |
@@ -80,17 +80,17 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function __call($name, $arguments) |
82 | 82 | { |
83 | - if(strpos($name, 'on') === 0){ |
|
84 | - if(is_callable($arguments[0])){ |
|
85 | - if(isset($arguments[1]) && is_string($arguments[0])){ |
|
83 | + if (strpos($name, 'on') === 0) { |
|
84 | + if (is_callable($arguments[0])) { |
|
85 | + if (isset($arguments[1]) && is_string($arguments[0])) { |
|
86 | 86 | $this->events[$name][$arguments[1]] = $arguments[0]; |
87 | - }else { |
|
87 | + } else { |
|
88 | 88 | $this->events[$name][] = $arguments[0]; |
89 | 89 | } |
90 | - }else{ |
|
90 | + } else { |
|
91 | 91 | throw new \InvalidArgumentException(sprintf('Expected Callable, got "%s"', gettype($arguments[0]))); |
92 | 92 | } |
93 | - }else{ |
|
93 | + } else { |
|
94 | 94 | throw new \BadMethodCallException('An event must start with "on" such as "onCacheGetItem"'); |
95 | 95 | } |
96 | 96 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function unbindEventCallback($eventName, $callbackName) |
104 | 104 | { |
105 | - if(isset($this->events[$eventName][$callbackName])){ |
|
105 | + if (isset($this->events[$eventName][$callbackName])) { |
|
106 | 106 | unset($this->events[$eventName][$callbackName]); |
107 | 107 | return true; |
108 | 108 | } |
@@ -84,13 +84,13 @@ |
||
84 | 84 | if(is_callable($arguments[0])){ |
85 | 85 | if(isset($arguments[1]) && is_string($arguments[0])){ |
86 | 86 | $this->events[$name][$arguments[1]] = $arguments[0]; |
87 | - }else { |
|
87 | + } else { |
|
88 | 88 | $this->events[$name][] = $arguments[0]; |
89 | 89 | } |
90 | - }else{ |
|
90 | + } else{ |
|
91 | 91 | throw new \InvalidArgumentException(sprintf('Expected Callable, got "%s"', gettype($arguments[0]))); |
92 | 92 | } |
93 | - }else{ |
|
93 | + } else{ |
|
94 | 94 | throw new \BadMethodCallException('An event must start with "on" such as "onCacheGetItem"'); |
95 | 95 | } |
96 | 96 | } |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | * @var ExtendedCacheItemPoolInterface[] |
57 | 57 | */ |
58 | 58 | protected static $config = [ |
59 | - 'itemDetailedDate' => false,// Specify if the item must provide detailed creation/modification dates |
|
60 | - 'defaultTtl' => 900,// Default time-to-live in second |
|
61 | - 'securityKey' => 'auto',// The securityKey that will be used to create sub-directory |
|
62 | - 'htaccess' => true,// Auto-generate .htaccess if tit is missing |
|
59 | + 'itemDetailedDate' => false, // Specify if the item must provide detailed creation/modification dates |
|
60 | + 'defaultTtl' => 900, // Default time-to-live in second |
|
61 | + 'securityKey' => 'auto', // The securityKey that will be used to create sub-directory |
|
62 | + 'htaccess' => true, // Auto-generate .htaccess if tit is missing |
|
63 | 63 | 'default_chmod' => 0777, // 0777 recommended |
64 | - 'path' => '',// if not set will be the value of sys_get_temp_dir() |
|
64 | + 'path' => '', // if not set will be the value of sys_get_temp_dir() |
|
65 | 65 | 'fallback' => false, //Fall back when old driver is not support |
66 | 66 | 'limited_memory_each_object' => 4096, // maximum size (bytes) of object store in memory |
67 | 67 | 'compress_data' => false, // compress stored data, if the backend supports it |
@@ -97,29 +97,29 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | $instance = crc32($driver . serialize($config)); |
100 | - if (!isset(self::$instances[ $instance ])) { |
|
100 | + if (!isset(self::$instances[$instance])) { |
|
101 | 101 | $badPracticeOmeter[$driver] = 1; |
102 | 102 | $class = self::getNamespacePath() . $driver . '\Driver'; |
103 | - try{ |
|
104 | - self::$instances[ $instance ] = new $class($config); |
|
105 | - self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); |
|
106 | - }catch(phpFastCacheDriverCheckException $e){ |
|
103 | + try { |
|
104 | + self::$instances[$instance] = new $class($config); |
|
105 | + self::$instances[$instance]->setEventManager(EventManager::getInstance()); |
|
106 | + } catch (phpFastCacheDriverCheckException $e) { |
|
107 | 107 | $fallback = self::standardizeDriverName($config['fallback']); |
108 | - if($fallback && $fallback !== $driver){ |
|
108 | + if ($fallback && $fallback !== $driver) { |
|
109 | 109 | $class = self::getNamespacePath() . $fallback . '\Driver'; |
110 | - self::$instances[ $instance ] = new $class($config); |
|
111 | - self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); |
|
110 | + self::$instances[$instance] = new $class($config); |
|
111 | + self::$instances[$instance]->setEventManager(EventManager::getInstance()); |
|
112 | 112 | trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING); |
113 | - }else{ |
|
113 | + } else { |
|
114 | 114 | throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e); |
115 | 115 | } |
116 | 116 | } |
117 | - } else if(++$badPracticeOmeter[$driver] >= 5){ |
|
117 | + } else if (++$badPracticeOmeter[$driver] >= 5) { |
|
118 | 118 | trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. |
119 | 119 | See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F'); |
120 | 120 | } |
121 | 121 | |
122 | - return self::$instances[ $instance ]; |
|
122 | + return self::$instances[$instance]; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public static function __callStatic($name, $arguments) |
182 | 182 | { |
183 | - $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[ 0 ] : []); |
|
183 | + $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[0] : []); |
|
184 | 184 | |
185 | 185 | return self::getInstance($name, $options); |
186 | 186 | } |
@@ -233,9 +233,9 @@ discard block |
||
233 | 233 | { |
234 | 234 | if (is_array($name)) { |
235 | 235 | self::$config = array_merge(self::$config, $name); |
236 | - } else if (is_string($name)){ |
|
237 | - self::$config[ $name ] = $value; |
|
238 | - }else{ |
|
236 | + } else if (is_string($name)) { |
|
237 | + self::$config[$name] = $value; |
|
238 | + } else { |
|
239 | 239 | throw new \InvalidArgumentException('Invalid variable type: $name'); |
240 | 240 | } |
241 | 241 | } |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | $driverArray = $this->driverRead($item); |
68 | 68 | |
69 | 69 | if ($driverArray) { |
70 | - if(!is_array($driverArray)){ |
|
70 | + if (!is_array($driverArray)) { |
|
71 | 71 | throw new phpFastCacheCoreException(sprintf('The driverRead method returned an unexpected variable type: %s', gettype($driverArray))); |
72 | 72 | } |
73 | 73 | $item->set($this->driverUnwrapData($driverArray)); |
74 | 74 | $item->expiresAt($this->driverUnwrapEdate($driverArray)); |
75 | 75 | |
76 | - if($this->config['itemDetailedDate']){ |
|
76 | + if ($this->config['itemDetailedDate']) { |
|
77 | 77 | |
78 | 78 | /** |
79 | 79 | * If the itemDetailedDate has been |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | } else { |
98 | 98 | $item->setHit(true); |
99 | 99 | } |
100 | - }else{ |
|
101 | - $item->expiresAfter(abs((int) $this->getConfig()[ 'defaultTtl' ])); |
|
100 | + } else { |
|
101 | + $item->expiresAfter(abs((int) $this->getConfig()['defaultTtl'])); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | * @param $this ExtendedCacheItemPoolInterface |
112 | 112 | * @param $this ExtendedCacheItemInterface |
113 | 113 | */ |
114 | - $this->eventManager->dispatch('CacheGetItem', $this, $this->itemInstances[ $key ]); |
|
114 | + $this->eventManager->dispatch('CacheGetItem', $this, $this->itemInstances[$key]); |
|
115 | 115 | |
116 | - return $this->itemInstances[ $key ]; |
|
116 | + return $this->itemInstances[$key]; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | public function setItem(CacheItemInterface $item) |
125 | 125 | { |
126 | 126 | if ($this->getClassNamespace() . '\\Item' === get_class($item)) { |
127 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
127 | + $this->itemInstances[$item->getKey()] = $item; |
|
128 | 128 | |
129 | 129 | return $this; |
130 | 130 | } else { |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | { |
142 | 142 | $collection = []; |
143 | 143 | foreach ($keys as $key) { |
144 | - $collection[ $key ] = $this->getItem($key); |
|
144 | + $collection[$key] = $this->getItem($key); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | return $collection; |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | * @var ExtendedCacheItemInterface $item |
231 | 231 | */ |
232 | 232 | if (!array_key_exists($item->getKey(), $this->itemInstances)) { |
233 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
234 | - } else if(spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){ |
|
233 | + $this->itemInstances[$item->getKey()] = $item; |
|
234 | + } else if (spl_object_hash($item) !== spl_object_hash($this->itemInstances[$item->getKey()])) { |
|
235 | 235 | throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.'); |
236 | 236 | } |
237 | 237 | |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | public function saveDeferred(CacheItemInterface $item) |
262 | 262 | { |
263 | 263 | if (!array_key_exists($item->getKey(), $this->itemInstances)) { |
264 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
265 | - }else if(spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){ |
|
264 | + $this->itemInstances[$item->getKey()] = $item; |
|
265 | + } else if (spl_object_hash($item) !== spl_object_hash($this->itemInstances[$item->getKey()])) { |
|
266 | 266 | throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.'); |
267 | 267 | } |
268 | 268 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | */ |
274 | 274 | $this->eventManager->dispatch('CacheSaveDeferredItem', $this, $item); |
275 | 275 | |
276 | - return $this->deferredList[ $item->getKey() ] = $item; |
|
276 | + return $this->deferredList[$item->getKey()] = $item; |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | foreach ($this->deferredList as $key => $item) { |
294 | 294 | $result = $this->save($item); |
295 | 295 | if ($return !== false) { |
296 | - unset($this->deferredList[ $key ]); |
|
296 | + unset($this->deferredList[$key]); |
|
297 | 297 | $return = $result; |
298 | 298 | } |
299 | 299 | } |