Skip to content

Commit

Permalink
Replacing self with static due to PHP5.3+. Following #7040.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Scherer committed Jul 21, 2015
1 parent 27e40f0 commit 52e7998
Show file tree
Hide file tree
Showing 53 changed files with 998 additions and 998 deletions.
142 changes: 71 additions & 71 deletions lib/Cake/Cache/Cache.php
Expand Up @@ -125,33 +125,33 @@ public static function config($name = null, $settings = array()) {
}

$current = array();
if (isset(self::$_config[$name])) {
$current = self::$_config[$name];
if (isset(static::$_config[$name])) {
$current = static::$_config[$name];
}

if (!empty($settings)) {
self::$_config[$name] = $settings + $current;
static::$_config[$name] = $settings + $current;
}

if (empty(self::$_config[$name]['engine'])) {
if (empty(static::$_config[$name]['engine'])) {
return false;
}

if (!empty(self::$_config[$name]['groups'])) {
foreach (self::$_config[$name]['groups'] as $group) {
self::$_groups[$group][] = $name;
sort(self::$_groups[$group]);
self::$_groups[$group] = array_unique(self::$_groups[$group]);
if (!empty(static::$_config[$name]['groups'])) {
foreach (static::$_config[$name]['groups'] as $group) {
static::$_groups[$group][] = $name;
sort(static::$_groups[$group]);
static::$_groups[$group] = array_unique(static::$_groups[$group]);
}
}

$engine = self::$_config[$name]['engine'];
$engine = static::$_config[$name]['engine'];

if (!isset(self::$_engines[$name])) {
self::_buildEngine($name);
$settings = self::$_config[$name] = self::settings($name);
} elseif ($settings = self::set(self::$_config[$name], null, $name)) {
self::$_config[$name] = $settings;
if (!isset(static::$_engines[$name])) {
static::_buildEngine($name);
$settings = static::$_config[$name] = static::settings($name);
} elseif ($settings = static::set(static::$_config[$name], null, $name)) {
static::$_config[$name] = $settings;
}
return compact('engine', 'settings');
}
Expand All @@ -164,7 +164,7 @@ public static function config($name = null, $settings = array()) {
* @throws CacheException
*/
protected static function _buildEngine($name) {
$config = self::$_config[$name];
$config = static::$_config[$name];

list($plugin, $class) = pluginSplit($config['engine'], true);
$cacheClass = $class . 'Engine';
Expand All @@ -176,17 +176,17 @@ protected static function _buildEngine($name) {
if (!is_subclass_of($cacheClass, 'CacheEngine')) {
throw new CacheException(__d('cake_dev', 'Cache engines must use %s as a base class.', 'CacheEngine'));
}
self::$_engines[$name] = new $cacheClass();
if (!self::$_engines[$name]->init($config)) {
static::$_engines[$name] = new $cacheClass();
if (!static::$_engines[$name]->init($config)) {
$msg = __d(
'cake_dev',
'Cache engine "%s" is not properly configured. Ensure required extensions are installed, and credentials/permissions are correct',
$name
);
throw new CacheException($msg);
}
if (self::$_engines[$name]->settings['probability'] && time() % self::$_engines[$name]->settings['probability'] === 0) {
self::$_engines[$name]->gc();
if (static::$_engines[$name]->settings['probability'] && time() % static::$_engines[$name]->settings['probability'] === 0) {
static::$_engines[$name]->gc();
}
return true;
}
Expand All @@ -197,7 +197,7 @@ protected static function _buildEngine($name) {
* @return array Array of configured Cache config names.
*/
public static function configured() {
return array_keys(self::$_config);
return array_keys(static::$_config);
}

/**
Expand All @@ -209,10 +209,10 @@ public static function configured() {
* @return bool success of the removal, returns false when the config does not exist.
*/
public static function drop($name) {
if (!isset(self::$_config[$name])) {
if (!isset(static::$_config[$name])) {
return false;
}
unset(self::$_config[$name], self::$_engines[$name]);
unset(static::$_config[$name], static::$_engines[$name]);
return true;
}

Expand Down Expand Up @@ -243,29 +243,29 @@ public static function set($settings = array(), $value = null, $config = 'defaul
if (is_array($settings) && $value !== null) {
$config = $value;
}
if (!isset(self::$_config[$config]) || !isset(self::$_engines[$config])) {
if (!isset(static::$_config[$config]) || !isset(static::$_engines[$config])) {
return false;
}
if (!empty($settings)) {
self::$_reset = true;
static::$_reset = true;
}

if (self::$_reset === true) {
if (static::$_reset === true) {
if (empty($settings)) {
self::$_reset = false;
$settings = self::$_config[$config];
static::$_reset = false;
$settings = static::$_config[$config];
} else {
if (is_string($settings) && $value !== null) {
$settings = array($settings => $value);
}
$settings += self::$_config[$config];
$settings += static::$_config[$config];
if (isset($settings['duration']) && !is_numeric($settings['duration'])) {
$settings['duration'] = strtotime($settings['duration']) - time();
}
}
self::$_engines[$config]->settings = $settings;
static::$_engines[$config]->settings = $settings;
}
return self::settings($config);
return static::settings($config);
}

/**
Expand All @@ -278,7 +278,7 @@ public static function set($settings = array(), $value = null, $config = 'defaul
* @return void
*/
public static function gc($config = 'default', $expires = null) {
self::$_engines[$config]->gc($expires);
static::$_engines[$config]->gc($expires);
}

/**
Expand All @@ -300,29 +300,29 @@ public static function gc($config = 'default', $expires = null) {
* @return bool True if the data was successfully cached, false on failure
*/
public static function write($key, $value, $config = 'default') {
$settings = self::settings($config);
$settings = static::settings($config);

if (empty($settings)) {
return false;
}
if (!self::isInitialized($config)) {
if (!static::isInitialized($config)) {
return false;
}
$key = self::$_engines[$config]->key($key);
$key = static::$_engines[$config]->key($key);

if (!$key || is_resource($value)) {
return false;
}

$success = self::$_engines[$config]->write($settings['prefix'] . $key, $value, $settings['duration']);
self::set(null, $config);
$success = static::$_engines[$config]->write($settings['prefix'] . $key, $value, $settings['duration']);
static::set(null, $config);
if ($success === false && $value !== '') {
trigger_error(
__d('cake_dev',
"%s cache was unable to write '%s' to %s cache",
$config,
$key,
self::$_engines[$config]->settings['engine']
static::$_engines[$config]->settings['engine']
),
E_USER_WARNING
);
Expand All @@ -348,19 +348,19 @@ public static function write($key, $value, $config = 'default') {
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
*/
public static function read($key, $config = 'default') {
$settings = self::settings($config);
$settings = static::settings($config);

if (empty($settings)) {
return false;
}
if (!self::isInitialized($config)) {
if (!static::isInitialized($config)) {
return false;
}
$key = self::$_engines[$config]->key($key);
$key = static::$_engines[$config]->key($key);
if (!$key) {
return false;
}
return self::$_engines[$config]->read($settings['prefix'] . $key);
return static::$_engines[$config]->read($settings['prefix'] . $key);
}

/**
Expand All @@ -373,21 +373,21 @@ public static function read($key, $config = 'default') {
* or if there was an error fetching it.
*/
public static function increment($key, $offset = 1, $config = 'default') {
$settings = self::settings($config);
$settings = static::settings($config);

if (empty($settings)) {
return false;
}
if (!self::isInitialized($config)) {
if (!static::isInitialized($config)) {
return false;
}
$key = self::$_engines[$config]->key($key);
$key = static::$_engines[$config]->key($key);

if (!$key || !is_int($offset) || $offset < 0) {
return false;
}
$success = self::$_engines[$config]->increment($settings['prefix'] . $key, $offset);
self::set(null, $config);
$success = static::$_engines[$config]->increment($settings['prefix'] . $key, $offset);
static::set(null, $config);
return $success;
}

Expand All @@ -401,21 +401,21 @@ public static function increment($key, $offset = 1, $config = 'default') {
* or if there was an error fetching it
*/
public static function decrement($key, $offset = 1, $config = 'default') {
$settings = self::settings($config);
$settings = static::settings($config);

if (empty($settings)) {
return false;
}
if (!self::isInitialized($config)) {
if (!static::isInitialized($config)) {
return false;
}
$key = self::$_engines[$config]->key($key);
$key = static::$_engines[$config]->key($key);

if (!$key || !is_int($offset) || $offset < 0) {
return false;
}
$success = self::$_engines[$config]->decrement($settings['prefix'] . $key, $offset);
self::set(null, $config);
$success = static::$_engines[$config]->decrement($settings['prefix'] . $key, $offset);
static::set(null, $config);
return $success;
}

Expand All @@ -437,21 +437,21 @@ public static function decrement($key, $offset = 1, $config = 'default') {
* @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public static function delete($key, $config = 'default') {
$settings = self::settings($config);
$settings = static::settings($config);

if (empty($settings)) {
return false;
}
if (!self::isInitialized($config)) {
if (!static::isInitialized($config)) {
return false;
}
$key = self::$_engines[$config]->key($key);
$key = static::$_engines[$config]->key($key);
if (!$key) {
return false;
}

$success = self::$_engines[$config]->delete($settings['prefix'] . $key);
self::set(null, $config);
$success = static::$_engines[$config]->delete($settings['prefix'] . $key);
static::set(null, $config);
return $success;
}

Expand All @@ -463,11 +463,11 @@ public static function delete($key, $config = 'default') {
* @return bool True if the cache was successfully cleared, false otherwise
*/
public static function clear($check = false, $config = 'default') {
if (!self::isInitialized($config)) {
if (!static::isInitialized($config)) {
return false;
}
$success = self::$_engines[$config]->clear($check);
self::set(null, $config);
$success = static::$_engines[$config]->clear($check);
static::set(null, $config);
return $success;
}

Expand All @@ -479,11 +479,11 @@ public static function clear($check = false, $config = 'default') {
* @return bool True if the cache group was successfully cleared, false otherwise
*/
public static function clearGroup($group, $config = 'default') {
if (!self::isInitialized($config)) {
if (!static::isInitialized($config)) {
return false;
}
$success = self::$_engines[$config]->clearGroup($group);
self::set(null, $config);
$success = static::$_engines[$config]->clearGroup($group);
static::set(null, $config);
return $success;
}

Expand All @@ -497,7 +497,7 @@ public static function isInitialized($config = 'default') {
if (Configure::read('Cache.disable')) {
return false;
}
return isset(self::$_engines[$config]);
return isset(static::$_engines[$config]);
}

/**
Expand All @@ -508,8 +508,8 @@ public static function isInitialized($config = 'default') {
* @see Cache::config()
*/
public static function settings($name = 'default') {
if (!empty(self::$_engines[$name])) {
return self::$_engines[$name]->settings();
if (!empty(static::$_engines[$name])) {
return static::$_engines[$name]->settings();
}
return array();
}
Expand All @@ -535,10 +535,10 @@ public static function settings($name = 'default') {
*/
public static function groupConfigs($group = null) {
if ($group === null) {
return self::$_groups;
return static::$_groups;
}
if (isset(self::$_groups[$group])) {
return array($group => self::$_groups[$group]);
if (isset(static::$_groups[$group])) {
return array($group => static::$_groups[$group]);
}
throw new CacheException(__d('cake_dev', 'Invalid cache group %s', $group));
}
Expand Down Expand Up @@ -569,12 +569,12 @@ public static function groupConfigs($group = null) {
* @return mixed The results of the callable or unserialized results.
*/
public static function remember($key, $callable, $config = 'default') {
$existing = self::read($key, $config);
$existing = static::read($key, $config);
if ($existing !== false) {
return $existing;
}
$results = call_user_func($callable);
self::write($key, $results, $config);
static::write($key, $results, $config);
return $results;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Console/Command/ServerShell.php
Expand Up @@ -65,8 +65,8 @@ class ServerShell extends AppShell {
* @return void
*/
public function initialize() {
$this->_host = self::DEFAULT_HOST;
$this->_port = self::DEFAULT_PORT;
$this->_host = static::DEFAULT_HOST;
$this->_port = static::DEFAULT_PORT;
$this->_documentRoot = WWW_ROOT;
}

Expand Down Expand Up @@ -135,7 +135,7 @@ public function main() {
escapeshellarg($this->_documentRoot . '/index.php')
);

$port = ($this->_port == self::DEFAULT_PORT) ? '' : ':' . $this->_port;
$port = ($this->_port == static::DEFAULT_PORT) ? '' : ':' . $this->_port;
$this->out(__d('cake_console', 'built-in server is running in http://%s%s/', $this->_host, $port));
system($command);
}
Expand Down

0 comments on commit 52e7998

Please sign in to comment.