Skip to content

Commit

Permalink
Replaced self by static
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed May 31, 2012
1 parent 1e57bef commit 012e4b5
Show file tree
Hide file tree
Showing 45 changed files with 796 additions and 796 deletions.
122 changes: 61 additions & 61 deletions lib/Cake/Cache/Cache.php
Expand Up @@ -119,25 +119,25 @@ 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] = array_merge($current, $settings);
static::$_config[$name] = array_merge($current, $settings);
}

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

$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 @@ -150,7 +150,7 @@ public static function config($name = null, $settings = array()) {
* @throws CacheException
*/
protected static function _buildEngine($name) {
$config = self::$_config[$name];
$config = static::$_config[$name];

$cacheClass = App::classname($config['engine'], 'Cache/Engine', 'Engine');
if (!$cacheClass) {
Expand All @@ -159,10 +159,10 @@ protected static function _buildEngine($name) {
if (!is_subclass_of($cacheClass, 'Cake\Cache\CacheEngine')) {
throw new Error\CacheException(__d('cake_dev', 'Cache engines must use Cake\Cache\CacheEngine as a base class.'));
}
self::$_engines[$name] = new $cacheClass();
if (self::$_engines[$name]->init($config)) {
if (self::$_engines[$name]->settings['probability'] && time() % self::$_engines[$name]->settings['probability'] === 0) {
self::$_engines[$name]->gc();
static::$_engines[$name] = new $cacheClass();
if (static::$_engines[$name]->init($config)) {
if (static::$_engines[$name]->settings['probability'] && time() % static::$_engines[$name]->settings['probability'] === 0) {
static::$_engines[$name]->gc();
}
return true;
}
Expand All @@ -175,7 +175,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 @@ -187,10 +187,10 @@ public static function configured() {
* @return boolean 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 @@ -221,29 +221,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 = array_merge(self::$_config[$config], $settings);
$settings = array_merge(static::$_config[$config], $settings);
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 @@ -256,7 +256,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 @@ -280,29 +280,29 @@ public static function gc($config = 'default', $expires = null) {
* @return boolean 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 Down Expand Up @@ -330,19 +330,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 @@ -355,21 +355,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_integer($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 @@ -383,21 +383,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_integer($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 @@ -419,21 +419,21 @@ public static function decrement($key, $offset = 1, $config = 'default') {
* @return boolean 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 @@ -445,11 +445,11 @@ public static function delete($key, $config = 'default') {
* @return boolean 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 @@ -461,11 +461,11 @@ public static function clear($check = false, $config = 'default') {
* @return boolean 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 @@ -479,7 +479,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 @@ -490,8 +490,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 Down
10 changes: 5 additions & 5 deletions lib/Cake/Console/ConsoleErrorHandler.php
Expand Up @@ -40,10 +40,10 @@ class ConsoleErrorHandler {
* @return ConsoleOutput
*/
public static function getStderr() {
if (empty(self::$stderr)) {
self::$stderr = new ConsoleOutput('php://stderr');
if (empty(static::$stderr)) {
static::$stderr = new ConsoleOutput('php://stderr');
}
return self::$stderr;
return static::$stderr;
}

/**
Expand All @@ -53,7 +53,7 @@ public static function getStderr() {
* @return void
*/
public function handleException(\Exception $exception) {
$stderr = self::getStderr();
$stderr = static::getStderr();
$stderr->write(__d('cake_console', "<error>Error:</error> %s\n%s",
$exception->getMessage(),
$exception->getTraceAsString()
Expand All @@ -76,7 +76,7 @@ public function handleError($code, $description, $file = null, $line = null, $co
if (error_reporting() === 0) {
return;
}
$stderr = self::getStderr();
$stderr = static::getStderr();
list($name, $log) = ErrorHandler::mapErrorCode($code);
$message = __d('cake_console', '%s in [%s, line %s]', $description, $file, $line);
$stderr->write(__d('cake_console', "<error>%s Error:</error> %s\n", $name, $message));
Expand Down

0 comments on commit 012e4b5

Please sign in to comment.