mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-03 06:33:38 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -2,20 +2,18 @@
|
|||
/**
|
||||
* Redis storage engine for cache
|
||||
*
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Cache.Engine
|
||||
* @since CakePHP(tm) v 2.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -35,10 +33,12 @@ class RedisEngine extends CacheEngine {
|
|||
/**
|
||||
* Settings
|
||||
*
|
||||
* - server = string url or ip to the Redis server host
|
||||
* - server = string URL or ip to the Redis server host
|
||||
* - database = integer database number to use for connection
|
||||
* - port = integer port number to the Redis server (default: 6379)
|
||||
* - timeout = float timeout in seconds (default: 0)
|
||||
* - persistent = bool Connects to the Redis server with a persistent connection (default: true)
|
||||
* - persistent = boolean Connects to the Redis server with a persistent connection (default: true)
|
||||
* - unix_socket = path to the unix socket file (default: false)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -51,7 +51,7 @@ class RedisEngine extends CacheEngine {
|
|||
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
|
||||
*
|
||||
* @param array $settings array of setting for the engine
|
||||
* @return boolean True if the engine has been successfully initialized, false if not
|
||||
* @return bool True if the engine has been successfully initialized, false if not
|
||||
*/
|
||||
public function init($settings = array()) {
|
||||
if (!class_exists('Redis')) {
|
||||
|
@ -59,11 +59,14 @@ class RedisEngine extends CacheEngine {
|
|||
}
|
||||
parent::init(array_merge(array(
|
||||
'engine' => 'Redis',
|
||||
'prefix' => null,
|
||||
'prefix' => Inflector::slug(APP_DIR) . '_',
|
||||
'server' => '127.0.0.1',
|
||||
'database' => 0,
|
||||
'port' => 6379,
|
||||
'password' => false,
|
||||
'timeout' => 0,
|
||||
'persistent' => true
|
||||
'persistent' => true,
|
||||
'unix_socket' => false
|
||||
), $settings)
|
||||
);
|
||||
|
||||
|
@ -73,21 +76,29 @@ class RedisEngine extends CacheEngine {
|
|||
/**
|
||||
* Connects to a Redis server
|
||||
*
|
||||
* @return boolean True if Redis server was connected
|
||||
* @return bool True if Redis server was connected
|
||||
*/
|
||||
protected function _connect() {
|
||||
$return = false;
|
||||
try {
|
||||
$this->_Redis = new Redis();
|
||||
if (empty($this->settings['persistent'])) {
|
||||
if (!empty($this->settings['unix_socket'])) {
|
||||
$return = $this->_Redis->connect($this->settings['unix_socket']);
|
||||
} elseif (empty($this->settings['persistent'])) {
|
||||
$return = $this->_Redis->connect($this->settings['server'], $this->settings['port'], $this->settings['timeout']);
|
||||
} else {
|
||||
$return = $this->_Redis->pconnect($this->settings['server'], $this->settings['port'], $this->settings['timeout']);
|
||||
$persistentId = $this->settings['port'] . $this->settings['timeout'] . $this->settings['database'];
|
||||
$return = $this->_Redis->pconnect($this->settings['server'], $this->settings['port'], $this->settings['timeout'], $persistentId);
|
||||
}
|
||||
} catch (RedisException $e) {
|
||||
$return = false;
|
||||
}
|
||||
if (!$return) {
|
||||
return false;
|
||||
}
|
||||
return $return;
|
||||
if ($this->settings['password'] && !$this->_Redis->auth($this->settings['password'])) {
|
||||
return false;
|
||||
}
|
||||
return $this->_Redis->select($this->settings['database']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,13 +106,18 @@ class RedisEngine extends CacheEngine {
|
|||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param mixed $value Data to be cached
|
||||
* @param integer $duration How long to cache the data, in seconds
|
||||
* @return boolean True if the data was successfully cached, false on failure
|
||||
* @param int $duration How long to cache the data, in seconds
|
||||
* @return bool True if the data was successfully cached, false on failure
|
||||
*/
|
||||
public function write($key, $value, $duration) {
|
||||
if (!is_int($value)) {
|
||||
$value = serialize($value);
|
||||
}
|
||||
|
||||
if (!$this->_Redis->isConnected()) {
|
||||
$this->_connect();
|
||||
}
|
||||
|
||||
if ($duration === 0) {
|
||||
return $this->_Redis->set($key, $value);
|
||||
}
|
||||
|
@ -117,11 +133,11 @@ class RedisEngine extends CacheEngine {
|
|||
*/
|
||||
public function read($key) {
|
||||
$value = $this->_Redis->get($key);
|
||||
if (ctype_digit($value)) {
|
||||
$value = (int)$value;
|
||||
if (preg_match('/^[-]?\d+$/', $value)) {
|
||||
return (int)$value;
|
||||
}
|
||||
if ($value !== false && is_string($value)) {
|
||||
$value = unserialize($value);
|
||||
return unserialize($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
@ -130,7 +146,7 @@ class RedisEngine extends CacheEngine {
|
|||
* Increments the value of an integer cached key
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param integer $offset How much to increment
|
||||
* @param int $offset How much to increment
|
||||
* @return New incremented value, false otherwise
|
||||
* @throws CacheException when you try to increment with compress = true
|
||||
*/
|
||||
|
@ -142,7 +158,7 @@ class RedisEngine extends CacheEngine {
|
|||
* Decrements the value of an integer cached key
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param integer $offset How much to subtract
|
||||
* @param int $offset How much to subtract
|
||||
* @return New decremented value, false otherwise
|
||||
* @throws CacheException when you try to decrement with compress = true
|
||||
*/
|
||||
|
@ -154,7 +170,7 @@ class RedisEngine extends CacheEngine {
|
|||
* Delete a key from the cache
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
|
||||
* @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
|
||||
*/
|
||||
public function delete($key) {
|
||||
return $this->_Redis->delete($key) > 0;
|
||||
|
@ -163,8 +179,9 @@ class RedisEngine extends CacheEngine {
|
|||
/**
|
||||
* Delete all keys from the cache
|
||||
*
|
||||
* @param boolean $check
|
||||
* @return boolean True if the cache was successfully cleared, false otherwise
|
||||
* @param bool $check Whether or not expiration keys should be checked. If
|
||||
* true, no keys will be removed as cache will rely on redis TTL's.
|
||||
* @return bool True if the cache was successfully cleared, false otherwise
|
||||
*/
|
||||
public function clear($check) {
|
||||
if ($check) {
|
||||
|
@ -182,7 +199,7 @@ class RedisEngine extends CacheEngine {
|
|||
* the group accordingly.
|
||||
*
|
||||
* @return array
|
||||
**/
|
||||
*/
|
||||
public function groups() {
|
||||
$result = array();
|
||||
foreach ($this->settings['groups'] as $group) {
|
||||
|
@ -200,20 +217,42 @@ class RedisEngine extends CacheEngine {
|
|||
* Increments the group value to simulate deletion of all keys under a group
|
||||
* old values will remain in storage until they expire.
|
||||
*
|
||||
* @return boolean success
|
||||
**/
|
||||
* @param string $group The group name to clear.
|
||||
* @return bool success
|
||||
*/
|
||||
public function clearGroup($group) {
|
||||
return (bool)$this->_Redis->incr($this->settings['prefix'] . $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects from the redis server
|
||||
*
|
||||
* @return voind
|
||||
**/
|
||||
*/
|
||||
public function __destruct() {
|
||||
if (!$this->settings['persistent']) {
|
||||
$this->_Redis->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data for key into cache if it doesn't exist already.
|
||||
* If it already exists, it fails and returns false.
|
||||
*
|
||||
* @param string $key Identifier for the data.
|
||||
* @param mixed $value Data to be cached.
|
||||
* @param int $duration How long to cache the data, in seconds.
|
||||
* @return bool True if the data was successfully cached, false on failure.
|
||||
* @link https://github.com/phpredis/phpredis#setnx
|
||||
*/
|
||||
public function add($key, $value, $duration) {
|
||||
if (!is_int($value)) {
|
||||
$value = serialize($value);
|
||||
}
|
||||
|
||||
$result = $this->_Redis->setnx($key, $value);
|
||||
// setnx() doesn't have an expiry option, so overwrite the key with one
|
||||
if ($result) {
|
||||
return $this->_Redis->setex($key, $duration, $value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue