@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | * @var array |
57 | 57 | */ |
58 | 58 | protected static $config = [ |
59 | - 'securityKey' => 'auto',// The securityKey that will be used to create sub-directory |
|
60 | - 'defaultTtl' => 900,// Default time-to-live in second |
|
61 | - 'htaccess' => true,// Auto-generate .htaccess if tit is missing |
|
62 | - 'default_chmod' => 0777, // 0777 recommended |
|
63 | - 'path' => '',// if not set will be the value of sys_get_temp_dir() |
|
64 | - 'fallback' => false, //Fall back when old driver is not support |
|
65 | - 'limited_memory_each_object' => 4096, // maximum size (bytes) of object store in memory |
|
66 | - 'compress_data' => false, // compress stored data, if the backend supports it |
|
59 | + 'securityKey' => 'auto',// The securityKey that will be used to create sub-directory |
|
60 | + 'defaultTtl' => 900,// Default time-to-live in second |
|
61 | + 'htaccess' => true,// Auto-generate .htaccess if tit is missing |
|
62 | + 'default_chmod' => 0777, // 0777 recommended |
|
63 | + 'path' => '',// if not set will be the value of sys_get_temp_dir() |
|
64 | + 'fallback' => false, //Fall back when old driver is not support |
|
65 | + 'limited_memory_each_object' => 4096, // maximum size (bytes) of object store in memory |
|
66 | + 'compress_data' => false, // compress stored data, if the backend supports it |
|
67 | 67 | ]; |
68 | 68 | |
69 | 69 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | } |
112 | 112 | } |
113 | 113 | } else if(++$badPracticeOmeter[$driver] >= 5){ |
114 | - trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. |
|
114 | + trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. |
|
115 | 115 | See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F'); |
116 | 116 | } |
117 | 117 | |
@@ -222,22 +222,22 @@ discard block |
||
222 | 222 | public static function getStaticSystemDrivers() |
223 | 223 | { |
224 | 224 | return [ |
225 | - 'Sqlite', |
|
226 | - 'Files', |
|
227 | - 'Apc', |
|
228 | - 'Apcu', |
|
229 | - 'Memcache', |
|
230 | - 'Memcached', |
|
231 | - 'Couchbase', |
|
232 | - 'Mongo', |
|
233 | - 'Mongodb', |
|
234 | - 'Predis', |
|
235 | - 'Redis', |
|
236 | - 'Ssdb', |
|
237 | - 'Leveldb', |
|
238 | - 'Wincache', |
|
239 | - 'Xcache', |
|
240 | - 'Devnull', |
|
225 | + 'Sqlite', |
|
226 | + 'Files', |
|
227 | + 'Apc', |
|
228 | + 'Apcu', |
|
229 | + 'Memcache', |
|
230 | + 'Memcached', |
|
231 | + 'Couchbase', |
|
232 | + 'Mongo', |
|
233 | + 'Mongodb', |
|
234 | + 'Predis', |
|
235 | + 'Redis', |
|
236 | + 'Ssdb', |
|
237 | + 'Leveldb', |
|
238 | + 'Wincache', |
|
239 | + 'Xcache', |
|
240 | + 'Devnull', |
|
241 | 241 | ]; |
242 | 242 | } |
243 | 243 |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | For MongoDb with Mongo PECL support use Mongo Driver.', E_USER_ERROR); |
68 | 68 | } |
69 | 69 | |
70 | - /* if(!class_exists('MongoDB\Driver\Collection')){ |
|
70 | + /* if(!class_exists('MongoDB\Driver\Collection')){ |
|
71 | 71 | trigger_error('The library mongo-php-library not found.<br /> |
72 | 72 | This driver do not support MonboDb low-level driver alone. Please install this driver to continue: https://github.com/mongodb/mongo-php-library', E_USER_ERROR); |
73 | 73 | } */ |
@@ -88,15 +88,15 @@ discard block |
||
88 | 88 | if ($item instanceof Item) { |
89 | 89 | try { |
90 | 90 | $result = (array) $this->getCollection()->updateMany( |
91 | - ['_id' => $item->getKey()], |
|
92 | - [ |
|
91 | + ['_id' => $item->getKey()], |
|
92 | + [ |
|
93 | 93 | '$set' => [ |
94 | - self::DRIVER_TIME_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time()*1000)), |
|
95 | - self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), |
|
96 | - self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), |
|
94 | + self::DRIVER_TIME_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time()*1000)), |
|
95 | + self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), |
|
96 | + self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), |
|
97 | 97 | ], |
98 | - ], |
|
99 | - ['upsert' => true, 'multiple' => false] |
|
98 | + ], |
|
99 | + ['upsert' => true, 'multiple' => false] |
|
100 | 100 | ); |
101 | 101 | } catch (MongoCursorException $e) { |
102 | 102 | return false; |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | protected function driverRead(CacheItemInterface $item) |
116 | 116 | { |
117 | 117 | $document = $this->getCollection() |
118 | - ->findOne(['_id' => $item->getKey()], |
|
118 | + ->findOne(['_id' => $item->getKey()], |
|
119 | 119 | [self::DRIVER_DATA_WRAPPER_INDEX, self::DRIVER_TIME_WRAPPER_INDEX, self::DRIVER_TAGS_WRAPPER_INDEX /*'d', 'e'*/]); |
120 | 120 | |
121 | 121 | if ($document) { |
122 | 122 | return [ |
123 | - self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()), |
|
124 | - self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_TIME_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
125 | - self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()), |
|
123 | + self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()), |
|
124 | + self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_TIME_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
125 | + self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()), |
|
126 | 126 | ]; |
127 | 127 | } else { |
128 | 128 | return null; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | if ($item instanceof Item) { |
143 | 143 | $deletionResult = (array) $this->getCollection()->deleteMany(['_id' => $item->getKey()], ["w" => 1]); |
144 | - // new driver has no results for deleteMany or deleteOne |
|
144 | + // new driver has no results for deleteMany or deleteOne |
|
145 | 145 | return true; |
146 | 146 | } else { |
147 | 147 | throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
@@ -177,12 +177,12 @@ discard block |
||
177 | 177 | * @todo make an url builder |
178 | 178 | */ |
179 | 179 | $this->instance = $this->instance ?: (new \MongoDB\Driver\Manager('mongodb://' . |
180 | - ($username ?: '') . |
|
181 | - ($password ? ":{$password}" : '') . |
|
182 | - ($username ? '@' : '') . "{$host}" . |
|
183 | - ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000])); |
|
184 | - $this->collection = $this->collection ?: new Collection($this->instance,'phpFastCache','Cache'); |
|
185 | - } |
|
180 | + ($username ?: '') . |
|
181 | + ($password ? ":{$password}" : '') . |
|
182 | + ($username ? '@' : '') . "{$host}" . |
|
183 | + ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000])); |
|
184 | + $this->collection = $this->collection ?: new Collection($this->instance,'phpFastCache','Cache'); |
|
185 | + } |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | |
@@ -206,25 +206,25 @@ discard block |
||
206 | 206 | public function getStats() |
207 | 207 | { |
208 | 208 | $serverStatus = $this->instance->executeCommand(new Command([ |
209 | - 'serverStatus' => 1, |
|
210 | - 'recordStats' => 0, |
|
211 | - 'repl' => 0, |
|
212 | - 'metrics' => 0, |
|
209 | + 'serverStatus' => 1, |
|
210 | + 'recordStats' => 0, |
|
211 | + 'repl' => 0, |
|
212 | + 'metrics' => 0, |
|
213 | 213 | ])); |
214 | 214 | |
215 | 215 | $collStats = $this->instance->executeCommand(new Command([ |
216 | - 'collStats' => 'Cache', |
|
217 | - 'verbose' => true, |
|
216 | + 'collStats' => 'Cache', |
|
217 | + 'verbose' => true, |
|
218 | 218 | ])); |
219 | 219 | |
220 | 220 | $stats = (new driverStatistic()) |
221 | - ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.") |
|
222 | - ->setSize((int) @$collStats[ 'size' ]) |
|
223 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
224 | - ->setRawData([ |
|
221 | + ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.") |
|
222 | + ->setSize((int) @$collStats[ 'size' ]) |
|
223 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
224 | + ->setRawData([ |
|
225 | 225 | 'serverStatus' => $serverStatus, |
226 | 226 | 'collStats' => $collStats, |
227 | - ]); |
|
227 | + ]); |
|
228 | 228 | |
229 | 229 | return $stats; |
230 | 230 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function driverCheck() |
64 | 64 | { |
65 | - if(!class_exists('MongoDB\Driver\Manager')){ |
|
65 | + if (!class_exists('MongoDB\Driver\Manager')) { |
|
66 | 66 | trigger_error('This driver is used to support the pecl MongoDb extension with mongo-php-library.<br /> |
67 | 67 | For MongoDb with Mongo PECL support use Mongo Driver.', E_USER_ERROR); |
68 | 68 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | ['_id' => $item->getKey()], |
92 | 92 | [ |
93 | 93 | '$set' => [ |
94 | - self::DRIVER_TIME_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time()*1000)), |
|
94 | + self::DRIVER_TIME_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)), |
|
95 | 95 | self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), |
96 | 96 | self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), |
97 | 97 | ], |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | return false; |
103 | 103 | } |
104 | 104 | |
105 | - return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true; |
|
105 | + return isset($result['ok']) ? $result['ok'] == 1 : true; |
|
106 | 106 | } else { |
107 | 107 | throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
108 | 108 | } |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | |
121 | 121 | if ($document) { |
122 | 122 | return [ |
123 | - self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()), |
|
124 | - self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_TIME_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
125 | - self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()), |
|
123 | + self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[self::DRIVER_DATA_WRAPPER_INDEX]->getData()), |
|
124 | + self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_TIME_WRAPPER_INDEX]->toDateTime()->getTimestamp()), |
|
125 | + self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[self::DRIVER_TAGS_WRAPPER_INDEX]->getData()), |
|
126 | 126 | ]; |
127 | 127 | } else { |
128 | 128 | return null; |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | if ($this->instance instanceof MongodbClient) { |
167 | 167 | throw new LogicException('Already connected to Mongodb server'); |
168 | 168 | } else { |
169 | - $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; |
|
170 | - $port = isset($server[ 'port' ]) ? $server[ 'port' ] : '27017'; |
|
171 | - $timeout = isset($server[ 'timeout' ]) ? $server[ 'timeout' ] : 3; |
|
172 | - $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; |
|
173 | - $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; |
|
169 | + $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1'; |
|
170 | + $port = isset($server['port']) ? $server['port'] : '27017'; |
|
171 | + $timeout = isset($server['timeout']) ? $server['timeout'] : 3; |
|
172 | + $password = isset($this->config['password']) ? $this->config['password'] : ''; |
|
173 | + $username = isset($this->config['username']) ? $this->config['username'] : ''; |
|
174 | 174 | |
175 | 175 | |
176 | 176 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ($password ? ":{$password}" : '') . |
182 | 182 | ($username ? '@' : '') . "{$host}" . |
183 | 183 | ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000])); |
184 | - $this->collection = $this->collection ?: new Collection($this->instance,'phpFastCache','Cache'); |
|
184 | + $this->collection = $this->collection ?: new Collection($this->instance, 'phpFastCache', 'Cache'); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
@@ -218,8 +218,8 @@ discard block |
||
218 | 218 | ])); |
219 | 219 | |
220 | 220 | $stats = (new driverStatistic()) |
221 | - ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.") |
|
222 | - ->setSize((int) @$collStats[ 'size' ]) |
|
221 | + ->setInfo('MongoDB version ' . $serverStatus['version'] . ', Uptime (in days): ' . round($serverStatus['uptime'] / 86400, 1) . "\n For more information see RawData.") |
|
222 | + ->setSize((int) @$collStats['size']) |
|
223 | 223 | ->setData(implode(', ', array_keys($this->itemInstances))) |
224 | 224 | ->setRawData([ |
225 | 225 | 'serverStatus' => $serverStatus, |