Update to CakePHP 2.8.0 copy in lib folder
This commit is contained in:
parent
28e94764d7
commit
b294f210dc
|
@ -26,12 +26,12 @@ App::uses('CacheEngine', 'Cache');
|
|||
* You can configure Cache engines in your application's `bootstrap.php` file. A sample configuration would
|
||||
* be
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* Cache::config('shared', array(
|
||||
* 'engine' => 'Apc',
|
||||
* 'prefix' => 'my_app_'
|
||||
* ));
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* This would configure an APC cache engine to the 'shared' alias. You could then read and write
|
||||
* to that cache alias by using it for the `$config` parameter in the various Cache methods. In
|
||||
|
@ -113,11 +113,11 @@ class Cache {
|
|||
* - `user` Used by Xcache. Username for XCache
|
||||
* - `password` Used by Xcache/Redis. Password for XCache/Redis
|
||||
*
|
||||
* @see app/Config/core.php for configuration settings
|
||||
* @param string $name Name of the configuration
|
||||
* @param array $settings Optional associative array of settings passed to the engine
|
||||
* @return array array(engine, settings) on success, false on failure
|
||||
* @throws CacheException
|
||||
* @see app/Config/core.php for configuration settings
|
||||
*/
|
||||
public static function config($name = null, $settings = array()) {
|
||||
if (is_array($name)) {
|
||||
|
@ -125,33 +125,33 @@ class Cache {
|
|||
}
|
||||
|
||||
$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');
|
||||
}
|
||||
|
@ -160,11 +160,11 @@ class Cache {
|
|||
* Finds and builds the instance of the required engine class.
|
||||
*
|
||||
* @param string $name Name of the config array that needs an engine instance built
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* @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';
|
||||
|
@ -176,12 +176,17 @@ class Cache {
|
|||
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)) {
|
||||
throw new CacheException(__d('cake_dev', 'Cache engine %s is not properly configured.', $name));
|
||||
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;
|
||||
}
|
||||
|
@ -192,22 +197,22 @@ class Cache {
|
|||
* @return array Array of configured Cache config names.
|
||||
*/
|
||||
public static function configured() {
|
||||
return array_keys(self::$_config);
|
||||
return array_keys(static::$_config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops a cache engine. Deletes the cache configuration information
|
||||
* If the deleted configuration is the last configuration using an certain engine,
|
||||
* If the deleted configuration is the last configuration using a certain engine,
|
||||
* the Engine instance is also unset.
|
||||
*
|
||||
* @param string $name A currently configured cache config you wish to remove.
|
||||
* @return boolean success of the removal, returns false when the config does not exist.
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
@ -238,29 +243,29 @@ class Cache {
|
|||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -269,11 +274,11 @@ class Cache {
|
|||
* Permanently remove all expired and deleted data
|
||||
*
|
||||
* @param string $config [optional] The config name you wish to have garbage collected. Defaults to 'default'
|
||||
* @param integer $expires [optional] An expires timestamp. Defaults to NULL
|
||||
* @return void
|
||||
* @param int $expires [optional] An expires timestamp. Defaults to NULL
|
||||
* @return bool
|
||||
*/
|
||||
public static function gc($config = 'default', $expires = null) {
|
||||
self::$_engines[$config]->gc($expires);
|
||||
return static::$_engines[$config]->gc($expires);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -292,32 +297,32 @@ class Cache {
|
|||
* @param string $key Identifier for the data
|
||||
* @param mixed $value Data to be cached - anything except a resource
|
||||
* @param string $config Optional string configuration name to write to. Defaults to 'default'
|
||||
* @return boolean True if the data was successfully cached, false on failure
|
||||
* @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
|
||||
);
|
||||
|
@ -343,46 +348,46 @@ class Cache {
|
|||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment a number under the key and return incremented value.
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param integer $offset How much to add
|
||||
* @param int $offset How much to add
|
||||
* @param string $config Optional string configuration name. Defaults to 'default'
|
||||
* @return mixed new value, or false if the data doesn't exist, is not integer,
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
@ -390,27 +395,27 @@ class Cache {
|
|||
* Decrement a number under the key and return decremented value.
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param integer $offset How much to subtract
|
||||
* @param int $offset How much to subtract
|
||||
* @param string $config Optional string configuration name. Defaults to 'default'
|
||||
* @return mixed new value, or false if the data doesn't exist, is not integer,
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
@ -429,40 +434,40 @@ class Cache {
|
|||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param string $config name of the configuration to use. Defaults to 'default'
|
||||
* @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 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all keys from the cache.
|
||||
*
|
||||
* @param boolean $check if true will check expiration, otherwise delete all
|
||||
* @param bool $check if true will check expiration, otherwise delete all
|
||||
* @param string $config name of the configuration to use. Defaults to 'default'
|
||||
* @return boolean True if the cache was successfully cleared, false otherwise
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
@ -471,14 +476,14 @@ class Cache {
|
|||
*
|
||||
* @param string $group name of the group to be cleared
|
||||
* @param string $config name of the configuration to use. Defaults to 'default'
|
||||
* @return boolean True if the cache group was successfully cleared, false otherwise
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
@ -486,13 +491,13 @@ class Cache {
|
|||
* Check if Cache has initialized a working config for the given name.
|
||||
*
|
||||
* @param string $config name of the configuration to use. Defaults to 'default'
|
||||
* @return boolean Whether or not the config name has been initialized.
|
||||
* @return bool Whether or not the config name has been initialized.
|
||||
*/
|
||||
public static function isInitialized($config = 'default') {
|
||||
if (Configure::read('Cache.disable')) {
|
||||
return false;
|
||||
}
|
||||
return isset(self::$_engines[$config]);
|
||||
return isset(static::$_engines[$config]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -503,8 +508,8 @@ class Cache {
|
|||
* @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();
|
||||
}
|
||||
|
@ -512,7 +517,7 @@ class Cache {
|
|||
/**
|
||||
* Retrieve group names to config mapping.
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* Cache::config('daily', array(
|
||||
* 'duration' => '1 day', 'groups' => array('posts')
|
||||
* ));
|
||||
|
@ -520,7 +525,7 @@ class Cache {
|
|||
* 'duration' => '1 week', 'groups' => array('posts', 'archive')
|
||||
* ));
|
||||
* $configs = Cache::groupConfigs('posts');
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* $config will equal to `array('posts' => array('daily', 'weekly'))`
|
||||
*
|
||||
|
@ -530,10 +535,10 @@ class Cache {
|
|||
*/
|
||||
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));
|
||||
}
|
||||
|
@ -549,27 +554,66 @@ class Cache {
|
|||
*
|
||||
* Using a Closure to provide data, assume $this is a Model:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* $model = $this;
|
||||
* $results = Cache::remember('all_articles', function() use ($model) {
|
||||
* return $model->find('all');
|
||||
* });
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* @param string $key The cache key to read/store data at.
|
||||
* @param callable $callable The callable that provides data in the case when
|
||||
* the cache key is empty. Can be any callable type supported by your PHP.
|
||||
* @param string $config The cache configuration to use for this operation.
|
||||
* Defaults to default.
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data for key into a cache engine if it doesn't exist already.
|
||||
*
|
||||
* ### Usage:
|
||||
*
|
||||
* Writing to the active cache config:
|
||||
*
|
||||
* `Cache::add('cached_data', $data);`
|
||||
*
|
||||
* Writing to a specific cache config:
|
||||
*
|
||||
* `Cache::add('cached_data', $data, 'long_term');`
|
||||
*
|
||||
* @param string $key Identifier for the data.
|
||||
* @param mixed $value Data to be cached - anything except a resource.
|
||||
* @param string $config Optional string configuration name to write to. Defaults to 'default'.
|
||||
* @return bool True if the data was successfully cached, false on failure.
|
||||
* Or if the key existed already.
|
||||
*/
|
||||
public static function add($key, $value, $config = 'default') {
|
||||
$settings = self::settings($config);
|
||||
|
||||
if (empty($settings)) {
|
||||
return false;
|
||||
}
|
||||
if (!self::isInitialized($config)) {
|
||||
return false;
|
||||
}
|
||||
$key = self::$_engines[$config]->key($key);
|
||||
|
||||
if (!$key || is_resource($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$success = self::$_engines[$config]->add($settings['prefix'] . $key, $value, $settings['duration']);
|
||||
self::set(null, $config);
|
||||
return $success;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ abstract class CacheEngine {
|
|||
* Called automatically by the cache frontend
|
||||
*
|
||||
* @param array $settings Associative array of parameters 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()) {
|
||||
$settings += $this->settings + array(
|
||||
|
@ -67,7 +67,7 @@ abstract class CacheEngine {
|
|||
*
|
||||
* Permanently remove all expired and deleted data
|
||||
*
|
||||
* @param integer $expires [optional] An expires timestamp, invalidating all data before.
|
||||
* @param int $expires [optional] An expires timestamp, invalidating all data before.
|
||||
* @return void
|
||||
*/
|
||||
public function gc($expires = null) {
|
||||
|
@ -78,11 +78,22 @@ abstract class CacheEngine {
|
|||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param mixed $value Data to be cached
|
||||
* @param integer $duration How long to cache for.
|
||||
* @return boolean True if the data was successfully cached, false on failure
|
||||
* @param int $duration How long to cache for.
|
||||
* @return bool True if the data was successfully cached, false on failure
|
||||
*/
|
||||
abstract public function write($key, $value, $duration);
|
||||
|
||||
/**
|
||||
* Write value for a key into cache if it doesn't already exist
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param mixed $value Data to be cached
|
||||
* @param int $duration How long to cache for.
|
||||
* @return bool True if the data was successfully cached, false on failure
|
||||
*/
|
||||
public function add($key, $value, $duration) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a key from the cache
|
||||
*
|
||||
|
@ -95,7 +106,7 @@ abstract class CacheEngine {
|
|||
* Increment a number under the key and return incremented value
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param integer $offset How much to add
|
||||
* @param int $offset How much to add
|
||||
* @return New incremented value, false otherwise
|
||||
*/
|
||||
abstract public function increment($key, $offset = 1);
|
||||
|
@ -104,7 +115,7 @@ abstract class CacheEngine {
|
|||
* Decrement a number under the key and return decremented value
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param integer $offset How much to subtract
|
||||
* @param int $offset How much to subtract
|
||||
* @return New incremented value, false otherwise
|
||||
*/
|
||||
abstract public function decrement($key, $offset = 1);
|
||||
|
@ -113,15 +124,15 @@ abstract class 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
|
||||
*/
|
||||
abstract public function delete($key);
|
||||
|
||||
/**
|
||||
* Delete all keys from the cache
|
||||
*
|
||||
* @param boolean $check if true will check expiration, otherwise delete all
|
||||
* @return boolean True if the cache was successfully cleared, false otherwise
|
||||
* @param bool $check if true will check expiration, otherwise delete all
|
||||
* @return bool True if the cache was successfully cleared, false otherwise
|
||||
*/
|
||||
abstract public function clear($check);
|
||||
|
||||
|
@ -130,8 +141,8 @@ abstract class CacheEngine {
|
|||
* to decide whether actually delete the keys or just simulate it to achieve
|
||||
* the same result.
|
||||
*
|
||||
* @param string $groups name of the group to be cleared
|
||||
* @return boolean
|
||||
* @param string $group name of the group to be cleared
|
||||
* @return bool
|
||||
*/
|
||||
public function clearGroup($group) {
|
||||
return false;
|
||||
|
@ -176,5 +187,4 @@ abstract class CacheEngine {
|
|||
$key = preg_replace('/[\s]+/', '_', strtolower(trim(str_replace(array(DS, '/', '.'), '_', strval($key)))));
|
||||
return $prefix . $key;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class ApcEngine 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
|
||||
* @see CacheEngine::__defaults
|
||||
*/
|
||||
public function init($settings = array()) {
|
||||
|
@ -55,8 +55,8 @@ class ApcEngine 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) {
|
||||
$expires = 0;
|
||||
|
@ -75,7 +75,7 @@ class ApcEngine extends CacheEngine {
|
|||
*/
|
||||
public function read($key) {
|
||||
$time = time();
|
||||
$cachetime = intval(apc_fetch($key . '_expires'));
|
||||
$cachetime = (int)apc_fetch($key . '_expires');
|
||||
if ($cachetime !== 0 && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ class ApcEngine 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
|
||||
*/
|
||||
public function increment($key, $offset = 1) {
|
||||
|
@ -97,7 +97,7 @@ class ApcEngine 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
|
||||
*/
|
||||
public function decrement($key, $offset = 1) {
|
||||
|
@ -108,7 +108,7 @@ class ApcEngine 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 apc_delete($key);
|
||||
|
@ -117,18 +117,25 @@ class ApcEngine extends CacheEngine {
|
|||
/**
|
||||
* Delete all keys from the cache. This will clear every cache config using APC.
|
||||
*
|
||||
* @param boolean $check If true, nothing will be cleared, as entries are removed
|
||||
* @param bool $check If true, nothing will be cleared, as entries are removed
|
||||
* from APC as they expired. This flag is really only used by FileEngine.
|
||||
* @return boolean True Returns true.
|
||||
* @return bool True Returns true.
|
||||
*/
|
||||
public function clear($check) {
|
||||
if ($check) {
|
||||
return true;
|
||||
}
|
||||
$info = apc_cache_info('user');
|
||||
$cacheKeys = $info['cache_list'];
|
||||
unset($info);
|
||||
foreach ($cacheKeys as $key) {
|
||||
if (class_exists('APCIterator', false)) {
|
||||
$iterator = new APCIterator(
|
||||
'user',
|
||||
'/^' . preg_quote($this->settings['prefix'], '/') . '/',
|
||||
APC_ITER_NONE
|
||||
);
|
||||
apc_delete($iterator);
|
||||
return true;
|
||||
}
|
||||
$cache = apc_cache_info('user');
|
||||
foreach ($cache['cache_list'] as $key) {
|
||||
if (strpos($key['info'], $this->settings['prefix']) === 0) {
|
||||
apc_delete($key['info']);
|
||||
}
|
||||
|
@ -173,11 +180,30 @@ class ApcEngine 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 to clear.
|
||||
* @return bool success
|
||||
*/
|
||||
public function clearGroup($group) {
|
||||
apc_inc($this->settings['prefix'] . $group, 1, $success);
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 http://php.net/manual/en/function.apc-add.php
|
||||
*/
|
||||
public function add($key, $value, $duration) {
|
||||
$expires = 0;
|
||||
if ($duration) {
|
||||
$expires = time() + $duration;
|
||||
}
|
||||
apc_add($key . '_expires', $expires, $duration);
|
||||
return apc_add($key, $value, $duration);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ class FileEngine extends CacheEngine {
|
|||
/**
|
||||
* True unless FileEngine::__active(); fails
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_init = true;
|
||||
|
||||
|
@ -64,7 +64,7 @@ class FileEngine 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()) {
|
||||
$settings += array(
|
||||
|
@ -93,8 +93,8 @@ class FileEngine extends CacheEngine {
|
|||
/**
|
||||
* Garbage collection. Permanently remove all expired and deleted data
|
||||
*
|
||||
* @param integer $expires [optional] An expires timestamp, invalidating all data before.
|
||||
* @return boolean True if garbage collection was successful, false on failure
|
||||
* @param int $expires [optional] An expires timestamp, invalidating all data before.
|
||||
* @return bool True if garbage collection was successful, false on failure
|
||||
*/
|
||||
public function gc($expires = null) {
|
||||
return $this->clear(true);
|
||||
|
@ -105,11 +105,11 @@ class FileEngine extends CacheEngine {
|
|||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param mixed $data 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, $data, $duration) {
|
||||
if ($data === '' || !$this->_init) {
|
||||
if (!$this->_init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ class FileEngine extends CacheEngine {
|
|||
|
||||
$this->_File->rewind();
|
||||
$time = time();
|
||||
$cachetime = intval($this->_File->current());
|
||||
$cachetime = (int)$this->_File->current();
|
||||
|
||||
if ($cachetime !== false && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
|
||||
if ($this->settings['lock']) {
|
||||
|
@ -200,7 +200,7 @@ class FileEngine 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) {
|
||||
if ($this->_setKey($key) === false || !$this->_init) {
|
||||
|
@ -217,8 +217,8 @@ class FileEngine extends CacheEngine {
|
|||
/**
|
||||
* Delete all values from the cache
|
||||
*
|
||||
* @param boolean $check Optional - only delete expired cache items
|
||||
* @return boolean True if the cache was successfully cleared, false otherwise
|
||||
* @param bool $check Optional - only delete expired cache items
|
||||
* @return bool True if the cache was successfully cleared, false otherwise
|
||||
*/
|
||||
public function clear($check) {
|
||||
if (!$this->_init) {
|
||||
|
@ -255,8 +255,8 @@ class FileEngine extends CacheEngine {
|
|||
* Used to clear a directory of matching files.
|
||||
*
|
||||
* @param string $path The path to search.
|
||||
* @param integer $now The current timestamp
|
||||
* @param integer $threshold Any file not modified after this value will be deleted.
|
||||
* @param int $now The current timestamp
|
||||
* @param int $threshold Any file not modified after this value will be deleted.
|
||||
* @return void
|
||||
*/
|
||||
protected function _clearDirectory($path, $now, $threshold) {
|
||||
|
@ -271,11 +271,12 @@ class FileEngine extends CacheEngine {
|
|||
if (substr($entry, 0, $prefixLength) !== $this->settings['prefix']) {
|
||||
continue;
|
||||
}
|
||||
$filePath = $path . $entry;
|
||||
if (!file_exists($filePath) || is_dir($filePath)) {
|
||||
|
||||
try {
|
||||
$file = new SplFileObject($path . $entry, 'r');
|
||||
} catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
$file = new SplFileObject($path . $entry, 'r');
|
||||
|
||||
if ($threshold) {
|
||||
$mtime = $file->getMTime();
|
||||
|
@ -303,8 +304,8 @@ class FileEngine extends CacheEngine {
|
|||
/**
|
||||
* Not implemented
|
||||
*
|
||||
* @param string $key
|
||||
* @param integer $offset
|
||||
* @param string $key The key to decrement
|
||||
* @param int $offset The number to offset
|
||||
* @return void
|
||||
* @throws CacheException
|
||||
*/
|
||||
|
@ -315,8 +316,8 @@ class FileEngine extends CacheEngine {
|
|||
/**
|
||||
* Not implemented
|
||||
*
|
||||
* @param string $key
|
||||
* @param integer $offset
|
||||
* @param string $key The key to decrement
|
||||
* @param int $offset The number to offset
|
||||
* @return void
|
||||
* @throws CacheException
|
||||
*/
|
||||
|
@ -329,8 +330,8 @@ class FileEngine extends CacheEngine {
|
|||
* for the cache file the key is referring to.
|
||||
*
|
||||
* @param string $key The key
|
||||
* @param boolean $createKey Whether the key should be created if it doesn't exists, or not
|
||||
* @return boolean true if the cache key could be set, false otherwise
|
||||
* @param bool $createKey Whether the key should be created if it doesn't exists, or not
|
||||
* @return bool true if the cache key could be set, false otherwise
|
||||
*/
|
||||
protected function _setKey($key, $createKey = false) {
|
||||
$groups = null;
|
||||
|
@ -369,7 +370,7 @@ class FileEngine extends CacheEngine {
|
|||
/**
|
||||
* Determine is cache directory is writable
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
protected function _active() {
|
||||
$dir = new SplFileInfo($this->settings['path']);
|
||||
|
@ -405,7 +406,8 @@ class FileEngine extends CacheEngine {
|
|||
/**
|
||||
* Recursively deletes all files under any directory named as $group
|
||||
*
|
||||
* @return boolean success
|
||||
* @param string $group The group to clear.
|
||||
* @return bool success
|
||||
*/
|
||||
public function clearGroup($group) {
|
||||
$this->_File = null;
|
||||
|
@ -427,4 +429,21 @@ class FileEngine extends CacheEngine {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function add($key, $value, $duration) {
|
||||
$cachedValue = $this->read($key);
|
||||
if ($cachedValue === false) {
|
||||
return $this->write($key, $value, $duration);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* more information.
|
||||
*
|
||||
* @package Cake.Cache.Engine
|
||||
* @deprecated You should use the Memcached adapter instead.
|
||||
* @deprecated 3.0.0 You should use the Memcached adapter instead.
|
||||
*/
|
||||
class MemcacheEngine extends CacheEngine {
|
||||
|
||||
|
@ -59,7 +59,7 @@ class MemcacheEngine 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('Memcache')) {
|
||||
|
@ -104,7 +104,7 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @return array Array containing host, port
|
||||
*/
|
||||
protected function _parseServerString($server) {
|
||||
if ($server[0] === 'u') {
|
||||
if (strpos($server, 'unix://') === 0) {
|
||||
return array($server, 0);
|
||||
}
|
||||
if (substr($server, 0, 1) === '[') {
|
||||
|
@ -131,8 +131,8 @@ class MemcacheEngine 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
|
||||
* @see http://php.net/manual/en/memcache.set.php
|
||||
*/
|
||||
public function write($key, $value, $duration) {
|
||||
|
@ -156,7 +156,7 @@ class MemcacheEngine 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
|
||||
*/
|
||||
|
@ -173,7 +173,7 @@ class MemcacheEngine 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
|
||||
*/
|
||||
|
@ -190,7 +190,7 @@ class MemcacheEngine 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->_Memcache->delete($key);
|
||||
|
@ -199,8 +199,9 @@ class MemcacheEngine 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 If true no deletes will occur and instead CakePHP will rely
|
||||
* on key TTL values.
|
||||
* @return bool True if the cache was successfully cleared, false otherwise
|
||||
*/
|
||||
public function clear($check) {
|
||||
if ($check) {
|
||||
|
@ -231,8 +232,8 @@ class MemcacheEngine extends CacheEngine {
|
|||
* Connects to a server in connection pool
|
||||
*
|
||||
* @param string $host host ip address or name
|
||||
* @param integer $port Server port
|
||||
* @return boolean True if memcache server was connected
|
||||
* @param int $port Server port
|
||||
* @return bool True if memcache server was connected
|
||||
*/
|
||||
public function connect($host, $port = 11211) {
|
||||
if ($this->_Memcache->getServerStatus($host, $port) === 0) {
|
||||
|
@ -282,9 +283,30 @@ class MemcacheEngine 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 to clear.
|
||||
* @return bool success
|
||||
*/
|
||||
public function clearGroup($group) {
|
||||
return (bool)$this->_Memcache->increment($this->settings['prefix'] . $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data for key into cache if it doesn't exist already. When using memcached as your cache engine
|
||||
* remember that the Memcached PECL extension does not support cache expiry times greater
|
||||
* than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.
|
||||
* 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 http://php.net/manual/en/memcache.add.php
|
||||
*/
|
||||
public function add($key, $value, $duration) {
|
||||
if ($duration > 30 * DAY) {
|
||||
$duration = 0;
|
||||
}
|
||||
|
||||
return $this->_Memcache->add($key, $value, $this->settings['compress'], $duration);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ class MemcachedEngine extends CacheEngine {
|
|||
* - serialize = string, default => php. The serializer engine used to serialize data.
|
||||
* Available engines are php, igbinary and json. Beside php, the memcached extension
|
||||
* must be compiled with the appropriate serializer support.
|
||||
* - options - Additional options for the memcached client. Should be an array of option => value.
|
||||
* Use the Memcached::OPT_* constants as keys.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -70,7 +72,7 @@ class MemcachedEngine 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
|
||||
* @throws CacheException when you try use authentication without Memcached compiled with SASL support
|
||||
*/
|
||||
public function init($settings = array()) {
|
||||
|
@ -92,7 +94,8 @@ class MemcachedEngine extends CacheEngine {
|
|||
'persistent' => false,
|
||||
'login' => null,
|
||||
'password' => null,
|
||||
'serialize' => 'php'
|
||||
'serialize' => 'php',
|
||||
'options' => array()
|
||||
);
|
||||
parent::init($settings);
|
||||
|
||||
|
@ -104,7 +107,11 @@ class MemcachedEngine extends CacheEngine {
|
|||
return true;
|
||||
}
|
||||
|
||||
$this->_Memcached = new Memcached($this->settings['persistent'] ? (string)$this->settings['persistent'] : null);
|
||||
if (!$this->settings['persistent']) {
|
||||
$this->_Memcached = new Memcached();
|
||||
} else {
|
||||
$this->_Memcached = new Memcached((string)$this->settings['persistent']);
|
||||
}
|
||||
$this->_setOptions();
|
||||
|
||||
if (count($this->_Memcached->getServerList())) {
|
||||
|
@ -126,8 +133,14 @@ class MemcachedEngine extends CacheEngine {
|
|||
__d('cake_dev', 'Memcached extension is not build with SASL support')
|
||||
);
|
||||
}
|
||||
$this->_Memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
|
||||
$this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']);
|
||||
}
|
||||
if (is_array($this->settings['options'])) {
|
||||
foreach ($this->settings['options'] as $opt => $value) {
|
||||
$this->_Memcached->setOption($opt, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -136,6 +149,7 @@ class MemcachedEngine extends CacheEngine {
|
|||
* Settings the memcached instance
|
||||
*
|
||||
* @throws CacheException when the Memcached extension is not built with the desired serializer engine
|
||||
* @return void
|
||||
*/
|
||||
protected function _setOptions() {
|
||||
$this->_Memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
|
||||
|
@ -171,8 +185,9 @@ class MemcachedEngine extends CacheEngine {
|
|||
* @return array Array containing host, port
|
||||
*/
|
||||
protected function _parseServerString($server) {
|
||||
if ($server[0] === 'u') {
|
||||
return array($server, 0);
|
||||
$socketTransport = 'unix://';
|
||||
if (strpos($server, $socketTransport) === 0) {
|
||||
return array(substr($server, strlen($socketTransport)), 0);
|
||||
}
|
||||
if (substr($server, 0, 1) === '[') {
|
||||
$position = strpos($server, ']:');
|
||||
|
@ -193,13 +208,13 @@ class MemcachedEngine extends CacheEngine {
|
|||
|
||||
/**
|
||||
* Write data for key into cache. When using memcached as your cache engine
|
||||
* remember that the Memcached pecl extension does not support cache expiry times greater
|
||||
* remember that the Memcached PECL extension does not support cache expiry times greater
|
||||
* than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.
|
||||
*
|
||||
* @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
|
||||
* @see http://php.net/manual/en/memcache.set.php
|
||||
*/
|
||||
public function write($key, $value, $duration) {
|
||||
|
@ -224,7 +239,7 @@ class MemcachedEngine 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
|
||||
*/
|
||||
|
@ -236,7 +251,7 @@ class MemcachedEngine 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
|
||||
*/
|
||||
|
@ -248,7 +263,7 @@ class MemcachedEngine 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->_Memcached->delete($key);
|
||||
|
@ -257,8 +272,10 @@ class MemcachedEngine 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 If true no deletes will occur and instead CakePHP will rely
|
||||
* on key TTL values.
|
||||
* @return bool True if the cache was successfully cleared, false otherwise. Will
|
||||
* also return false if you are using a binary protocol.
|
||||
*/
|
||||
public function clear($check) {
|
||||
if ($check) {
|
||||
|
@ -266,6 +283,9 @@ class MemcachedEngine extends CacheEngine {
|
|||
}
|
||||
|
||||
$keys = $this->_Memcached->getAllKeys();
|
||||
if ($keys === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (strpos($key, $this->settings['prefix']) === 0) {
|
||||
|
@ -314,9 +334,30 @@ class MemcachedEngine 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 to clear.
|
||||
* @return bool success
|
||||
*/
|
||||
public function clearGroup($group) {
|
||||
return (bool)$this->_Memcached->increment($this->settings['prefix'] . $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data for key into cache if it doesn't exist already. When using memcached as your cache engine
|
||||
* remember that the Memcached pecl extension does not support cache expiry times greater
|
||||
* than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.
|
||||
* 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 http://php.net/manual/en/memcached.add.php
|
||||
*/
|
||||
public function add($key, $value, $duration) {
|
||||
if ($duration > 30 * DAY) {
|
||||
$duration = 0;
|
||||
}
|
||||
|
||||
return $this->_Memcached->add($key, $value, $duration);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ class RedisEngine extends CacheEngine {
|
|||
* - port = integer port number to the Redis server (default: 6379)
|
||||
* - timeout = float timeout in seconds (default: 0)
|
||||
* - 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
|
||||
*/
|
||||
|
@ -50,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')) {
|
||||
|
@ -58,13 +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)
|
||||
);
|
||||
|
||||
|
@ -74,28 +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 {
|
||||
$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;
|
||||
}
|
||||
if ($return && $this->settings['password']) {
|
||||
$return = $this->_Redis->auth($this->settings['password']);
|
||||
if ($this->settings['password'] && !$this->_Redis->auth($this->settings['password'])) {
|
||||
return false;
|
||||
}
|
||||
if ($return) {
|
||||
$return = $this->_Redis->select($this->settings['database']);
|
||||
}
|
||||
return $return;
|
||||
return $this->_Redis->select($this->settings['database']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,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);
|
||||
}
|
||||
|
@ -138,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
|
||||
*/
|
||||
|
@ -150,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
|
||||
*/
|
||||
|
@ -162,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;
|
||||
|
@ -171,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) {
|
||||
|
@ -208,7 +217,8 @@ 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);
|
||||
|
@ -222,4 +232,27 @@ class RedisEngine extends CacheEngine {
|
|||
$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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class WincacheEngine 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
|
||||
* @see CacheEngine::__defaults
|
||||
*/
|
||||
public function init($settings = array()) {
|
||||
|
@ -57,8 +57,8 @@ class WincacheEngine 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) {
|
||||
$expires = time() + $duration;
|
||||
|
@ -80,7 +80,7 @@ class WincacheEngine extends CacheEngine {
|
|||
*/
|
||||
public function read($key) {
|
||||
$time = time();
|
||||
$cachetime = intval(wincache_ucache_get($key . '_expires'));
|
||||
$cachetime = (int)wincache_ucache_get($key . '_expires');
|
||||
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
|
||||
return false;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ class WincacheEngine 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
|
||||
*/
|
||||
public function increment($key, $offset = 1) {
|
||||
|
@ -102,7 +102,7 @@ class WincacheEngine 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
|
||||
*/
|
||||
public function decrement($key, $offset = 1) {
|
||||
|
@ -113,7 +113,7 @@ class WincacheEngine 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 wincache_ucache_delete($key);
|
||||
|
@ -123,9 +123,9 @@ class WincacheEngine extends CacheEngine {
|
|||
* Delete all keys from the cache. This will clear every
|
||||
* item in the cache matching the cache config prefix.
|
||||
*
|
||||
* @param boolean $check If true, nothing will be cleared, as entries will
|
||||
* @param bool $check If true, nothing will be cleared, as entries will
|
||||
* naturally expire in wincache..
|
||||
* @return boolean True Returns true.
|
||||
* @return bool True Returns true.
|
||||
*/
|
||||
public function clear($check) {
|
||||
if ($check) {
|
||||
|
@ -179,7 +179,8 @@ class WincacheEngine 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 to clear.
|
||||
* @return bool success
|
||||
*/
|
||||
public function clearGroup($group) {
|
||||
$success = null;
|
||||
|
@ -187,4 +188,20 @@ class WincacheEngine extends CacheEngine {
|
|||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function add($key, $value, $duration) {
|
||||
$cachedValue = $this->read($key);
|
||||
if ($cachedValue === false) {
|
||||
return $this->write($key, $value, $duration);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,10 +41,10 @@ class XcacheEngine 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 (php_sapi_name() !== 'cli') {
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
parent::init(array_merge(array(
|
||||
'engine' => 'Xcache',
|
||||
'prefix' => Inflector::slug(APP_DIR) . '_',
|
||||
|
@ -62,8 +62,8 @@ class XcacheEngine 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) {
|
||||
$expires = time() + $duration;
|
||||
|
@ -80,7 +80,7 @@ class XcacheEngine extends CacheEngine {
|
|||
public function read($key) {
|
||||
if (xcache_isset($key)) {
|
||||
$time = time();
|
||||
$cachetime = intval(xcache_get($key . '_expires'));
|
||||
$cachetime = (int)xcache_get($key . '_expires');
|
||||
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
|
||||
return false;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ class XcacheEngine extends CacheEngine {
|
|||
* If the cache key is not an integer it will be treated as 0
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function increment($key, $offset = 1) {
|
||||
|
@ -106,7 +106,7 @@ class XcacheEngine extends CacheEngine {
|
|||
* If the cache key is not an integer it will be treated as 0
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function decrement($key, $offset = 1) {
|
||||
|
@ -117,7 +117,7 @@ class XcacheEngine 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 xcache_unset($key);
|
||||
|
@ -126,8 +126,9 @@ class XcacheEngine 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 If true no deletes will occur and instead CakePHP will rely
|
||||
* on key TTL values.
|
||||
* @return bool True if the cache was successfully cleared, false otherwise
|
||||
*/
|
||||
public function clear($check) {
|
||||
$this->_auth();
|
||||
|
@ -163,7 +164,8 @@ class XcacheEngine 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 to clear.
|
||||
* @return bool success
|
||||
*/
|
||||
public function clearGroup($group) {
|
||||
return (bool)xcache_inc($this->settings['prefix'] . $group, 1);
|
||||
|
@ -176,7 +178,7 @@ class XcacheEngine extends CacheEngine {
|
|||
* This has to be done because xcache_clear_cache() needs to pass Basic Http Auth
|
||||
* (see xcache.admin configuration settings)
|
||||
*
|
||||
* @param boolean $reverse Revert changes
|
||||
* @param bool $reverse Revert changes
|
||||
* @return void
|
||||
*/
|
||||
protected function _auth($reverse = false) {
|
||||
|
@ -205,4 +207,21 @@ class XcacheEngine extends CacheEngine {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function add($key, $value, $duration) {
|
||||
$cachedValue = $this->read($key);
|
||||
if ($cachedValue === false) {
|
||||
return $this->write($key, $value, $duration);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ if ($plugins = CakePlugin::loaded()) {
|
|||
$plugins[$key] = Inflector::underscore($value);
|
||||
}
|
||||
$pluginPattern = implode('|', $plugins);
|
||||
$match = array('plugin' => $pluginPattern);
|
||||
$shortParams = array('routeClass' => 'PluginShortRoute', 'plugin' => $pluginPattern);
|
||||
$match = array('plugin' => $pluginPattern, 'defaultRoute' => true);
|
||||
$shortParams = array('routeClass' => 'PluginShortRoute', 'plugin' => $pluginPattern, 'defaultRoute' => true);
|
||||
|
||||
foreach ($prefixes as $prefix) {
|
||||
$params = array('prefix' => $prefix, $prefix => true);
|
||||
|
@ -66,11 +66,11 @@ if ($plugins = CakePlugin::loaded()) {
|
|||
foreach ($prefixes as $prefix) {
|
||||
$params = array('prefix' => $prefix, $prefix => true);
|
||||
$indexParams = $params + array('action' => 'index');
|
||||
Router::connect("/{$prefix}/:controller", $indexParams);
|
||||
Router::connect("/{$prefix}/:controller/:action/*", $params);
|
||||
Router::connect("/{$prefix}/:controller", $indexParams, array('defaultRoute' => true));
|
||||
Router::connect("/{$prefix}/:controller/:action/*", $params, array('defaultRoute' => true));
|
||||
}
|
||||
Router::connect('/:controller', array('action' => 'index'));
|
||||
Router::connect('/:controller/:action/*');
|
||||
Router::connect('/:controller', array('action' => 'index'), array('defaultRoute' => true));
|
||||
Router::connect('/:controller/:action/*', array(), array('defaultRoute' => true));
|
||||
|
||||
$namedConfig = Router::namedConfig();
|
||||
if ($namedConfig['rules'] === false) {
|
||||
|
@ -79,3 +79,4 @@ if ($namedConfig['rules'] === false) {
|
|||
|
||||
unset($namedConfig, $params, $indexParams, $prefix, $prefixes, $shortParams, $match,
|
||||
$pluginPattern, $plugins, $key, $value);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ interface ConfigReaderInterface {
|
|||
* These sources can either be static resources like files, or dynamic ones like
|
||||
* a database, or other datasource.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $key Key to read.
|
||||
* @return array An array of data to merge into the runtime configuration
|
||||
*/
|
||||
public function read($key);
|
||||
|
@ -36,7 +36,7 @@ interface ConfigReaderInterface {
|
|||
*
|
||||
* @param string $key The identifier to write to.
|
||||
* @param array $data The data to dump.
|
||||
* @return boolean True on success or false on failure.
|
||||
* @return bool True on success or false on failure.
|
||||
*/
|
||||
public function dump($key, $data);
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
App::uses('Hash', 'Utility');
|
||||
App::uses('CakePlugin', 'Core');
|
||||
|
||||
/**
|
||||
* Ini file configuration engine.
|
||||
|
@ -33,10 +34,10 @@ App::uses('Hash', 'Utility');
|
|||
* You can nest properties as deeply as needed using `.`'s. In addition to using `.` you
|
||||
* can use standard ini section notation to create nested structures:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* [section]
|
||||
* key = value
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* Once loaded into Configure, the above would be accessed using:
|
||||
*
|
||||
|
@ -101,7 +102,7 @@ class IniReader implements ConfigReaderInterface {
|
|||
}
|
||||
|
||||
$file = $this->_getFilePath($key);
|
||||
if (!is_file($file)) {
|
||||
if (!is_file(realpath($file))) {
|
||||
throw new ConfigureException(__d('cake_dev', 'Could not load configuration file: %s', $file));
|
||||
}
|
||||
|
||||
|
@ -152,7 +153,7 @@ class IniReader implements ConfigReaderInterface {
|
|||
* @param string $key The identifier to write to. If the key has a . it will be treated
|
||||
* as a plugin prefix.
|
||||
* @param array $data The data to convert to ini file.
|
||||
* @return integer Bytes saved.
|
||||
* @return int Bytes saved.
|
||||
*/
|
||||
public function dump($key, $data) {
|
||||
$result = array();
|
||||
|
@ -181,7 +182,7 @@ class IniReader implements ConfigReaderInterface {
|
|||
/**
|
||||
* Converts a value into the ini equivalent
|
||||
*
|
||||
* @param mixed $value to export.
|
||||
* @param mixed $val Value to export.
|
||||
* @return string String value for ini file.
|
||||
*/
|
||||
protected function _value($val) {
|
||||
|
@ -218,7 +219,7 @@ class IniReader implements ConfigReaderInterface {
|
|||
}
|
||||
|
||||
if ($plugin) {
|
||||
$file = App::pluginPath($plugin) . 'Config' . DS . $key;
|
||||
$file = CakePlugin::path($plugin) . 'Config' . DS . $key;
|
||||
} else {
|
||||
$file = $this->_path . $key;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakePlugin', 'Core');
|
||||
|
||||
/**
|
||||
* PHP Reader allows Configure to load configuration values from
|
||||
* files containing simple PHP arrays.
|
||||
|
@ -49,7 +51,7 @@ class PhpReader implements ConfigReaderInterface {
|
|||
* Read a config file and return its contents.
|
||||
*
|
||||
* Files with `.` in the name will be treated as values in plugins. Instead of reading from
|
||||
* the initialized path, plugin keys will be located using App::pluginPath().
|
||||
* the initialized path, plugin keys will be located using CakePlugin::path().
|
||||
*
|
||||
* @param string $key The identifier to read from. If the key has a . it will be treated
|
||||
* as a plugin prefix.
|
||||
|
@ -63,7 +65,7 @@ class PhpReader implements ConfigReaderInterface {
|
|||
}
|
||||
|
||||
$file = $this->_getFilePath($key);
|
||||
if (!is_file($file)) {
|
||||
if (!is_file(realpath($file))) {
|
||||
throw new ConfigureException(__d('cake_dev', 'Could not load configuration file: %s', $file));
|
||||
}
|
||||
|
||||
|
@ -81,7 +83,7 @@ class PhpReader implements ConfigReaderInterface {
|
|||
* @param string $key The identifier to write to. If the key has a . it will be treated
|
||||
* as a plugin prefix.
|
||||
* @param array $data Data to dump.
|
||||
* @return integer Bytes saved.
|
||||
* @return int Bytes saved.
|
||||
*/
|
||||
public function dump($key, $data) {
|
||||
$contents = '<?php' . "\n" . '$config = ' . var_export($data, true) . ';';
|
||||
|
@ -105,7 +107,7 @@ class PhpReader implements ConfigReaderInterface {
|
|||
$key .= '.php';
|
||||
|
||||
if ($plugin) {
|
||||
$file = App::pluginPath($plugin) . 'Config' . DS . $key;
|
||||
$file = CakePlugin::path($plugin) . 'Config' . DS . $key;
|
||||
} else {
|
||||
$file = $this->_path . $key;
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ class AclShell extends AppShell {
|
|||
*
|
||||
* @param string $class Class name that is being used.
|
||||
* @param array $node Array of node information.
|
||||
* @param integer $indent indent level.
|
||||
* @param int $indent indent level.
|
||||
* @return void
|
||||
*/
|
||||
protected function _outputNode($class, $node, $indent) {
|
||||
|
@ -519,7 +519,7 @@ class AclShell extends AppShell {
|
|||
/**
|
||||
* Checks that given node exists
|
||||
*
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function nodeExists() {
|
||||
if (!isset($this->args[0]) || !isset($this->args[1])) {
|
||||
|
@ -558,8 +558,8 @@ class AclShell extends AppShell {
|
|||
* or an array of properties to use in AcoNode::node()
|
||||
*
|
||||
* @param string $class Class type you want (Aro/Aco)
|
||||
* @param string|array $identifier A mixed identifier for finding the node.
|
||||
* @return integer Integer of NodeId. Will trigger an error if nothing is found.
|
||||
* @param string|array|null $identifier A mixed identifier for finding the node, otherwise null.
|
||||
* @return int Integer of NodeId. Will trigger an error if nothing is found.
|
||||
*/
|
||||
protected function _getNodeId($class, $identifier) {
|
||||
$node = $this->Acl->{$class}->node($identifier);
|
||||
|
@ -568,7 +568,7 @@ class AclShell extends AppShell {
|
|||
$identifier = var_export($identifier, true);
|
||||
}
|
||||
$this->error(__d('cake_console', 'Could not find node using reference "%s"', $identifier));
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
return Hash::get($node, "0.{$class}.id");
|
||||
}
|
||||
|
@ -579,8 +579,8 @@ class AclShell extends AppShell {
|
|||
* @return array aro, aco, action
|
||||
*/
|
||||
protected function _getParams() {
|
||||
$aro = is_numeric($this->args[0]) ? intval($this->args[0]) : $this->args[0];
|
||||
$aco = is_numeric($this->args[1]) ? intval($this->args[1]) : $this->args[1];
|
||||
$aro = is_numeric($this->args[0]) ? (int)$this->args[0] : $this->args[0];
|
||||
$aco = is_numeric($this->args[1]) ? (int)$this->args[1] : $this->args[1];
|
||||
$aroName = $aro;
|
||||
$acoName = $aco;
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ class CommandListShell extends AppShell {
|
|||
/**
|
||||
* Output text.
|
||||
*
|
||||
* @param array $shellList
|
||||
* @param array $shellList The shell list.
|
||||
* @return void
|
||||
*/
|
||||
protected function _asText($shellList) {
|
||||
|
@ -95,7 +95,7 @@ class CommandListShell extends AppShell {
|
|||
/**
|
||||
* Output as XML
|
||||
*
|
||||
* @param array $shellList
|
||||
* @param array $shellList The shell list.
|
||||
* @return void
|
||||
*/
|
||||
protected function _asXml($shellList) {
|
||||
|
|
|
@ -144,7 +144,7 @@ class CompletionShell extends AppShell {
|
|||
/**
|
||||
* Emit results as a string, space delimited
|
||||
*
|
||||
* @param array $options
|
||||
* @param array $options The options to output
|
||||
* @return void
|
||||
*/
|
||||
protected function _output($options = array()) {
|
||||
|
|
|
@ -19,7 +19,7 @@ App::uses('AppShell', 'Console/Command');
|
|||
* Provides a very basic 'interactive' console for CakePHP apps.
|
||||
*
|
||||
* @package Cake.Console.Command
|
||||
* @deprecated Deprecated since version 2.4, will be removed in 3.0
|
||||
* @deprecated 3.0.0 Deprecated since version 2.4, will be removed in 3.0
|
||||
*/
|
||||
class ConsoleShell extends AppShell {
|
||||
|
||||
|
@ -193,7 +193,7 @@ class ConsoleShell extends AppShell {
|
|||
/**
|
||||
* Override main() to handle action
|
||||
*
|
||||
* @param string $command
|
||||
* @param string $command The command to run.
|
||||
* @return void
|
||||
*/
|
||||
public function main($command = null) {
|
||||
|
@ -218,7 +218,7 @@ class ConsoleShell extends AppShell {
|
|||
/**
|
||||
* Determine the method to process the current command
|
||||
*
|
||||
* @param string $command
|
||||
* @param string $command The command to run.
|
||||
* @return string or false
|
||||
*/
|
||||
protected function _method($command) {
|
||||
|
@ -256,7 +256,7 @@ class ConsoleShell extends AppShell {
|
|||
/**
|
||||
* Bind an association
|
||||
*
|
||||
* @param mixed $command
|
||||
* @param mixed $command The command to run.
|
||||
* @return void
|
||||
*/
|
||||
protected function _bind($command) {
|
||||
|
@ -283,7 +283,7 @@ class ConsoleShell extends AppShell {
|
|||
/**
|
||||
* Unbind an association
|
||||
*
|
||||
* @param mixed $command
|
||||
* @param mixed $command The command to run.
|
||||
* @return void
|
||||
*/
|
||||
protected function _unbind($command) {
|
||||
|
@ -303,7 +303,7 @@ class ConsoleShell extends AppShell {
|
|||
$validCurrentAssociation = false;
|
||||
|
||||
foreach ($currentAssociations as $model => $currentAssociation) {
|
||||
if ($model == $modelB && $association == $currentAssociation) {
|
||||
if ($model === $modelB && $association === $currentAssociation) {
|
||||
$validCurrentAssociation = true;
|
||||
}
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ class ConsoleShell extends AppShell {
|
|||
/**
|
||||
* Perform a find
|
||||
*
|
||||
* @param mixed $command
|
||||
* @param mixed $command The command to run.
|
||||
* @return void
|
||||
*/
|
||||
protected function _find($command) {
|
||||
|
@ -382,7 +382,7 @@ class ConsoleShell extends AppShell {
|
|||
/**
|
||||
* Save a record
|
||||
*
|
||||
* @param mixed $command
|
||||
* @param mixed $command The command to run.
|
||||
* @return void
|
||||
*/
|
||||
protected function _save($command) {
|
||||
|
@ -406,7 +406,7 @@ class ConsoleShell extends AppShell {
|
|||
/**
|
||||
* Show the columns for a model
|
||||
*
|
||||
* @param mixed $command
|
||||
* @param mixed $command The command to run.
|
||||
* @return void
|
||||
*/
|
||||
protected function _columns($command) {
|
||||
|
@ -455,7 +455,7 @@ class ConsoleShell extends AppShell {
|
|||
/**
|
||||
* Parse an array URL and show the equivalent URL as a string
|
||||
*
|
||||
* @param mixed $command
|
||||
* @param mixed $command The command to run.
|
||||
* @return void
|
||||
*/
|
||||
protected function _routeToString($command) {
|
||||
|
@ -471,7 +471,7 @@ class ConsoleShell extends AppShell {
|
|||
/**
|
||||
* Parse a string URL and show as an array
|
||||
*
|
||||
* @param mixed $command
|
||||
* @param mixed $command The command to run.
|
||||
* @return void
|
||||
*/
|
||||
protected function _routeToArray($command) {
|
||||
|
@ -483,8 +483,8 @@ class ConsoleShell extends AppShell {
|
|||
/**
|
||||
* Tells if the specified model is included in the list of available models
|
||||
*
|
||||
* @param string $modelToCheck
|
||||
* @return boolean true if is an available model, false otherwise
|
||||
* @param string $modelToCheck The model to check.
|
||||
* @return bool true if is an available model, false otherwise
|
||||
*/
|
||||
protected function _isValidModel($modelToCheck) {
|
||||
return in_array($modelToCheck, $this->models);
|
||||
|
@ -494,7 +494,7 @@ class ConsoleShell extends AppShell {
|
|||
* Reloads the routes configuration from app/Config/routes.php, and compiles
|
||||
* all routes found
|
||||
*
|
||||
* @return boolean True if config reload was a success, otherwise false
|
||||
* @return bool True if config reload was a success, otherwise false
|
||||
*/
|
||||
protected function _loadRoutes() {
|
||||
Router::reload();
|
||||
|
|
|
@ -39,7 +39,7 @@ class SchemaShell extends AppShell {
|
|||
/**
|
||||
* is this a dry run?
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_dry = null;
|
||||
|
||||
|
@ -66,13 +66,10 @@ class SchemaShell extends AppShell {
|
|||
list($this->params['plugin'], $splitName) = pluginSplit($name);
|
||||
$name = $this->params['name'] = $splitName;
|
||||
}
|
||||
|
||||
$defaultFile = 'schema.php';
|
||||
if (empty($this->params['file'])) {
|
||||
$this->params['file'] = $defaultFile;
|
||||
}
|
||||
if ($name && $this->params['file'] === $defaultFile) {
|
||||
if ($name && empty($this->params['file'])) {
|
||||
$this->params['file'] = Inflector::underscore($name);
|
||||
} elseif (empty($this->params['file'])) {
|
||||
$this->params['file'] = 'schema.php';
|
||||
}
|
||||
if (strpos($this->params['file'], '.php') === false) {
|
||||
$this->params['file'] .= '.php';
|
||||
|
@ -92,7 +89,7 @@ class SchemaShell extends AppShell {
|
|||
$name = $plugin;
|
||||
}
|
||||
}
|
||||
$name = Inflector::classify($name);
|
||||
$name = Inflector::camelize($name);
|
||||
$this->Schema = new CakeSchema(compact('name', 'path', 'file', 'connection', 'plugin'));
|
||||
}
|
||||
|
||||
|
@ -125,7 +122,7 @@ class SchemaShell extends AppShell {
|
|||
if ($this->params['force']) {
|
||||
$options['models'] = false;
|
||||
} elseif (!empty($this->params['models'])) {
|
||||
$options['models'] = String::tokenize($this->params['models']);
|
||||
$options['models'] = CakeText::tokenize($this->params['models']);
|
||||
}
|
||||
|
||||
$snapshot = false;
|
||||
|
@ -154,14 +151,14 @@ class SchemaShell extends AppShell {
|
|||
Configure::write('Cache.disable', $cacheDisable);
|
||||
|
||||
if (!empty($this->params['exclude']) && !empty($content)) {
|
||||
$excluded = String::tokenize($this->params['exclude']);
|
||||
$excluded = CakeText::tokenize($this->params['exclude']);
|
||||
foreach ($excluded as $table) {
|
||||
unset($content['tables'][$table]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($snapshot === true) {
|
||||
$fileName = rtrim($this->params['file'], '.php');
|
||||
$fileName = basename($this->params['file'], '.php');
|
||||
$Folder = new Folder($this->Schema->path);
|
||||
$result = $Folder->read();
|
||||
|
||||
|
@ -288,17 +285,17 @@ class SchemaShell extends AppShell {
|
|||
'connection' => $this->params['connection'],
|
||||
);
|
||||
if (!empty($this->params['snapshot'])) {
|
||||
$fileName = rtrim($this->Schema->file, '.php');
|
||||
$fileName = basename($this->Schema->file, '.php');
|
||||
$options['file'] = $fileName . '_' . $this->params['snapshot'] . '.php';
|
||||
}
|
||||
|
||||
$Schema = $this->Schema->load($options);
|
||||
|
||||
if (!$Schema) {
|
||||
$this->err(__d('cake_console', 'The chosen schema could not be loaded. Attempted to load:'));
|
||||
$this->err(__d('cake_console', 'File: %s', $this->Schema->path . DS . $this->Schema->file));
|
||||
$this->err(__d('cake_console', 'Name: %s', $this->Schema->name));
|
||||
return $this->_stop();
|
||||
$this->err(__d('cake_console', '<error>Error</error>: The chosen schema could not be loaded. Attempted to load:'));
|
||||
$this->err(__d('cake_console', '- file: %s', $this->Schema->path . DS . $this->Schema->file));
|
||||
$this->err(__d('cake_console', '- name: %s', $this->Schema->name));
|
||||
return $this->_stop(2);
|
||||
}
|
||||
$table = null;
|
||||
if (isset($this->args[1])) {
|
||||
|
@ -311,8 +308,8 @@ class SchemaShell extends AppShell {
|
|||
* Create database from Schema object
|
||||
* Should be called via the run method
|
||||
*
|
||||
* @param CakeSchema $Schema
|
||||
* @param string $table
|
||||
* @param CakeSchema $Schema The schema instance to create.
|
||||
* @param string $table The table name.
|
||||
* @return void
|
||||
*/
|
||||
protected function _create(CakeSchema $Schema, $table = null) {
|
||||
|
@ -337,8 +334,7 @@ class SchemaShell extends AppShell {
|
|||
$this->out("\n" . __d('cake_console', 'The following table(s) will be dropped.'));
|
||||
$this->out(array_keys($drop));
|
||||
|
||||
if (
|
||||
!empty($this->params['yes']) ||
|
||||
if (!empty($this->params['yes']) ||
|
||||
$this->in(__d('cake_console', 'Are you sure you want to drop the table(s)?'), array('y', 'n'), 'n') === 'y'
|
||||
) {
|
||||
$this->out(__d('cake_console', 'Dropping table(s).'));
|
||||
|
@ -348,8 +344,7 @@ class SchemaShell extends AppShell {
|
|||
$this->out("\n" . __d('cake_console', 'The following table(s) will be created.'));
|
||||
$this->out(array_keys($create));
|
||||
|
||||
if (
|
||||
!empty($this->params['yes']) ||
|
||||
if (!empty($this->params['yes']) ||
|
||||
$this->in(__d('cake_console', 'Are you sure you want to create the table(s)?'), array('y', 'n'), 'y') === 'y'
|
||||
) {
|
||||
$this->out(__d('cake_console', 'Creating table(s).'));
|
||||
|
@ -362,8 +357,8 @@ class SchemaShell extends AppShell {
|
|||
* Update database with Schema object
|
||||
* Should be called via the run method
|
||||
*
|
||||
* @param CakeSchema $Schema
|
||||
* @param string $table
|
||||
* @param CakeSchema &$Schema The schema instance
|
||||
* @param string $table The table name.
|
||||
* @return void
|
||||
*/
|
||||
protected function _update(&$Schema, $table = null) {
|
||||
|
@ -402,13 +397,15 @@ class SchemaShell extends AppShell {
|
|||
|
||||
$this->out("\n" . __d('cake_console', 'The following statements will run.'));
|
||||
$this->out(array_map('trim', $contents));
|
||||
if (
|
||||
!empty($this->params['yes']) ||
|
||||
if (!empty($this->params['yes']) ||
|
||||
$this->in(__d('cake_console', 'Are you sure you want to alter the tables?'), array('y', 'n'), 'n') === 'y'
|
||||
) {
|
||||
$this->out();
|
||||
$this->out(__d('cake_console', 'Updating Database...'));
|
||||
$this->_run($contents, 'update', $Schema);
|
||||
|
||||
Configure::write('Cache.disable', false);
|
||||
Cache::clear(false, '_cake_model_');
|
||||
}
|
||||
|
||||
$this->out(__d('cake_console', 'End update.'));
|
||||
|
@ -417,9 +414,9 @@ class SchemaShell extends AppShell {
|
|||
/**
|
||||
* Runs sql from _create() or _update()
|
||||
*
|
||||
* @param array $contents
|
||||
* @param string $event
|
||||
* @param CakeSchema $Schema
|
||||
* @param array $contents The contents to execute.
|
||||
* @param string $event The event to fire
|
||||
* @param CakeSchema $Schema The schema instance.
|
||||
* @return void
|
||||
*/
|
||||
protected function _run($contents, $event, CakeSchema $Schema) {
|
||||
|
@ -483,7 +480,6 @@ class SchemaShell extends AppShell {
|
|||
);
|
||||
$file = array(
|
||||
'help' => __d('cake_console', 'File name to read and write.'),
|
||||
'default' => 'schema.php'
|
||||
);
|
||||
$name = array(
|
||||
'help' => __d('cake_console',
|
||||
|
|
|
@ -34,7 +34,7 @@ class ServerShell extends AppShell {
|
|||
/**
|
||||
* Default ListenPort
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
const DEFAULT_PORT = 80;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -91,8 +91,8 @@ class ServerShell extends AppShell {
|
|||
$this->_documentRoot = $this->params['document_root'];
|
||||
}
|
||||
|
||||
// for windows
|
||||
if (substr($this->_documentRoot, -1, 1) == DIRECTORY_SEPARATOR) {
|
||||
// for Windows
|
||||
if (substr($this->_documentRoot, -1, 1) === DIRECTORY_SEPARATOR) {
|
||||
$this->_documentRoot = substr($this->_documentRoot, 0, strlen($this->_documentRoot) - 1);
|
||||
}
|
||||
if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_documentRoot, $m)) {
|
||||
|
@ -135,7 +135,7 @@ class ServerShell extends AppShell {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class BakeTask extends AppShell {
|
|||
/**
|
||||
* Flag for interactive mode
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $interactive = false;
|
||||
|
||||
|
|
|
@ -53,9 +53,9 @@ class CommandTask extends AppShell {
|
|||
/**
|
||||
* Scan the provided paths for shells, and append them into $shellList
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $shells
|
||||
* @param array $shellList
|
||||
* @param string $type The type of object.
|
||||
* @param array $shells The shell name.
|
||||
* @param array &$shellList List of shells.
|
||||
* @return void
|
||||
*/
|
||||
protected function _appendShells($type, $shells, &$shellList) {
|
||||
|
@ -90,7 +90,7 @@ class CommandTask extends AppShell {
|
|||
/**
|
||||
* Return a list of subcommands for a given command
|
||||
*
|
||||
* @param string $commandName
|
||||
* @param string $commandName The command you want subcommands from.
|
||||
* @return array
|
||||
*/
|
||||
public function subCommands($commandName) {
|
||||
|
@ -127,7 +127,7 @@ class CommandTask extends AppShell {
|
|||
/**
|
||||
* Get Shell instance for the given command
|
||||
*
|
||||
* @param mixed $commandName
|
||||
* @param mixed $commandName The command you want.
|
||||
* @return mixed
|
||||
*/
|
||||
public function getShell($commandName) {
|
||||
|
@ -157,7 +157,7 @@ class CommandTask extends AppShell {
|
|||
/**
|
||||
* Get Shell instance for the given command
|
||||
*
|
||||
* @param mixed $commandName
|
||||
* @param mixed $commandName The command to get options for.
|
||||
* @return array
|
||||
*/
|
||||
public function options($commandName) {
|
||||
|
|
|
@ -188,6 +188,7 @@ class ControllerTask extends BakeTask {
|
|||
if (strtolower($wannaUseSession) === 'y') {
|
||||
array_push($components, 'Session');
|
||||
}
|
||||
array_unique($components);
|
||||
}
|
||||
} else {
|
||||
list($wannaBakeCrud, $wannaBakeAdminCrud) = $this->_askAboutMethods();
|
||||
|
@ -224,10 +225,10 @@ class ControllerTask extends BakeTask {
|
|||
/**
|
||||
* Confirm a to be baked controller with the user
|
||||
*
|
||||
* @param string $controllerName
|
||||
* @param string $useDynamicScaffold
|
||||
* @param array $helpers
|
||||
* @param array $components
|
||||
* @param string $controllerName The name of the controller.
|
||||
* @param string $useDynamicScaffold Whether or not to use dynamic scaffolds.
|
||||
* @param array $helpers The list of helpers to include.
|
||||
* @param array $components The list of components to include.
|
||||
* @return void
|
||||
*/
|
||||
public function confirmController($controllerName, $useDynamicScaffold, $helpers, $components) {
|
||||
|
@ -247,10 +248,10 @@ class ControllerTask extends BakeTask {
|
|||
);
|
||||
|
||||
foreach ($properties as $var => $title) {
|
||||
if (count($$var)) {
|
||||
if (count(${$var})) {
|
||||
$output = '';
|
||||
$length = count($$var);
|
||||
foreach ($$var as $i => $propElement) {
|
||||
$length = count(${$var});
|
||||
foreach (${$var} as $i => $propElement) {
|
||||
if ($i != $length - 1) {
|
||||
$output .= ucfirst($propElement) . ', ';
|
||||
} else {
|
||||
|
@ -285,7 +286,7 @@ class ControllerTask extends BakeTask {
|
|||
*
|
||||
* @param string $controllerName Controller name
|
||||
* @param string $admin Admin route to use
|
||||
* @param boolean $wannaUseSession Set to true to use sessions, false otherwise
|
||||
* @param bool $wannaUseSession Set to true to use sessions, false otherwise
|
||||
* @return string Baked actions
|
||||
*/
|
||||
public function bakeActions($controllerName, $admin = null, $wannaUseSession = true) {
|
||||
|
@ -383,9 +384,9 @@ class ControllerTask extends BakeTask {
|
|||
* @return array Components the user wants to use.
|
||||
*/
|
||||
public function doComponents() {
|
||||
$components = array('Paginator');
|
||||
$components = array('Paginator', 'Flash');
|
||||
return array_merge($components, $this->_doPropertyChoices(
|
||||
__d('cake_console', "Would you like this controller to use other components\nbesides PaginatorComponent?"),
|
||||
__d('cake_console', "Would you like this controller to use other components\nbesides PaginatorComponent and FlashComponent?"),
|
||||
__d('cake_console', "Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'")
|
||||
));
|
||||
}
|
||||
|
@ -451,14 +452,14 @@ class ControllerTask extends BakeTask {
|
|||
return $this->_stop();
|
||||
}
|
||||
|
||||
if (!$enteredController || intval($enteredController) > count($controllers)) {
|
||||
if (!$enteredController || (int)$enteredController > count($controllers)) {
|
||||
$this->err(__d('cake_console', "The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again."));
|
||||
$enteredController = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (intval($enteredController) > 0 && intval($enteredController) <= count($controllers)) {
|
||||
$controllerName = $controllers[intval($enteredController) - 1];
|
||||
if ((int)$enteredController > 0 && (int)$enteredController <= count($controllers)) {
|
||||
$controllerName = $controllers[(int)$enteredController - 1];
|
||||
} else {
|
||||
$controllerName = Inflector::camelize($enteredController);
|
||||
}
|
||||
|
|
|
@ -199,8 +199,8 @@ class DbConfigTask extends AppShell {
|
|||
/**
|
||||
* Output verification message and bake if it looks good
|
||||
*
|
||||
* @param array $config
|
||||
* @return boolean True if user says it looks good, false otherwise
|
||||
* @param array $config The config data.
|
||||
* @return bool True if user says it looks good, false otherwise
|
||||
*/
|
||||
protected function _verify($config) {
|
||||
$config += $this->_defaultConfig;
|
||||
|
@ -247,7 +247,7 @@ class DbConfigTask extends AppShell {
|
|||
* Assembles and writes database.php
|
||||
*
|
||||
* @param array $configs Configuration settings to use
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function bake($configs) {
|
||||
if (!is_dir($this->path)) {
|
||||
|
@ -296,7 +296,7 @@ class DbConfigTask extends AppShell {
|
|||
|
||||
foreach ($oldConfigs as $key => $oldConfig) {
|
||||
foreach ($configs as $config) {
|
||||
if ($oldConfig['name'] == $config['name']) {
|
||||
if ($oldConfig['name'] === $config['name']) {
|
||||
unset($oldConfigs[$key]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class ExtractTask extends AppShell {
|
|||
/**
|
||||
* Merge all domain and category strings into the default.pot file
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_merge = false;
|
||||
|
||||
|
@ -70,7 +70,7 @@ class ExtractTask extends AppShell {
|
|||
protected $_tokens = array();
|
||||
|
||||
/**
|
||||
* Extracted strings indexed by category and domain.
|
||||
* Extracted strings indexed by category, domain, msgid and context.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -93,21 +93,21 @@ class ExtractTask extends AppShell {
|
|||
/**
|
||||
* Holds whether this call should extract model validation messages
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_extractValidation = true;
|
||||
|
||||
/**
|
||||
* Holds the validation string domain to use for validation messages when extracting
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_validationDomain = 'default';
|
||||
|
||||
/**
|
||||
* Holds whether this call should extract the CakePHP Lib messages
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_extractCore = false;
|
||||
|
||||
|
@ -127,7 +127,7 @@ class ExtractTask extends AppShell {
|
|||
);
|
||||
$response = $this->in($message, null, $defaultPath);
|
||||
if (strtoupper($response) === 'Q') {
|
||||
$this->out(__d('cake_console', 'Extract Aborted'));
|
||||
$this->err(__d('cake_console', 'Extract Aborted'));
|
||||
return $this->_stop();
|
||||
} elseif (strtoupper($response) === 'D' && count($this->_paths)) {
|
||||
$this->out();
|
||||
|
@ -151,7 +151,7 @@ class ExtractTask extends AppShell {
|
|||
*/
|
||||
public function execute() {
|
||||
if (!empty($this->params['exclude'])) {
|
||||
$this->_exclude = explode(',', $this->params['exclude']);
|
||||
$this->_exclude = explode(',', str_replace('/', DS, $this->params['exclude']));
|
||||
}
|
||||
if (isset($this->params['files']) && !is_array($this->params['files'])) {
|
||||
$this->_files = explode(',', $this->params['files']);
|
||||
|
@ -204,7 +204,7 @@ class ExtractTask extends AppShell {
|
|||
while (true) {
|
||||
$response = $this->in($message, null, rtrim($this->_paths[0], DS) . DS . 'Locale');
|
||||
if (strtoupper($response) === 'Q') {
|
||||
$this->out(__d('cake_console', 'Extract Aborted'));
|
||||
$this->err(__d('cake_console', 'Extract Aborted'));
|
||||
return $this->_stop();
|
||||
} elseif ($this->_isPathUsable($response)) {
|
||||
$this->_output = $response . DS;
|
||||
|
@ -242,29 +242,33 @@ class ExtractTask extends AppShell {
|
|||
*
|
||||
* Takes care of duplicate translations
|
||||
*
|
||||
* @param string $category
|
||||
* @param string $domain
|
||||
* @param string $msgid
|
||||
* @param array $details
|
||||
* @param string $category The category
|
||||
* @param string $domain The domain
|
||||
* @param string $msgid The message string
|
||||
* @param array $details The file and line references
|
||||
* @return void
|
||||
*/
|
||||
protected function _addTranslation($category, $domain, $msgid, $details = array()) {
|
||||
if (empty($this->_translations[$category][$domain][$msgid])) {
|
||||
$this->_translations[$category][$domain][$msgid] = array(
|
||||
'msgid_plural' => false
|
||||
$context = '';
|
||||
if (isset($details['msgctxt'])) {
|
||||
$context = $details['msgctxt'];
|
||||
}
|
||||
|
||||
if (empty($this->_translations[$category][$domain][$msgid][$context])) {
|
||||
$this->_translations[$category][$domain][$msgid][$context] = array(
|
||||
'msgid_plural' => false,
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($details['msgid_plural'])) {
|
||||
$this->_translations[$category][$domain][$msgid]['msgid_plural'] = $details['msgid_plural'];
|
||||
$this->_translations[$category][$domain][$msgid][$context]['msgid_plural'] = $details['msgid_plural'];
|
||||
}
|
||||
|
||||
if (isset($details['file'])) {
|
||||
$line = 0;
|
||||
if (isset($details['line'])) {
|
||||
$line = $details['line'];
|
||||
}
|
||||
$this->_translations[$category][$domain][$msgid]['references'][$details['file']][] = $line;
|
||||
$this->_translations[$category][$domain][$msgid][$context]['references'][$details['file']][] = $line;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -312,6 +316,10 @@ class ExtractTask extends AppShell {
|
|||
))->addOption('merge', array(
|
||||
'help' => __d('cake_console', 'Merge all domain and category strings into the default.po file.'),
|
||||
'choices' => array('yes', 'no')
|
||||
))->addOption('no-location', array(
|
||||
'boolean' => true,
|
||||
'default' => false,
|
||||
'help' => __d('cake_console', 'Do not write lines with locations'),
|
||||
))->addOption('output', array(
|
||||
'help' => __d('cake_console', 'Full path to output directory.')
|
||||
))->addOption('files', array(
|
||||
|
@ -355,14 +363,14 @@ class ExtractTask extends AppShell {
|
|||
protected function _extractTokens() {
|
||||
foreach ($this->_files as $file) {
|
||||
$this->_file = $file;
|
||||
$this->out(__d('cake_console', 'Processing %s...', $file));
|
||||
$this->out(__d('cake_console', 'Processing %s...', $file), 1, Shell::VERBOSE);
|
||||
|
||||
$code = file_get_contents($file);
|
||||
$allTokens = token_get_all($code);
|
||||
|
||||
$this->_tokens = array();
|
||||
foreach ($allTokens as $token) {
|
||||
if (!is_array($token) || ($token[0] != T_WHITESPACE && $token[0] != T_INLINE_HTML)) {
|
||||
if (!is_array($token) || ($token[0] !== T_WHITESPACE && $token[0] !== T_INLINE_HTML)) {
|
||||
$this->_tokens[] = $token;
|
||||
}
|
||||
}
|
||||
|
@ -374,6 +382,15 @@ class ExtractTask extends AppShell {
|
|||
$this->_parse('__dc', array('domain', 'singular', 'category'));
|
||||
$this->_parse('__dn', array('domain', 'singular', 'plural'));
|
||||
$this->_parse('__dcn', array('domain', 'singular', 'plural', 'count', 'category'));
|
||||
|
||||
$this->_parse('__x', array('context', 'singular'));
|
||||
$this->_parse('__xn', array('context', 'singular', 'plural'));
|
||||
$this->_parse('__dx', array('domain', 'context', 'singular'));
|
||||
$this->_parse('__dxc', array('domain', 'context', 'singular', 'category'));
|
||||
$this->_parse('__dxn', array('domain', 'context', 'singular', 'plural'));
|
||||
$this->_parse('__dxcn', array('domain', 'context', 'singular', 'plural', 'count', 'category'));
|
||||
$this->_parse('__xc', array('context', 'singular', 'category'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -398,7 +415,7 @@ class ExtractTask extends AppShell {
|
|||
}
|
||||
|
||||
list($type, $string, $line) = $countToken;
|
||||
if (($type == T_STRING) && ($string == $functionName) && ($firstParenthesis === '(')) {
|
||||
if (($type == T_STRING) && ($string === $functionName) && ($firstParenthesis === '(')) {
|
||||
$position = $count;
|
||||
$depth = 0;
|
||||
|
||||
|
@ -414,11 +431,12 @@ class ExtractTask extends AppShell {
|
|||
$mapCount = count($map);
|
||||
$strings = $this->_getStrings($position, $mapCount);
|
||||
|
||||
if ($mapCount == count($strings)) {
|
||||
if ($mapCount === count($strings)) {
|
||||
extract(array_combine($map, $strings));
|
||||
$category = isset($category) ? $category : 6;
|
||||
$category = intval($category);
|
||||
$category = (int)$category;
|
||||
$categoryName = $categories[$category];
|
||||
|
||||
$domain = isset($domain) ? $domain : 'default';
|
||||
$details = array(
|
||||
'file' => $this->_file,
|
||||
|
@ -427,8 +445,14 @@ class ExtractTask extends AppShell {
|
|||
if (isset($plural)) {
|
||||
$details['msgid_plural'] = $plural;
|
||||
}
|
||||
$this->_addTranslation($categoryName, $domain, $singular, $details);
|
||||
} else {
|
||||
if (isset($context)) {
|
||||
$details['msgctxt'] = $context;
|
||||
}
|
||||
// Skip LC_TIME files as we use a special file format for them.
|
||||
if ($categoryName !== 'LC_TIME') {
|
||||
$this->_addTranslation($categoryName, $domain, $singular, $details);
|
||||
}
|
||||
} elseif (!is_array($this->_tokens[$count - 1]) || $this->_tokens[$count - 1][0] != T_FUNCTION) {
|
||||
$this->_markerError($this->_file, $line, $functionName, $count);
|
||||
}
|
||||
}
|
||||
|
@ -547,32 +571,46 @@ class ExtractTask extends AppShell {
|
|||
protected function _buildFiles() {
|
||||
$paths = $this->_paths;
|
||||
$paths[] = realpath(APP) . DS;
|
||||
|
||||
usort($paths, function ($a, $b) {
|
||||
return strlen($b) - strlen($a);
|
||||
});
|
||||
|
||||
foreach ($this->_translations as $category => $domains) {
|
||||
foreach ($domains as $domain => $translations) {
|
||||
foreach ($translations as $msgid => $details) {
|
||||
$plural = $details['msgid_plural'];
|
||||
$files = $details['references'];
|
||||
$occurrences = array();
|
||||
foreach ($files as $file => $lines) {
|
||||
$lines = array_unique($lines);
|
||||
$occurrences[] = $file . ':' . implode(';', $lines);
|
||||
}
|
||||
$occurrences = implode("\n#: ", $occurrences);
|
||||
$header = '#: ' . str_replace(DS, '/', str_replace($paths, '', $occurrences)) . "\n";
|
||||
foreach ($translations as $msgid => $contexts) {
|
||||
foreach ($contexts as $context => $details) {
|
||||
$plural = $details['msgid_plural'];
|
||||
$header = '';
|
||||
if (empty($this->params['no-location'])) {
|
||||
$files = $details['references'];
|
||||
$occurrences = array();
|
||||
foreach ($files as $file => $lines) {
|
||||
$lines = array_unique($lines);
|
||||
$occurrences[] = $file . ':' . implode(';', $lines);
|
||||
}
|
||||
$occurrences = implode("\n#: ", $occurrences);
|
||||
$header = '#: ' . str_replace(DS, '/', str_replace($paths, '', $occurrences)) . "\n";
|
||||
}
|
||||
|
||||
if ($plural === false) {
|
||||
$sentence = "msgid \"{$msgid}\"\n";
|
||||
$sentence .= "msgstr \"\"\n\n";
|
||||
} else {
|
||||
$sentence = "msgid \"{$msgid}\"\n";
|
||||
$sentence .= "msgid_plural \"{$plural}\"\n";
|
||||
$sentence .= "msgstr[0] \"\"\n";
|
||||
$sentence .= "msgstr[1] \"\"\n\n";
|
||||
}
|
||||
$sentence = '';
|
||||
if ($context) {
|
||||
$sentence .= "msgctxt \"{$context}\"\n";
|
||||
}
|
||||
if ($plural === false) {
|
||||
$sentence .= "msgid \"{$msgid}\"\n";
|
||||
$sentence .= "msgstr \"\"\n\n";
|
||||
} else {
|
||||
$sentence .= "msgid \"{$msgid}\"\n";
|
||||
$sentence .= "msgid_plural \"{$plural}\"\n";
|
||||
$sentence .= "msgstr[0] \"\"\n";
|
||||
$sentence .= "msgstr[1] \"\"\n\n";
|
||||
}
|
||||
|
||||
$this->_store($category, $domain, $header, $sentence);
|
||||
if (($category !== 'LC_MESSAGES' || $domain !== 'default') && $this->_merge) {
|
||||
$this->_store('LC_MESSAGES', 'default', $header, $sentence);
|
||||
$this->_store($category, $domain, $header, $sentence);
|
||||
if (($category !== 'LC_MESSAGES' || $domain !== 'default') && $this->_merge) {
|
||||
$this->_store('LC_MESSAGES', 'default', $header, $sentence);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -582,10 +620,10 @@ class ExtractTask extends AppShell {
|
|||
/**
|
||||
* Prepare a file to be stored
|
||||
*
|
||||
* @param string $category
|
||||
* @param string $domain
|
||||
* @param string $header
|
||||
* @param string $sentence
|
||||
* @param string $category The category
|
||||
* @param string $domain The domain
|
||||
* @param string $header The header content.
|
||||
* @param string $sentence The sentence to store.
|
||||
* @return void
|
||||
*/
|
||||
protected function _store($category, $domain, $header, $sentence) {
|
||||
|
@ -664,7 +702,6 @@ class ExtractTask extends AppShell {
|
|||
$output .= "msgid \"\"\n";
|
||||
$output .= "msgstr \"\"\n";
|
||||
$output .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n";
|
||||
$output .= "\"POT-Creation-Date: " . date("Y-m-d H:iO") . "\\n\"\n";
|
||||
$output .= "\"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\\n\"\n";
|
||||
$output .= "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n";
|
||||
$output .= "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n";
|
||||
|
@ -678,8 +715,8 @@ class ExtractTask extends AppShell {
|
|||
/**
|
||||
* Get the strings from the position forward
|
||||
*
|
||||
* @param integer $position Actual position on tokens array
|
||||
* @param integer $target Number of strings to extract
|
||||
* @param int &$position Actual position on tokens array
|
||||
* @param int $target Number of strings to extract
|
||||
* @return array Strings extracted
|
||||
*/
|
||||
protected function _getStrings(&$position, $target) {
|
||||
|
@ -728,22 +765,22 @@ class ExtractTask extends AppShell {
|
|||
* Indicate an invalid marker on a processed file
|
||||
*
|
||||
* @param string $file File where invalid marker resides
|
||||
* @param integer $line Line number
|
||||
* @param int $line Line number
|
||||
* @param string $marker Marker found
|
||||
* @param integer $count Count
|
||||
* @param int $count Count
|
||||
* @return void
|
||||
*/
|
||||
protected function _markerError($file, $line, $marker, $count) {
|
||||
$this->out(__d('cake_console', "Invalid marker content in %s:%s\n* %s(", $file, $line, $marker));
|
||||
$this->err(__d('cake_console', "Invalid marker content in %s:%s\n* %s(", $file, $line, $marker));
|
||||
$count += 2;
|
||||
$tokenCount = count($this->_tokens);
|
||||
$parenthesis = 1;
|
||||
|
||||
while ((($tokenCount - $count) > 0) && $parenthesis) {
|
||||
if (is_array($this->_tokens[$count])) {
|
||||
$this->out($this->_tokens[$count][1], false);
|
||||
$this->err($this->_tokens[$count][1], false);
|
||||
} else {
|
||||
$this->out($this->_tokens[$count], false);
|
||||
$this->err($this->_tokens[$count], false);
|
||||
if ($this->_tokens[$count] === '(') {
|
||||
$parenthesis++;
|
||||
}
|
||||
|
@ -754,7 +791,7 @@ class ExtractTask extends AppShell {
|
|||
}
|
||||
$count++;
|
||||
}
|
||||
$this->out("\n", true);
|
||||
$this->err("\n", true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -774,26 +811,24 @@ class ExtractTask extends AppShell {
|
|||
}
|
||||
$pattern = '/' . implode('|', $exclude) . '/';
|
||||
}
|
||||
foreach ($this->_paths as $path) {
|
||||
$Folder = new Folder($path);
|
||||
foreach ($this->_paths as $i => $path) {
|
||||
$this->_paths[$i] = realpath($path) . DS;
|
||||
$Folder = new Folder($this->_paths[$i]);
|
||||
$files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true);
|
||||
if (!empty($pattern)) {
|
||||
foreach ($files as $i => $file) {
|
||||
if (preg_match($pattern, $file)) {
|
||||
unset($files[$i]);
|
||||
}
|
||||
}
|
||||
$files = preg_grep($pattern, $files, PREG_GREP_INVERT);
|
||||
$files = array_values($files);
|
||||
}
|
||||
$this->_files = array_merge($this->_files, $files);
|
||||
}
|
||||
$this->_files = array_unique($this->_files);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this execution is meant to extract string only from directories in folder represented by the
|
||||
* APP constant, i.e. this task is extracting strings from same application.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
protected function _isExtractingApp() {
|
||||
return $this->_paths === array(APP);
|
||||
|
@ -803,7 +838,7 @@ class ExtractTask extends AppShell {
|
|||
* Checks whether or not a given path is usable for writing.
|
||||
*
|
||||
* @param string $path Path to folder
|
||||
* @return boolean true if it exists and is writable, false otherwise
|
||||
* @return bool true if it exists and is writable, false otherwise
|
||||
*/
|
||||
protected function _isPathUsable($path) {
|
||||
return is_dir($path) && is_writable($path);
|
||||
|
|
|
@ -74,7 +74,7 @@ class FixtureTask extends BakeTask {
|
|||
))->addOption('count', array(
|
||||
'help' => __d('cake_console', 'When using generated data, the number of records to include in the fixture(s).'),
|
||||
'short' => 'n',
|
||||
'default' => 10
|
||||
'default' => 1
|
||||
))->addOption('connection', array(
|
||||
'help' => __d('cake_console', 'Which database configuration to use for baking.'),
|
||||
'short' => 'c',
|
||||
|
@ -210,7 +210,7 @@ class FixtureTask extends BakeTask {
|
|||
* @param string $model Name of model to bake.
|
||||
* @param string $useTable Name of table to use.
|
||||
* @param array $importOptions Options for public $import
|
||||
* @return string Baked fixture content
|
||||
* @return string|null Baked fixture content, otherwise null.
|
||||
*/
|
||||
public function bake($model, $useTable = false, $importOptions = array()) {
|
||||
App::uses('CakeSchema', 'Model');
|
||||
|
@ -242,8 +242,8 @@ class FixtureTask extends BakeTask {
|
|||
$this->_Schema = new CakeSchema();
|
||||
$data = $this->_Schema->read(array('models' => false, 'connection' => $this->connection));
|
||||
if (!isset($data['tables'][$useTable])) {
|
||||
$this->error('Could not find your selected table ' . $useTable);
|
||||
return false;
|
||||
$this->err("<warning>Warning:</warning> Could not find the '${useTable}' table for ${model}.");
|
||||
return null;
|
||||
}
|
||||
|
||||
$tableInfo = $data['tables'][$useTable];
|
||||
|
@ -316,7 +316,7 @@ class FixtureTask extends BakeTask {
|
|||
* Generate String representation of Records
|
||||
*
|
||||
* @param array $tableInfo Table schema array
|
||||
* @param integer $recordCount
|
||||
* @param int $recordCount The number of records to generate.
|
||||
* @return array Array of records to use in the fixture.
|
||||
*/
|
||||
protected function _generateRecords($tableInfo, $recordCount = 1) {
|
||||
|
@ -340,7 +340,7 @@ class FixtureTask extends BakeTask {
|
|||
isset($fieldInfo['length']) && $fieldInfo['length'] == 36
|
||||
);
|
||||
if ($isPrimaryUuid) {
|
||||
$insert = String::uuid();
|
||||
$insert = CakeText::uuid();
|
||||
} else {
|
||||
$insert = "Lorem ipsum dolor sit amet";
|
||||
if (!empty($fieldInfo['length'])) {
|
||||
|
@ -381,7 +381,7 @@ class FixtureTask extends BakeTask {
|
|||
}
|
||||
|
||||
/**
|
||||
* Convert a $records array into a a string.
|
||||
* Convert a $records array into a string.
|
||||
*
|
||||
* @param array $records Array of records to be converted to string
|
||||
* @return string A string value of the $records array.
|
||||
|
@ -414,19 +414,26 @@ class FixtureTask extends BakeTask {
|
|||
* @return array Array of records.
|
||||
*/
|
||||
protected function _getRecordsFromTable($modelName, $useTable = null) {
|
||||
$modelObject = new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
|
||||
if ($this->interactive) {
|
||||
$condition = null;
|
||||
$prompt = __d('cake_console', "Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1");
|
||||
while (!$condition) {
|
||||
$condition = $this->in($prompt, null, 'WHERE 1=1');
|
||||
}
|
||||
|
||||
$recordsFound = $modelObject->find('count', array(
|
||||
'conditions' => $condition,
|
||||
'recursive' => -1,
|
||||
));
|
||||
|
||||
$prompt = __d('cake_console', "How many records do you want to import?");
|
||||
$recordCount = $this->in($prompt, null, 10);
|
||||
$recordCount = $this->in($prompt, null, ($recordsFound < 10 ) ? $recordsFound : 10);
|
||||
} else {
|
||||
$condition = 'WHERE 1=1';
|
||||
$recordCount = (isset($this->params['count']) ? $this->params['count'] : 10);
|
||||
}
|
||||
$modelObject = new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
|
||||
|
||||
$records = $modelObject->find('all', array(
|
||||
'conditions' => $condition,
|
||||
'recursive' => -1,
|
||||
|
|
|
@ -161,8 +161,8 @@ class ModelTask extends BakeTask {
|
|||
*
|
||||
* @param array $options Array of options to use for the selections. indexes must start at 0
|
||||
* @param string $prompt Prompt to use for options list.
|
||||
* @param integer $default The default option for the given prompt.
|
||||
* @return integer Result of user choice.
|
||||
* @param int $default The default option for the given prompt.
|
||||
* @return int Result of user choice.
|
||||
*/
|
||||
public function inOptions($options, $prompt = null, $default = null) {
|
||||
$valid = false;
|
||||
|
@ -176,7 +176,7 @@ class ModelTask extends BakeTask {
|
|||
$prompt = __d('cake_console', 'Make a selection from the choices above');
|
||||
}
|
||||
$choice = $this->in($prompt, null, $default);
|
||||
if (intval($choice) > 0 && intval($choice) <= $max) {
|
||||
if ((int)$choice > 0 && (int)$choice <= $max) {
|
||||
$valid = true;
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ class ModelTask extends BakeTask {
|
|||
/**
|
||||
* Handles interactive baking
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
protected function _interactive() {
|
||||
$this->hr();
|
||||
|
@ -342,7 +342,7 @@ class ModelTask extends BakeTask {
|
|||
* Handles Generation and user interaction for creating validation.
|
||||
*
|
||||
* @param Model $model Model to have validations generated for.
|
||||
* @return array $validate Array of user selected validations.
|
||||
* @return array validate Array of user selected validations.
|
||||
*/
|
||||
public function doValidation($model) {
|
||||
if (!$model instanceof Model) {
|
||||
|
@ -383,6 +383,8 @@ class ModelTask extends BakeTask {
|
|||
if (class_exists('Validation')) {
|
||||
$options = get_class_methods('Validation');
|
||||
}
|
||||
$deprecatedOptions = array('notEmpty', 'between', 'ssn');
|
||||
$options = array_diff($options, $deprecatedOptions);
|
||||
sort($options);
|
||||
$default = 1;
|
||||
foreach ($options as $option) {
|
||||
|
@ -401,7 +403,7 @@ class ModelTask extends BakeTask {
|
|||
*
|
||||
* @param string $fieldName Name of field to be validated.
|
||||
* @param array $metaData metadata for field
|
||||
* @param string $primaryKey
|
||||
* @param string $primaryKey The primary key field.
|
||||
* @return array Array of validation for the field.
|
||||
*/
|
||||
public function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
|
||||
|
@ -443,9 +445,9 @@ class ModelTask extends BakeTask {
|
|||
} elseif ($metaData['type'] === 'string' && $metaData['length'] == 36) {
|
||||
$guess = $methods['uuid'];
|
||||
} elseif ($metaData['type'] === 'string') {
|
||||
$guess = $methods['notEmpty'];
|
||||
$guess = $methods['notBlank'];
|
||||
} elseif ($metaData['type'] === 'text') {
|
||||
$guess = $methods['notEmpty'];
|
||||
$guess = $methods['notBlank'];
|
||||
} elseif ($metaData['type'] === 'integer') {
|
||||
$guess = $methods['numeric'];
|
||||
} elseif ($metaData['type'] === 'float') {
|
||||
|
@ -460,6 +462,8 @@ class ModelTask extends BakeTask {
|
|||
$guess = $methods['datetime'];
|
||||
} elseif ($metaData['type'] === 'inet') {
|
||||
$guess = $methods['ip'];
|
||||
} elseif ($metaData['type'] === 'decimal') {
|
||||
$guess = $methods['decimal'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,7 +514,7 @@ class ModelTask extends BakeTask {
|
|||
/**
|
||||
* Handles associations
|
||||
*
|
||||
* @param Model $model
|
||||
* @param Model $model The model object
|
||||
* @return array Associations
|
||||
*/
|
||||
public function doAssociations($model) {
|
||||
|
@ -562,7 +566,7 @@ class ModelTask extends BakeTask {
|
|||
/**
|
||||
* Handles behaviors
|
||||
*
|
||||
* @param Model $model
|
||||
* @param Model $model The model object.
|
||||
* @return array Behaviors
|
||||
*/
|
||||
public function doActsAs($model) {
|
||||
|
@ -632,13 +636,13 @@ class ModelTask extends BakeTask {
|
|||
}
|
||||
foreach ($tempFieldNames as $fieldName) {
|
||||
$assoc = false;
|
||||
if ($fieldName != $model->primaryKey && $fieldName == $foreignKey) {
|
||||
if ($fieldName !== $model->primaryKey && $fieldName === $foreignKey) {
|
||||
$assoc = array(
|
||||
'alias' => $tempOtherModel->name,
|
||||
'className' => $tempOtherModel->name,
|
||||
'foreignKey' => $fieldName
|
||||
);
|
||||
} elseif ($otherTable == $model->table && $fieldName === 'parent_id') {
|
||||
} elseif ($otherTable === $model->table && $fieldName === 'parent_id') {
|
||||
$assoc = array(
|
||||
'alias' => 'Child' . $model->name,
|
||||
'className' => $model->name,
|
||||
|
@ -728,7 +732,7 @@ class ModelTask extends BakeTask {
|
|||
while (strtolower($wannaDoMoreAssoc) === 'y') {
|
||||
$assocs = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||
$this->out(__d('cake_console', 'What is the association type?'));
|
||||
$assocType = intval($this->inOptions($assocs, __d('cake_console', 'Enter a number')));
|
||||
$assocType = (int)$this->inOptions($assocs, __d('cake_console', 'Enter a number'));
|
||||
|
||||
$this->out(__d('cake_console', "For the following options be very careful to match your setup exactly.\n" .
|
||||
"Any spelling mistakes will cause errors."));
|
||||
|
@ -765,7 +769,7 @@ class ModelTask extends BakeTask {
|
|||
if (!empty($showKeys)) {
|
||||
$this->out(__d('cake_console', 'A helpful List of possible keys'));
|
||||
$foreignKey = $this->inOptions($showKeys, __d('cake_console', 'What is the foreignKey?'));
|
||||
$foreignKey = $showKeys[intval($foreignKey)];
|
||||
$foreignKey = $showKeys[(int)$foreignKey];
|
||||
}
|
||||
if (!isset($foreignKey)) {
|
||||
$foreignKey = $this->in(__d('cake_console', 'What is the foreignKey? Specify your own.'), null, $suggestedForeignKey);
|
||||
|
@ -812,7 +816,7 @@ class ModelTask extends BakeTask {
|
|||
* Assembles and writes a Model file.
|
||||
*
|
||||
* @param string|object $name Model name or object
|
||||
* @param array|boolean $data if array and $name is not an object assume bake data, otherwise boolean.
|
||||
* @param array|bool $data if array and $name is not an object assume bake data, otherwise boolean.
|
||||
* @return string
|
||||
*/
|
||||
public function bake($name, $data = array()) {
|
||||
|
@ -926,7 +930,7 @@ class ModelTask extends BakeTask {
|
|||
$tableIsGood = $this->in(__d('cake_console', 'Do you want to use this table?'), array('y', 'n'), 'y');
|
||||
}
|
||||
if (strtolower($tableIsGood) === 'n') {
|
||||
$useTable = $this->in(__d('cake_console', 'What is the name of the table?'));
|
||||
$useTable = $this->in(__d('cake_console', 'What is the name of the table (without prefix)?'));
|
||||
}
|
||||
}
|
||||
return $useTable;
|
||||
|
@ -985,14 +989,14 @@ class ModelTask extends BakeTask {
|
|||
return $this->_stop();
|
||||
}
|
||||
|
||||
if (!$enteredModel || intval($enteredModel) > count($this->_modelNames)) {
|
||||
if (!$enteredModel || (int)$enteredModel > count($this->_modelNames)) {
|
||||
$this->err(__d('cake_console', "The model name you supplied was empty,\n" .
|
||||
"or the number you selected was not an option. Please try again."));
|
||||
$enteredModel = '';
|
||||
}
|
||||
}
|
||||
if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_modelNames)) {
|
||||
return $this->_modelNames[intval($enteredModel) - 1];
|
||||
if ((int)$enteredModel > 0 && (int)$enteredModel <= count($this->_modelNames)) {
|
||||
return $this->_modelNames[(int)$enteredModel - 1];
|
||||
}
|
||||
|
||||
return $enteredModel;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
* The Plugin Task handles creating an empty plugin, ready to be used
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -73,7 +71,7 @@ class PluginTask extends AppShell {
|
|||
/**
|
||||
* Interactive interface
|
||||
*
|
||||
* @param string $plugin
|
||||
* @param string $plugin The plugin name.
|
||||
* @return void
|
||||
*/
|
||||
protected function _interactive($plugin = null) {
|
||||
|
@ -90,7 +88,7 @@ class PluginTask extends AppShell {
|
|||
* Bake the plugin, create directories and files
|
||||
*
|
||||
* @param string $plugin Name of the plugin in CamelCased format
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function bake($plugin) {
|
||||
$pathOptions = App::path('plugins');
|
||||
|
@ -108,18 +106,25 @@ class PluginTask extends AppShell {
|
|||
$Folder = new Folder($this->path . $plugin);
|
||||
$directories = array(
|
||||
'Config' . DS . 'Schema',
|
||||
'Model' . DS . 'Behavior',
|
||||
'Model' . DS . 'Datasource',
|
||||
'Console' . DS . 'Command' . DS . 'Task',
|
||||
'Console' . DS . 'Templates',
|
||||
'Controller' . DS . 'Component',
|
||||
'Lib',
|
||||
'View' . DS . 'Helper',
|
||||
'Locale' . DS . 'eng' . DS . 'LC_MESSAGES',
|
||||
'Model' . DS . 'Behavior',
|
||||
'Model' . DS . 'Datasource',
|
||||
'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component',
|
||||
'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper',
|
||||
'Test' . DS . 'Case' . DS . 'Lib',
|
||||
'Test' . DS . 'Case' . DS . 'Model' . DS . 'Behavior',
|
||||
'Test' . DS . 'Case' . DS . 'Model' . DS . 'Datasource',
|
||||
'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper',
|
||||
'Test' . DS . 'Fixture',
|
||||
'Vendor',
|
||||
'webroot'
|
||||
'View' . DS . 'Elements',
|
||||
'View' . DS . 'Helper',
|
||||
'View' . DS . 'Layouts',
|
||||
'webroot' . DS . 'css',
|
||||
'webroot' . DS . 'js',
|
||||
'webroot' . DS . 'img',
|
||||
);
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
|
@ -184,7 +189,7 @@ class PluginTask extends AppShell {
|
|||
/**
|
||||
* find and change $this->path to the user selection
|
||||
*
|
||||
* @param array $pathOptions
|
||||
* @param array $pathOptions The list of paths to look in.
|
||||
* @return void
|
||||
*/
|
||||
public function findPath($pathOptions) {
|
||||
|
@ -203,7 +208,7 @@ class PluginTask extends AppShell {
|
|||
}
|
||||
$prompt = __d('cake_console', 'Choose a plugin path from the paths above.');
|
||||
$choice = $this->in($prompt, null, 1);
|
||||
if (intval($choice) > 0 && intval($choice) <= $max) {
|
||||
if ((int)$choice > 0 && (int)$choice <= $max) {
|
||||
$valid = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
App::uses('AppShell', 'Console/Command');
|
||||
App::uses('File', 'Utility');
|
||||
App::uses('Folder', 'Utility');
|
||||
App::uses('String', 'Utility');
|
||||
App::uses('CakeText', 'Utility');
|
||||
App::uses('Security', 'Utility');
|
||||
|
||||
/**
|
||||
|
@ -142,7 +142,7 @@ class ProjectTask extends AppShell {
|
|||
/**
|
||||
* Checks PHP's include_path for CakePHP.
|
||||
*
|
||||
* @return boolean Indicates whether or not CakePHP exists on include_path
|
||||
* @return bool Indicates whether or not CakePHP exists on include_path
|
||||
*/
|
||||
public function cakeOnIncludePath() {
|
||||
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
|
||||
|
@ -212,7 +212,7 @@ class ProjectTask extends AppShell {
|
|||
}
|
||||
|
||||
foreach ($Folder->messages() as $message) {
|
||||
$this->out(String::wrap(' * ' . $message), 1, Shell::VERBOSE);
|
||||
$this->out(CakeText::wrap(' * ' . $message), 1, Shell::VERBOSE);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -231,14 +231,14 @@ class ProjectTask extends AppShell {
|
|||
* and points app/console/cake.php to the right place
|
||||
*
|
||||
* @param string $path Project path.
|
||||
* @return boolean success
|
||||
* @return bool success
|
||||
*/
|
||||
public function consolePath($path) {
|
||||
$File = new File($path . 'Console' . DS . 'cake.php');
|
||||
$contents = $File->read();
|
||||
if (preg_match('/(__CAKE_PATH__)/', $contents, $match)) {
|
||||
$root = strpos(CAKE_CORE_INCLUDE_PATH, '/') === 0 ? " \$ds . '" : "'";
|
||||
$replacement = $root . str_replace(DS, "' . \$ds . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "'";
|
||||
$root = strpos(CAKE_CORE_INCLUDE_PATH, '/') === 0 ? " DS . '" : "'";
|
||||
$replacement = $root . str_replace(DS, "' . DS . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "'";
|
||||
$result = str_replace($match[0], $replacement, $contents);
|
||||
if ($File->write($result)) {
|
||||
return true;
|
||||
|
@ -252,7 +252,7 @@ class ProjectTask extends AppShell {
|
|||
* Generates and writes 'Security.salt'
|
||||
*
|
||||
* @param string $path Project path
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function securitySalt($path) {
|
||||
$File = new File($path . 'Config' . DS . 'core.php');
|
||||
|
@ -272,7 +272,7 @@ class ProjectTask extends AppShell {
|
|||
* Generates and writes 'Security.cipherSeed'
|
||||
*
|
||||
* @param string $path Project path
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function securityCipherSeed($path) {
|
||||
$File = new File($path . 'Config' . DS . 'core.php');
|
||||
|
@ -293,7 +293,7 @@ class ProjectTask extends AppShell {
|
|||
* Writes cache prefix using app's name
|
||||
*
|
||||
* @param string $dir Path to project
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function cachePrefix($dir) {
|
||||
$app = basename($dir);
|
||||
|
@ -310,8 +310,8 @@ class ProjectTask extends AppShell {
|
|||
* Generates and writes CAKE_CORE_INCLUDE_PATH
|
||||
*
|
||||
* @param string $path Project path
|
||||
* @param boolean $hardCode Whether or not define calls should be hardcoded.
|
||||
* @return boolean Success
|
||||
* @param bool $hardCode Whether or not define calls should be hardcoded.
|
||||
* @return bool Success
|
||||
*/
|
||||
public function corePath($path, $hardCode = true) {
|
||||
if (dirname($path) !== CAKE_CORE_INCLUDE_PATH) {
|
||||
|
@ -331,8 +331,8 @@ class ProjectTask extends AppShell {
|
|||
* Replaces the __CAKE_PATH__ placeholder in the template files.
|
||||
*
|
||||
* @param string $filename The filename to operate on.
|
||||
* @param boolean $hardCode Whether or not the define should be uncommented.
|
||||
* @return boolean Success
|
||||
* @param bool $hardCode Whether or not the define should be uncommented.
|
||||
* @return bool Success
|
||||
*/
|
||||
protected function _replaceCorePath($filename, $hardCode) {
|
||||
$contents = file_get_contents($filename);
|
||||
|
@ -340,6 +340,11 @@ class ProjectTask extends AppShell {
|
|||
$root = strpos(CAKE_CORE_INCLUDE_PATH, '/') === 0 ? " DS . '" : "'";
|
||||
$corePath = $root . str_replace(DS, "' . DS . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "'";
|
||||
|
||||
$composer = ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib';
|
||||
if (file_exists($composer)) {
|
||||
$corePath = " ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib'";
|
||||
}
|
||||
|
||||
$result = str_replace('__CAKE_PATH__', $corePath, $contents, $count);
|
||||
if ($hardCode) {
|
||||
$result = str_replace('//define(\'CAKE_CORE', 'define(\'CAKE_CORE', $result);
|
||||
|
@ -354,7 +359,7 @@ class ProjectTask extends AppShell {
|
|||
* Enables Configure::read('Routing.prefixes') in /app/Config/core.php
|
||||
*
|
||||
* @param string $name Name to use as admin routing
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function cakeAdmin($name) {
|
||||
$path = (empty($this->configPath)) ? APP . 'Config' . DS : $this->configPath;
|
||||
|
|
|
@ -102,8 +102,8 @@ class TestTask extends BakeTask {
|
|||
/**
|
||||
* Handles interactive baking
|
||||
*
|
||||
* @param string $type
|
||||
* @return string|boolean
|
||||
* @param string $type The type of object to bake a test for.
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function _interactive($type = null) {
|
||||
$this->interactive = true;
|
||||
|
@ -129,7 +129,7 @@ class TestTask extends BakeTask {
|
|||
*
|
||||
* @param string $type Type of object to bake test case for ie. Model, Controller
|
||||
* @param string $className the 'cake name' for the class ie. Posts for the PostsController
|
||||
* @return string|boolean
|
||||
* @return string|bool
|
||||
*/
|
||||
public function bake($type, $className) {
|
||||
$plugin = null;
|
||||
|
@ -242,7 +242,7 @@ class TestTask extends BakeTask {
|
|||
* Currently only model, and controller are supported
|
||||
*
|
||||
* @param string $type The Type of object you are generating tests for eg. controller
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function typeCanDetectFixtures($type) {
|
||||
$type = strtolower($type);
|
||||
|
@ -254,7 +254,7 @@ class TestTask extends BakeTask {
|
|||
*
|
||||
* @param string $package The package of object you are generating tests for eg. controller
|
||||
* @param string $class the Classname of the class the test is being generated for.
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function isLoadableClass($package, $class) {
|
||||
App::uses($class, $package);
|
||||
|
@ -302,7 +302,7 @@ class TestTask extends BakeTask {
|
|||
|
||||
$position = strpos($class, $type);
|
||||
|
||||
if ($position !== false && strlen($class) - $position == strlen($type)) {
|
||||
if ($position !== false && (strlen($class) - $position) === strlen($type)) {
|
||||
return $class;
|
||||
}
|
||||
return $class . $type;
|
||||
|
@ -466,7 +466,7 @@ class TestTask extends BakeTask {
|
|||
* Controllers require a mock class.
|
||||
*
|
||||
* @param string $type The type of object tests are being generated for eg. controller.
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMockClass($type) {
|
||||
$type = strtolower($type);
|
||||
|
|
|
@ -89,7 +89,7 @@ class ViewTask extends BakeTask {
|
|||
$this->_interactive();
|
||||
}
|
||||
if (empty($this->args[0])) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (!isset($this->connection)) {
|
||||
$this->connection = 'default';
|
||||
|
@ -151,7 +151,7 @@ class ViewTask extends BakeTask {
|
|||
unset($methods[$i]);
|
||||
}
|
||||
}
|
||||
if ($method[0] === '_' || $method == strtolower($this->controllerName . 'Controller')) {
|
||||
if ($method[0] === '_' || $method === strtolower($this->controllerName . 'Controller')) {
|
||||
unset($methods[$i]);
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ class ViewTask extends BakeTask {
|
|||
$this->Controller->connection = $this->connection;
|
||||
$this->controllerName = $this->Controller->getName();
|
||||
|
||||
$prompt = __d('cake_console', "Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite %s views if it exist.", $this->controllerName);
|
||||
$prompt = __d('cake_console', "Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite %s views if they exist.", $this->controllerName);
|
||||
$interactive = $this->in($prompt, array('y', 'n'), 'n');
|
||||
|
||||
if (strtolower($interactive) === 'n') {
|
||||
|
@ -248,7 +248,7 @@ class ViewTask extends BakeTask {
|
|||
* 'singularHumanName', 'pluralHumanName', 'fields', 'foreignKeys',
|
||||
* 'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'
|
||||
*
|
||||
* @return array Returns an variables to be made available to a view template
|
||||
* @return array Returns a variables to be made available to a view template
|
||||
*/
|
||||
protected function _loadController() {
|
||||
if (!$this->controllerName) {
|
||||
|
@ -298,7 +298,7 @@ class ViewTask extends BakeTask {
|
|||
* Bake a view file for each of the supplied actions
|
||||
*
|
||||
* @param array $actions Array of actions to make files for.
|
||||
* @param array $vars
|
||||
* @param array $vars The template variables.
|
||||
* @return void
|
||||
*/
|
||||
public function bakeActions($actions, $vars) {
|
||||
|
@ -342,7 +342,7 @@ class ViewTask extends BakeTask {
|
|||
*
|
||||
* @param string $action Action to bake
|
||||
* @param string $content Content to write
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function bake($action, $content = '') {
|
||||
if ($content === true) {
|
||||
|
@ -454,8 +454,8 @@ class ViewTask extends BakeTask {
|
|||
/**
|
||||
* Returns associations for controllers models.
|
||||
*
|
||||
* @param Model $model
|
||||
* @return array $associations
|
||||
* @param Model $model The Model instance.
|
||||
* @return array associations
|
||||
*/
|
||||
protected function _associations(Model $model) {
|
||||
$keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||
|
|
|
@ -179,11 +179,11 @@ class TestShell extends Shell {
|
|||
/**
|
||||
* Parse the CLI options into an array CakeTestDispatcher can use.
|
||||
*
|
||||
* @return array Array of params for CakeTestDispatcher
|
||||
* @return array|null Array of params for CakeTestDispatcher or null.
|
||||
*/
|
||||
protected function _parseArgs() {
|
||||
if (empty($this->args)) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
$params = array(
|
||||
'core' => false,
|
||||
|
@ -222,6 +222,7 @@ class TestShell extends Shell {
|
|||
$options = array();
|
||||
$params = $this->params;
|
||||
unset($params['help']);
|
||||
unset($params['quiet']);
|
||||
|
||||
if (!empty($params['no-colors'])) {
|
||||
unset($params['no-colors'], $params['colors']);
|
||||
|
@ -334,9 +335,9 @@ class TestShell extends Shell {
|
|||
/**
|
||||
* Find the test case for the passed file. The file could itself be a test.
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $category
|
||||
* @param boolean $throwOnMissingFile
|
||||
* @param string $file The file to map.
|
||||
* @param string $category The test file category.
|
||||
* @param bool $throwOnMissingFile Whether or not to throw an exception.
|
||||
* @return array array(type, case)
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -411,7 +412,7 @@ class TestShell extends Shell {
|
|||
/**
|
||||
* For the given file, what category of test is it? returns app, core or the name of the plugin
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $file The file to map.
|
||||
* @return string
|
||||
*/
|
||||
protected function _mapFileToCategory($file) {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
App::uses('AppShell', 'Console/Command');
|
||||
App::uses('Folder', 'Utility');
|
||||
App::uses('CakePlugin', 'Core');
|
||||
|
||||
/**
|
||||
* A shell class to help developers upgrade applications to CakePHP 2.0
|
||||
|
@ -102,7 +103,7 @@ class UpgradeShell extends AppShell {
|
|||
public function tests() {
|
||||
$this->_paths = array(APP . 'tests' . DS);
|
||||
if (!empty($this->params['plugin'])) {
|
||||
$this->_paths = array(App::pluginPath($this->params['plugin']) . 'tests' . DS);
|
||||
$this->_paths = array(CakePlugin::path($this->params['plugin']) . 'tests' . DS);
|
||||
}
|
||||
$patterns = array(
|
||||
array(
|
||||
|
@ -128,7 +129,7 @@ class UpgradeShell extends AppShell {
|
|||
$cwd = getcwd();
|
||||
|
||||
if (!empty($this->params['plugin'])) {
|
||||
chdir(App::pluginPath($this->params['plugin']));
|
||||
chdir(CakePlugin::path($this->params['plugin']));
|
||||
}
|
||||
|
||||
if (is_dir('plugins')) {
|
||||
|
@ -215,7 +216,7 @@ class UpgradeShell extends AppShell {
|
|||
$this->_paths = array_diff(App::path('views'), App::core('views'));
|
||||
|
||||
if (!empty($this->params['plugin'])) {
|
||||
$this->_paths = array(App::pluginPath($this->params['plugin']) . 'views' . DS);
|
||||
$this->_paths = array(CakePlugin::path($this->params['plugin']) . 'views' . DS);
|
||||
}
|
||||
|
||||
$patterns = array();
|
||||
|
@ -229,7 +230,7 @@ class UpgradeShell extends AppShell {
|
|||
CakePlugin::load($plugin);
|
||||
$pluginHelpers = array_merge(
|
||||
$pluginHelpers,
|
||||
App::objects('helper', App::pluginPath($plugin) . DS . 'views' . DS . 'helpers' . DS, false)
|
||||
App::objects('helper', CakePlugin::path($plugin) . DS . 'views' . DS . 'helpers' . DS, false)
|
||||
);
|
||||
}
|
||||
$helpers = array_merge($pluginHelpers, $helpers);
|
||||
|
@ -260,7 +261,7 @@ class UpgradeShell extends AppShell {
|
|||
APP
|
||||
);
|
||||
if (!empty($this->params['plugin'])) {
|
||||
$this->_paths = array(App::pluginPath($this->params['plugin']));
|
||||
$this->_paths = array(CakePlugin::path($this->params['plugin']));
|
||||
}
|
||||
|
||||
$patterns = array(
|
||||
|
@ -299,7 +300,7 @@ class UpgradeShell extends AppShell {
|
|||
APP
|
||||
);
|
||||
if (!empty($this->params['plugin'])) {
|
||||
$this->_paths = array(App::pluginPath($this->params['plugin']));
|
||||
$this->_paths = array(CakePlugin::path($this->params['plugin']));
|
||||
}
|
||||
$patterns = array(
|
||||
array(
|
||||
|
@ -354,7 +355,7 @@ class UpgradeShell extends AppShell {
|
|||
$this->_paths = array_merge($views, $controllers, $components);
|
||||
|
||||
if (!empty($this->params['plugin'])) {
|
||||
$pluginPath = App::pluginPath($this->params['plugin']);
|
||||
$pluginPath = CakePlugin::path($this->params['plugin']);
|
||||
$this->_paths = array(
|
||||
$pluginPath . 'controllers' . DS,
|
||||
$pluginPath . 'controllers' . DS . 'components' . DS,
|
||||
|
@ -411,7 +412,7 @@ class UpgradeShell extends AppShell {
|
|||
APP
|
||||
);
|
||||
if (!empty($this->params['plugin'])) {
|
||||
$this->_paths = array(App::pluginPath($this->params['plugin']));
|
||||
$this->_paths = array(CakePlugin::path($this->params['plugin']));
|
||||
}
|
||||
$patterns = array(
|
||||
array(
|
||||
|
@ -433,7 +434,7 @@ class UpgradeShell extends AppShell {
|
|||
APP
|
||||
);
|
||||
if (!empty($this->params['plugin'])) {
|
||||
$this->_paths = array(App::pluginPath($this->params['plugin']));
|
||||
$this->_paths = array(CakePlugin::path($this->params['plugin']));
|
||||
}
|
||||
$patterns = array(
|
||||
array(
|
||||
|
@ -554,6 +555,7 @@ class UpgradeShell extends AppShell {
|
|||
/**
|
||||
* Replace cakeError with built-in exceptions.
|
||||
* NOTE: this ignores calls where you've passed your own secondary parameters to cakeError().
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function exceptions() {
|
||||
|
@ -563,7 +565,7 @@ class UpgradeShell extends AppShell {
|
|||
$this->_paths = array_merge($controllers, $components);
|
||||
|
||||
if (!empty($this->params['plugin'])) {
|
||||
$pluginPath = App::pluginPath($this->params['plugin']);
|
||||
$pluginPath = CakePlugin::path($this->params['plugin']);
|
||||
$this->_paths = array(
|
||||
$pluginPath . 'controllers' . DS,
|
||||
$pluginPath . 'controllers' . DS . 'components' . DS,
|
||||
|
@ -609,7 +611,7 @@ class UpgradeShell extends AppShell {
|
|||
|
||||
$new = 'View' . DS . Inflector::camelize($old);
|
||||
$old = 'View' . DS . $old;
|
||||
if ($new == $old) {
|
||||
if ($new === $old) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -661,7 +663,7 @@ class UpgradeShell extends AppShell {
|
|||
* Find all php files in the folder (honoring recursive) and determine where CakePHP expects the file to be
|
||||
* If the file is not exactly where CakePHP expects it - move it.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $path The path to move files in.
|
||||
* @param array $options array(recursive, checkFolder)
|
||||
* @return void
|
||||
*/
|
||||
|
@ -763,7 +765,7 @@ class UpgradeShell extends AppShell {
|
|||
/**
|
||||
* Searches the paths and finds files based on extension.
|
||||
*
|
||||
* @param string $extensions
|
||||
* @param string $extensions The extensions to include. Defaults to none.
|
||||
* @return void
|
||||
*/
|
||||
protected function _findFiles($extensions = '') {
|
||||
|
@ -839,8 +841,9 @@ class UpgradeShell extends AppShell {
|
|||
);
|
||||
|
||||
$parser->description(
|
||||
__d('cake_console', "A shell to help automate upgrading from CakePHP 1.3 to 2.0. \n" .
|
||||
"Be sure to have a backup of your application before running these commands."
|
||||
__d('cake_console', "A tool to help automate upgrading an application or plugin " .
|
||||
"from CakePHP 1.3 to 2.0. Be sure to have a backup of your application before " .
|
||||
"running these commands."
|
||||
))->addSubcommand('all', array(
|
||||
'help' => __d('cake_console', 'Run all upgrade commands.'),
|
||||
'parser' => $subcommandParser
|
||||
|
|
|
@ -40,35 +40,37 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a exception in the console environment. Prints a message to stderr.
|
||||
* Handle an exception in the console environment. Prints a message to stderr.
|
||||
*
|
||||
* @param Exception $exception The exception to handle
|
||||
* @param Exception|ParserError $exception The exception to handle
|
||||
* @return void
|
||||
*/
|
||||
public function handleException(Exception $exception) {
|
||||
$stderr = self::getStderr();
|
||||
public function handleException($exception) {
|
||||
$stderr = static::getStderr();
|
||||
$stderr->write(__d('cake_console', "<error>Error:</error> %s\n%s",
|
||||
$exception->getMessage(),
|
||||
$exception->getTraceAsString()
|
||||
));
|
||||
return $this->_stop($exception->getCode() ? $exception->getCode() : 1);
|
||||
$code = $exception->getCode();
|
||||
$code = ($code && is_int($code)) ? $code : 1;
|
||||
return $this->_stop($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle errors in the console environment. Writes errors to stderr,
|
||||
* and logs messages if Configure::read('debug') is 0.
|
||||
*
|
||||
* @param integer $code Error code
|
||||
* @param int $code Error code
|
||||
* @param string $description Description of the error.
|
||||
* @param string $file The file the error occurred in.
|
||||
* @param integer $line The line the error occurred on.
|
||||
* @param int $line The line the error occurred on.
|
||||
* @param array $context The backtrace of the error.
|
||||
* @return void
|
||||
*/
|
||||
|
@ -76,7 +78,7 @@ class ConsoleErrorHandler {
|
|||
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));
|
||||
|
@ -93,7 +95,7 @@ class ConsoleErrorHandler {
|
|||
/**
|
||||
* Wrapper for exit(), used for testing.
|
||||
*
|
||||
* @param integer $code The exit code.
|
||||
* @param int $code The exit code.
|
||||
* @return void
|
||||
*/
|
||||
protected function _stop($code = 0) {
|
||||
|
|
|
@ -37,7 +37,7 @@ class ConsoleInput {
|
|||
* 2. Handle we are attached to must be stdin.
|
||||
* Allows rich editing with arrow keys and history when inputting a string.
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_canReadline;
|
||||
|
||||
|
@ -47,7 +47,7 @@ class ConsoleInput {
|
|||
* @param string $handle The location of the stream to use as input.
|
||||
*/
|
||||
public function __construct($handle = 'php://stdin') {
|
||||
$this->_canReadline = extension_loaded('readline') && $handle == 'php://stdin' ? true : false;
|
||||
$this->_canReadline = extension_loaded('readline') && $handle === 'php://stdin' ? true : false;
|
||||
$this->_input = fopen($handle, 'r');
|
||||
}
|
||||
|
||||
|
@ -70,8 +70,8 @@ class ConsoleInput {
|
|||
/**
|
||||
* Checks if data is available on the stream
|
||||
*
|
||||
* @param integer $timeout An optional time to wait for data
|
||||
* @return boolean True for data available, false otherwise
|
||||
* @param int $timeout An optional time to wait for data
|
||||
* @return bool True for data available, false otherwise
|
||||
*/
|
||||
public function dataAvailable($timeout = 0) {
|
||||
$readFds = array($this->_input);
|
||||
|
|
|
@ -41,7 +41,7 @@ class ConsoleInputArgument {
|
|||
/**
|
||||
* Is this option required?
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_required;
|
||||
|
||||
|
@ -57,7 +57,7 @@ class ConsoleInputArgument {
|
|||
*
|
||||
* @param string|array $name The long name of the option, or an array with all the properties.
|
||||
* @param string $help The help text for this option
|
||||
* @param boolean $required Whether this argument is required. Missing required args will trigger exceptions
|
||||
* @param bool $required Whether this argument is required. Missing required args will trigger exceptions
|
||||
* @param array $choices Valid choices for this option.
|
||||
*/
|
||||
public function __construct($name, $help = '', $required = false, $choices = array()) {
|
||||
|
@ -85,7 +85,7 @@ class ConsoleInputArgument {
|
|||
/**
|
||||
* Generate the help for this argument.
|
||||
*
|
||||
* @param integer $width The width to make the name of the option.
|
||||
* @param int $width The width to make the name of the option.
|
||||
* @return string
|
||||
*/
|
||||
public function help($width = 0) {
|
||||
|
@ -123,7 +123,7 @@ class ConsoleInputArgument {
|
|||
/**
|
||||
* Check if this argument is a required argument
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function isRequired() {
|
||||
return (bool)$this->_required;
|
||||
|
@ -132,8 +132,8 @@ class ConsoleInputArgument {
|
|||
/**
|
||||
* Check that $value is a valid choice for this argument.
|
||||
*
|
||||
* @param string $value
|
||||
* @return boolean
|
||||
* @param string $value The choice to validate.
|
||||
* @return bool
|
||||
* @throws ConsoleException
|
||||
*/
|
||||
public function validChoice($value) {
|
||||
|
|
|
@ -48,7 +48,7 @@ class ConsoleInputOption {
|
|||
/**
|
||||
* Is the option a boolean option. Boolean options do not consume a parameter.
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_boolean;
|
||||
|
||||
|
@ -72,7 +72,7 @@ class ConsoleInputOption {
|
|||
* @param string|array $name The long name of the option, or an array with all the properties.
|
||||
* @param string $short The short alias for this option
|
||||
* @param string $help The help text for this option
|
||||
* @param boolean $boolean Whether this option is a boolean option. Boolean options don't consume extra tokens
|
||||
* @param bool $boolean Whether this option is a boolean option. Boolean options don't consume extra tokens
|
||||
* @param string $default The default value for this option.
|
||||
* @param array $choices Valid choices for this option.
|
||||
* @throws ConsoleException
|
||||
|
@ -118,7 +118,7 @@ class ConsoleInputOption {
|
|||
/**
|
||||
* Generate the help for this this option.
|
||||
*
|
||||
* @param integer $width The width to make the name of the option.
|
||||
* @param int $width The width to make the name of the option.
|
||||
* @return string
|
||||
*/
|
||||
public function help($width = 0) {
|
||||
|
@ -168,7 +168,7 @@ class ConsoleInputOption {
|
|||
/**
|
||||
* Check if this option is a boolean option
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function isBoolean() {
|
||||
return (bool)$this->_boolean;
|
||||
|
@ -177,8 +177,8 @@ class ConsoleInputOption {
|
|||
/**
|
||||
* Check that a value is a valid choice for this option.
|
||||
*
|
||||
* @param string $value
|
||||
* @return boolean
|
||||
* @param string $value The choice to validate.
|
||||
* @return bool
|
||||
* @throws ConsoleException
|
||||
*/
|
||||
public function validChoice($value) {
|
||||
|
|
|
@ -81,7 +81,7 @@ class ConsoleInputSubcommand {
|
|||
/**
|
||||
* Generate the help for this this subcommand.
|
||||
*
|
||||
* @param integer $width The width to make the name of the subcommand.
|
||||
* @param int $width The width to make the name of the subcommand.
|
||||
* @return string
|
||||
*/
|
||||
public function help($width = 0) {
|
||||
|
|
|
@ -136,7 +136,7 @@ class ConsoleOptionParser {
|
|||
* Construct an OptionParser so you can define its behavior
|
||||
*
|
||||
* @param string $command The command name this parser is for. The command name is used for generating help.
|
||||
* @param boolean $defaultOptions Whether you want the verbose and quiet options set. Setting
|
||||
* @param bool $defaultOptions Whether you want the verbose and quiet options set. Setting
|
||||
* this to false will prevent the addition of `--verbose` & `--quiet` options.
|
||||
*/
|
||||
public function __construct($command = null, $defaultOptions = true) {
|
||||
|
@ -165,7 +165,7 @@ class ConsoleOptionParser {
|
|||
* Static factory method for creating new OptionParsers so you can chain methods off of them.
|
||||
*
|
||||
* @param string $command The command name this parser is for. The command name is used for generating help.
|
||||
* @param boolean $defaultOptions Whether you want the verbose and quiet options set.
|
||||
* @param bool $defaultOptions Whether you want the verbose and quiet options set.
|
||||
* @return ConsoleOptionParser
|
||||
*/
|
||||
public static function create($command, $defaultOptions = true) {
|
||||
|
@ -175,7 +175,7 @@ class ConsoleOptionParser {
|
|||
/**
|
||||
* Build a parser from an array. Uses an array like
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* $spec = array(
|
||||
* 'description' => 'text',
|
||||
* 'epilog' => 'text',
|
||||
|
@ -189,7 +189,7 @@ class ConsoleOptionParser {
|
|||
* // list of subcommands to add.
|
||||
* )
|
||||
* );
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* @param array $spec The spec to build the OptionParser with.
|
||||
* @return ConsoleOptionParser
|
||||
|
@ -218,7 +218,7 @@ class ConsoleOptionParser {
|
|||
* Get or set the command name for shell/task.
|
||||
*
|
||||
* @param string $text The text to set, or null if you want to read
|
||||
* @return mixed If reading, the value of the command. If setting $this will be returned
|
||||
* @return string|self If reading, the value of the command. If setting $this will be returned.
|
||||
*/
|
||||
public function command($text = null) {
|
||||
if ($text !== null) {
|
||||
|
@ -233,7 +233,7 @@ class ConsoleOptionParser {
|
|||
*
|
||||
* @param string|array $text The text to set, or null if you want to read. If an array the
|
||||
* text will be imploded with "\n"
|
||||
* @return mixed If reading, the value of the description. If setting $this will be returned
|
||||
* @return string|self If reading, the value of the description. If setting $this will be returned.
|
||||
*/
|
||||
public function description($text = null) {
|
||||
if ($text !== null) {
|
||||
|
@ -251,7 +251,7 @@ class ConsoleOptionParser {
|
|||
* the options and arguments listing when help is generated.
|
||||
*
|
||||
* @param string|array $text Text when setting or null when reading. If an array the text will be imploded with "\n"
|
||||
* @return mixed If reading, the value of the epilog. If setting $this will be returned.
|
||||
* @return string|self If reading, the value of the epilog. If setting $this will be returned.
|
||||
*/
|
||||
public function epilog($text = null) {
|
||||
if ($text !== null) {
|
||||
|
@ -284,7 +284,7 @@ class ConsoleOptionParser {
|
|||
* @param ConsoleInputOption|string $name The long name you want to the value to be parsed out as when options are parsed.
|
||||
* Will also accept an instance of ConsoleInputOption
|
||||
* @param array $options An array of parameters that define the behavior of the option
|
||||
* @return ConsoleOptionParser $this.
|
||||
* @return self
|
||||
*/
|
||||
public function addOption($name, $options = array()) {
|
||||
if (is_object($name) && $name instanceof ConsoleInputOption) {
|
||||
|
@ -324,7 +324,7 @@ class ConsoleOptionParser {
|
|||
*
|
||||
* @param ConsoleInputArgument|string $name The name of the argument. Will also accept an instance of ConsoleInputArgument
|
||||
* @param array $params Parameters for the argument, see above.
|
||||
* @return ConsoleOptionParser $this.
|
||||
* @return self
|
||||
*/
|
||||
public function addArgument($name, $params = array()) {
|
||||
if (is_object($name) && $name instanceof ConsoleInputArgument) {
|
||||
|
@ -354,7 +354,7 @@ class ConsoleOptionParser {
|
|||
*
|
||||
* @param array $args Array of arguments to add.
|
||||
* @see ConsoleOptionParser::addArgument()
|
||||
* @return ConsoleOptionParser $this
|
||||
* @return self
|
||||
*/
|
||||
public function addArguments(array $args) {
|
||||
foreach ($args as $name => $params) {
|
||||
|
@ -369,7 +369,7 @@ class ConsoleOptionParser {
|
|||
*
|
||||
* @param array $options Array of options to add.
|
||||
* @see ConsoleOptionParser::addOption()
|
||||
* @return ConsoleOptionParser $this
|
||||
* @return self
|
||||
*/
|
||||
public function addOptions(array $options) {
|
||||
foreach ($options as $name => $params) {
|
||||
|
@ -391,7 +391,7 @@ class ConsoleOptionParser {
|
|||
*
|
||||
* @param ConsoleInputSubcommand|string $name Name of the subcommand. Will also accept an instance of ConsoleInputSubcommand
|
||||
* @param array $options Array of params, see above.
|
||||
* @return ConsoleOptionParser $this.
|
||||
* @return self
|
||||
*/
|
||||
public function addSubcommand($name, $options = array()) {
|
||||
if (is_object($name) && $name instanceof ConsoleInputSubcommand) {
|
||||
|
@ -410,11 +410,22 @@ class ConsoleOptionParser {
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a subcommand from the option parser.
|
||||
*
|
||||
* @param string $name The subcommand name to remove.
|
||||
* @return self
|
||||
*/
|
||||
public function removeSubcommand($name) {
|
||||
unset($this->_subcommands[$name]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add multiple subcommands at once.
|
||||
*
|
||||
* @param array $commands Array of subcommands.
|
||||
* @return ConsoleOptionParser $this
|
||||
* @return self
|
||||
*/
|
||||
public function addSubcommands(array $commands) {
|
||||
foreach ($commands as $name => $params) {
|
||||
|
@ -458,7 +469,7 @@ class ConsoleOptionParser {
|
|||
* @param array $argv Array of args (argv) to parse.
|
||||
* @param string $command The subcommand to use. If this parameter is a subcommand, that has a parser,
|
||||
* That parser will be used to parse $argv instead.
|
||||
* @return Array array($params, $args)
|
||||
* @return array array($params, $args)
|
||||
* @throws ConsoleException When an invalid parameter is encountered.
|
||||
*/
|
||||
public function parse($argv, $command = null) {
|
||||
|
@ -506,12 +517,11 @@ class ConsoleOptionParser {
|
|||
* @param string $subcommand If present and a valid subcommand that has a linked parser.
|
||||
* That subcommands help will be shown instead.
|
||||
* @param string $format Define the output format, can be text or xml
|
||||
* @param integer $width The width to format user content to. Defaults to 72
|
||||
* @param int $width The width to format user content to. Defaults to 72
|
||||
* @return string Generated help.
|
||||
*/
|
||||
public function help($subcommand = null, $format = 'text', $width = 72) {
|
||||
if (
|
||||
isset($this->_subcommands[$subcommand]) &&
|
||||
if (isset($this->_subcommands[$subcommand]) &&
|
||||
$this->_subcommands[$subcommand]->parser() instanceof self
|
||||
) {
|
||||
$subparser = $this->_subcommands[$subcommand]->parser();
|
||||
|
@ -597,13 +607,14 @@ class ConsoleOptionParser {
|
|||
$params[$name] = $value;
|
||||
return $params;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if $name has an option (short/long) defined for it.
|
||||
*
|
||||
* @param string $name The name of the option.
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
protected function _optionExists($name) {
|
||||
if (substr($name, 0, 2) === '--') {
|
||||
|
|
|
@ -47,21 +47,21 @@ class ConsoleOutput {
|
|||
/**
|
||||
* Raw output constant - no modification of output text.
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
const RAW = 0;
|
||||
|
||||
/**
|
||||
* Plain output - tags will be stripped.
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
const PLAIN = 1;
|
||||
|
||||
/**
|
||||
* Color output - Convert known tags in to ANSI color escape codes.
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
const COLOR = 2;
|
||||
|
||||
|
@ -79,10 +79,18 @@ class ConsoleOutput {
|
|||
*/
|
||||
protected $_output;
|
||||
|
||||
/**
|
||||
* The number of bytes last written to the output stream
|
||||
* used when overwriting the previous message.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_lastWritten = 0;
|
||||
|
||||
/**
|
||||
* The current output type. Manipulated with ConsoleOutput::outputAs();
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $_outputAs = self::COLOR;
|
||||
|
||||
|
@ -153,16 +161,19 @@ class ConsoleOutput {
|
|||
/**
|
||||
* Construct the output object.
|
||||
*
|
||||
* Checks for a pretty console environment. Ansicon allows pretty consoles
|
||||
* on windows, and is supported.
|
||||
* Checks for a pretty console environment. Ansicon and ConEmu allows
|
||||
* pretty consoles on Windows, and is supported.
|
||||
*
|
||||
* @param string $stream The identifier of the stream to write output to.
|
||||
*/
|
||||
public function __construct($stream = 'php://stdout') {
|
||||
$this->_output = fopen($stream, 'w');
|
||||
|
||||
if (DS === '\\' && !(bool)env('ANSICON')) {
|
||||
$this->_outputAs = self::PLAIN;
|
||||
if ((DS === '\\' && !(bool)env('ANSICON') && env('ConEmuANSI') !== 'ON') ||
|
||||
$stream === 'php://output' ||
|
||||
(function_exists('posix_isatty') && !posix_isatty($this->_output))
|
||||
) {
|
||||
$this->_outputAs = static::PLAIN;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,15 +181,44 @@ class ConsoleOutput {
|
|||
* Outputs a single or multiple messages to stdout. If no parameters
|
||||
* are passed, outputs just a newline.
|
||||
*
|
||||
* @param string|array $message A string or a an array of strings to output
|
||||
* @param integer $newlines Number of newlines to append
|
||||
* @return integer Returns the number of bytes returned from writing to stdout.
|
||||
* @param string|array $message A string or an array of strings to output
|
||||
* @param int $newlines Number of newlines to append
|
||||
* @return int Returns the number of bytes returned from writing to stdout.
|
||||
*/
|
||||
public function write($message, $newlines = 1) {
|
||||
if (is_array($message)) {
|
||||
$message = implode(self::LF, $message);
|
||||
$message = implode(static::LF, $message);
|
||||
}
|
||||
return $this->_write($this->styleText($message . str_repeat(static::LF, $newlines)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite some already output text.
|
||||
*
|
||||
* Useful for building progress bars, or when you want to replace
|
||||
* text already output to the screen with new text.
|
||||
*
|
||||
* **Warning** You cannot overwrite text that contains newlines.
|
||||
*
|
||||
* @param array|string $message The message to output.
|
||||
* @param int $newlines Number of newlines to append.
|
||||
* @param int|null $size The number of bytes to overwrite. Defaults to the
|
||||
* length of the last message output.
|
||||
* @return void
|
||||
*/
|
||||
public function overwrite($message, $newlines = 1, $size = null) {
|
||||
$size = $size ?: $this->_lastWritten;
|
||||
// Output backspaces.
|
||||
$this->write(str_repeat("\x08", $size), 0);
|
||||
$newBytes = $this->write($message, 0);
|
||||
// Fill any remaining bytes with spaces.
|
||||
$fill = $size - $newBytes;
|
||||
if ($fill > 0) {
|
||||
$this->write(str_repeat(' ', $fill), 0);
|
||||
}
|
||||
if ($newlines) {
|
||||
$this->write("", $newlines);
|
||||
}
|
||||
return $this->_write($this->styleText($message . str_repeat(self::LF, $newlines)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,11 +228,11 @@ class ConsoleOutput {
|
|||
* @return string String with color codes added.
|
||||
*/
|
||||
public function styleText($text) {
|
||||
if ($this->_outputAs == self::RAW) {
|
||||
if ($this->_outputAs == static::RAW) {
|
||||
return $text;
|
||||
}
|
||||
if ($this->_outputAs == self::PLAIN) {
|
||||
$tags = implode('|', array_keys(self::$_styles));
|
||||
if ($this->_outputAs == static::PLAIN) {
|
||||
$tags = implode('|', array_keys(static::$_styles));
|
||||
return preg_replace('#</?(?:' . $tags . ')>#', '', $text);
|
||||
}
|
||||
return preg_replace_callback(
|
||||
|
@ -203,7 +243,7 @@ class ConsoleOutput {
|
|||
/**
|
||||
* Replace tags with color codes.
|
||||
*
|
||||
* @param array $matches.
|
||||
* @param array $matches An array of matches to replace.
|
||||
* @return string
|
||||
*/
|
||||
protected function _replaceTags($matches) {
|
||||
|
@ -213,16 +253,16 @@ class ConsoleOutput {
|
|||
}
|
||||
|
||||
$styleInfo = array();
|
||||
if (!empty($style['text']) && isset(self::$_foregroundColors[$style['text']])) {
|
||||
$styleInfo[] = self::$_foregroundColors[$style['text']];
|
||||
if (!empty($style['text']) && isset(static::$_foregroundColors[$style['text']])) {
|
||||
$styleInfo[] = static::$_foregroundColors[$style['text']];
|
||||
}
|
||||
if (!empty($style['background']) && isset(self::$_backgroundColors[$style['background']])) {
|
||||
$styleInfo[] = self::$_backgroundColors[$style['background']];
|
||||
if (!empty($style['background']) && isset(static::$_backgroundColors[$style['background']])) {
|
||||
$styleInfo[] = static::$_backgroundColors[$style['background']];
|
||||
}
|
||||
unset($style['text'], $style['background']);
|
||||
foreach ($style as $option => $value) {
|
||||
if ($value) {
|
||||
$styleInfo[] = self::$_options[$option];
|
||||
$styleInfo[] = static::$_options[$option];
|
||||
}
|
||||
}
|
||||
return "\033[" . implode($styleInfo, ';') . 'm' . $matches['text'] . "\033[0m";
|
||||
|
@ -232,10 +272,11 @@ class ConsoleOutput {
|
|||
* Writes a message to the output stream.
|
||||
*
|
||||
* @param string $message Message to write.
|
||||
* @return boolean success
|
||||
* @return bool success
|
||||
*/
|
||||
protected function _write($message) {
|
||||
return fwrite($this->_output, $message);
|
||||
$this->_lastWritten = fwrite($this->_output, $message);
|
||||
return $this->_lastWritten;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -265,23 +306,23 @@ class ConsoleOutput {
|
|||
*/
|
||||
public function styles($style = null, $definition = null) {
|
||||
if ($style === null && $definition === null) {
|
||||
return self::$_styles;
|
||||
return static::$_styles;
|
||||
}
|
||||
if (is_string($style) && $definition === null) {
|
||||
return isset(self::$_styles[$style]) ? self::$_styles[$style] : null;
|
||||
return isset(static::$_styles[$style]) ? static::$_styles[$style] : null;
|
||||
}
|
||||
if ($definition === false) {
|
||||
unset(self::$_styles[$style]);
|
||||
unset(static::$_styles[$style]);
|
||||
return true;
|
||||
}
|
||||
self::$_styles[$style] = $definition;
|
||||
static::$_styles[$style] = $definition;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get/Set the output type to use. The output type how formatting tags are treated.
|
||||
*
|
||||
* @param integer $type The output type to use. Should be one of the class constants.
|
||||
* @param int $type The output type to use. Should be one of the class constants.
|
||||
* @return mixed Either null or the value if getting.
|
||||
*/
|
||||
public function outputAs($type = null) {
|
||||
|
@ -295,7 +336,9 @@ class ConsoleOutput {
|
|||
* Clean up and close handles
|
||||
*/
|
||||
public function __destruct() {
|
||||
fclose($this->_output);
|
||||
if (is_resource($this->_output)) {
|
||||
fclose($this->_output);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('String', 'Utility');
|
||||
App::uses('CakeText', 'Utility');
|
||||
|
||||
/**
|
||||
* HelpFormatter formats help for console shells. Can format to either
|
||||
|
@ -33,19 +33,19 @@ class HelpFormatter {
|
|||
/**
|
||||
* The maximum number of arguments shown when generating usage.
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $_maxArgs = 6;
|
||||
|
||||
/**
|
||||
* The maximum number of options shown when generating usage.
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $_maxOptions = 6;
|
||||
|
||||
/**
|
||||
* Build the help formatter for a an OptionParser
|
||||
* Build the help formatter for an OptionParser
|
||||
*
|
||||
* @param ConsoleOptionParser $parser The option parser help is being generated for.
|
||||
*/
|
||||
|
@ -56,7 +56,7 @@ class HelpFormatter {
|
|||
/**
|
||||
* Get the help as formatted text suitable for output on the command line.
|
||||
*
|
||||
* @param integer $width The width of the help output.
|
||||
* @param int $width The width of the help output.
|
||||
* @return string
|
||||
*/
|
||||
public function text($width = 72) {
|
||||
|
@ -64,7 +64,7 @@ class HelpFormatter {
|
|||
$out = array();
|
||||
$description = $parser->description();
|
||||
if (!empty($description)) {
|
||||
$out[] = String::wrap($description, $width);
|
||||
$out[] = CakeText::wrap($description, $width);
|
||||
$out[] = '';
|
||||
}
|
||||
$out[] = __d('cake_console', '<info>Usage:</info>');
|
||||
|
@ -76,7 +76,7 @@ class HelpFormatter {
|
|||
$out[] = '';
|
||||
$max = $this->_getMaxLength($subcommands) + 2;
|
||||
foreach ($subcommands as $command) {
|
||||
$out[] = String::wrap($command->help($max), array(
|
||||
$out[] = CakeText::wrap($command->help($max), array(
|
||||
'width' => $width,
|
||||
'indent' => str_repeat(' ', $max),
|
||||
'indentAt' => 1
|
||||
|
@ -93,7 +93,7 @@ class HelpFormatter {
|
|||
$out[] = __d('cake_console', '<info>Options:</info>');
|
||||
$out[] = '';
|
||||
foreach ($options as $option) {
|
||||
$out[] = String::wrap($option->help($max), array(
|
||||
$out[] = CakeText::wrap($option->help($max), array(
|
||||
'width' => $width,
|
||||
'indent' => str_repeat(' ', $max),
|
||||
'indentAt' => 1
|
||||
|
@ -108,7 +108,7 @@ class HelpFormatter {
|
|||
$out[] = __d('cake_console', '<info>Arguments:</info>');
|
||||
$out[] = '';
|
||||
foreach ($arguments as $argument) {
|
||||
$out[] = String::wrap($argument->help($max), array(
|
||||
$out[] = CakeText::wrap($argument->help($max), array(
|
||||
'width' => $width,
|
||||
'indent' => str_repeat(' ', $max),
|
||||
'indentAt' => 1
|
||||
|
@ -118,7 +118,7 @@ class HelpFormatter {
|
|||
}
|
||||
$epilog = $parser->epilog();
|
||||
if (!empty($epilog)) {
|
||||
$out[] = String::wrap($epilog, $width);
|
||||
$out[] = CakeText::wrap($epilog, $width);
|
||||
$out[] = '';
|
||||
}
|
||||
return implode("\n", $out);
|
||||
|
@ -159,8 +159,8 @@ class HelpFormatter {
|
|||
/**
|
||||
* Iterate over a collection and find the longest named thing.
|
||||
*
|
||||
* @param array $collection
|
||||
* @return integer
|
||||
* @param array $collection The collection to find a max length of.
|
||||
* @return int
|
||||
*/
|
||||
protected function _getMaxLength($collection) {
|
||||
$max = 0;
|
||||
|
@ -173,7 +173,7 @@ class HelpFormatter {
|
|||
/**
|
||||
* Get the help as an xml string.
|
||||
*
|
||||
* @param boolean $string Return the SimpleXml object or a string. Defaults to true.
|
||||
* @param bool $string Return the SimpleXml object or a string. Defaults to true.
|
||||
* @return string|SimpleXmlElement See $string
|
||||
*/
|
||||
public function xml($string = true) {
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.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 (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since 2.8
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
abstract class BaseShellHelper {
|
||||
|
||||
/**
|
||||
* Default config for this helper.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_defaultConfig = array();
|
||||
|
||||
/**
|
||||
* ConsoleOutput instance.
|
||||
*
|
||||
* @var ConsoleOutput
|
||||
*/
|
||||
protected $_consoleOutput;
|
||||
|
||||
/**
|
||||
* Runtime config
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_config = array();
|
||||
|
||||
/**
|
||||
* Whether the config property has already been configured with defaults
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_configInitialized = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ConsoleOutput $consoleOutput The ConsoleOutput instance to use.
|
||||
* @param array $config The settings for this helper.
|
||||
*/
|
||||
public function __construct(ConsoleOutput $consoleOutput, array $config = array()) {
|
||||
$this->_consoleOutput = $consoleOutput;
|
||||
$this->config($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize config & store config values
|
||||
*
|
||||
* @param null $config Config values to set
|
||||
* @return array|void
|
||||
*/
|
||||
public function config($config = null) {
|
||||
if ($config === null) {
|
||||
return $this->_config;
|
||||
}
|
||||
if (!$this->_configInitialized) {
|
||||
$this->_config = array_merge($this->_defaultConfig, $config);
|
||||
$this->_configInitialized = true;
|
||||
} else {
|
||||
$this->_config = array_merge($this->_config, $config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should output content using `$this->_consoleOutput`.
|
||||
*
|
||||
* @param array $args The arguments for the helper.
|
||||
* @return void
|
||||
*/
|
||||
abstract public function output($args);
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.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 (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since 2.8
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
App::uses("BaseShellHelper", "Console/Helper");
|
||||
|
||||
/**
|
||||
* Create a progress bar using a supplied callback.
|
||||
*/
|
||||
class ProgressShellHelper extends BaseShellHelper {
|
||||
|
||||
/**
|
||||
* The current progress.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_progress = 0;
|
||||
|
||||
/**
|
||||
* The total number of 'items' to progress through.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_total = 0;
|
||||
|
||||
/**
|
||||
* The width of the bar.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_width = 0;
|
||||
|
||||
/**
|
||||
* Output a progress bar.
|
||||
*
|
||||
* Takes a number of options to customize the behavior:
|
||||
*
|
||||
* - `total` The total number of items in the progress bar. Defaults
|
||||
* to 100.
|
||||
* - `width` The width of the progress bar. Defaults to 80.
|
||||
* - `callback` The callback that will be called in a loop to advance the progress bar.
|
||||
*
|
||||
* @param array $args The arguments/options to use when outputing the progress bar.
|
||||
* @return void
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function output($args) {
|
||||
$args += array('callback' => null);
|
||||
if (isset($args[0])) {
|
||||
$args['callback'] = $args[0];
|
||||
}
|
||||
if (!$args['callback'] || !is_callable($args['callback'])) {
|
||||
throw new RuntimeException('Callback option must be a callable.');
|
||||
}
|
||||
$this->init($args);
|
||||
$callback = $args['callback'];
|
||||
while ($this->_progress < $this->_total) {
|
||||
$callback($this);
|
||||
$this->draw();
|
||||
}
|
||||
$this->_consoleOutput->write('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the progress bar for use.
|
||||
*
|
||||
* - `total` The total number of items in the progress bar. Defaults
|
||||
* to 100.
|
||||
* - `width` The width of the progress bar. Defaults to 80.
|
||||
*
|
||||
* @param array $args The initialization data.
|
||||
* @return void
|
||||
*/
|
||||
public function init(array $args = array()) {
|
||||
$args += array('total' => 100, 'width' => 80);
|
||||
$this->_progress = 0;
|
||||
$this->_width = $args['width'];
|
||||
$this->_total = $args['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the progress bar.
|
||||
*
|
||||
* @param int $num The amount of progress to advance by.
|
||||
* @return void
|
||||
*/
|
||||
public function increment($num = 1) {
|
||||
$this->_progress = min(max(0, $this->_progress + $num), $this->_total);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the progress bar based on the current state.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function draw() {
|
||||
$numberLen = strlen(' 100%');
|
||||
$complete = round($this->_progress / $this->_total, 2);
|
||||
$barLen = ($this->_width - $numberLen) * ($this->_progress / $this->_total);
|
||||
$bar = '';
|
||||
if ($barLen > 1) {
|
||||
$bar = str_repeat('=', $barLen - 1) . '>';
|
||||
}
|
||||
$pad = ceil($this->_width - $numberLen - $barLen);
|
||||
if ($pad > 0) {
|
||||
$bar .= str_repeat(' ', $pad);
|
||||
}
|
||||
$percent = ($complete * 100) . '%';
|
||||
$bar .= str_pad($percent, $numberLen, ' ', STR_PAD_LEFT);
|
||||
$this->_consoleOutput->overwrite($bar, 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.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 (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since 2.8
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
App::uses("BaseShellHelper", "Console/Helper");
|
||||
|
||||
/**
|
||||
* Create a visually pleasing ASCII art table
|
||||
* from 2 dimensional array data.
|
||||
*/
|
||||
class TableShellHelper extends BaseShellHelper {
|
||||
|
||||
/**
|
||||
* Default config for this helper.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_defaultConfig = array(
|
||||
'headers' => true,
|
||||
'rowSeparator' => false,
|
||||
'headerStyle' => 'info',
|
||||
);
|
||||
|
||||
/**
|
||||
* Calculate the column widths
|
||||
*
|
||||
* @param array $rows The rows on which the columns width will be calculated on.
|
||||
* @return array
|
||||
*/
|
||||
protected function _calculateWidths($rows) {
|
||||
$widths = array();
|
||||
foreach ($rows as $line) {
|
||||
for ($i = 0, $len = count($line); $i < $len; $i++) {
|
||||
$columnLength = mb_strlen($line[$i]);
|
||||
if ($columnLength > (isset($widths[$i]) ? $widths[$i] : 0)) {
|
||||
$widths[$i] = $columnLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $widths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a row separator.
|
||||
*
|
||||
* @param array $widths The widths of each column to output.
|
||||
* @return void
|
||||
*/
|
||||
protected function _rowSeparator($widths) {
|
||||
$out = '';
|
||||
foreach ($widths as $column) {
|
||||
$out .= '+' . str_repeat('-', $column + 2);
|
||||
}
|
||||
$out .= '+';
|
||||
$this->_consoleOutput->write($out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a row.
|
||||
*
|
||||
* @param array $row The row to output.
|
||||
* @param array $widths The widths of each column to output.
|
||||
* @param array $options Options to be passed.
|
||||
* @return void
|
||||
*/
|
||||
protected function _render($row, $widths, $options = array()) {
|
||||
$out = '';
|
||||
foreach ($row as $i => $column) {
|
||||
$pad = $widths[$i] - mb_strlen($column);
|
||||
if (!empty($options['style'])) {
|
||||
$column = $this->_addStyle($column, $options['style']);
|
||||
}
|
||||
$out .= '| ' . $column . str_repeat(' ', $pad) . ' ';
|
||||
}
|
||||
$out .= '|';
|
||||
$this->_consoleOutput->write($out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a table.
|
||||
*
|
||||
* @param array $rows The data to render out.
|
||||
* @return void
|
||||
*/
|
||||
public function output($rows) {
|
||||
$config = $this->config();
|
||||
$widths = $this->_calculateWidths($rows);
|
||||
$this->_rowSeparator($widths);
|
||||
if ($config['headers'] === true) {
|
||||
$this->_render(array_shift($rows), $widths, array('style' => $config['headerStyle']));
|
||||
$this->_rowSeparator($widths);
|
||||
}
|
||||
foreach ($rows as $line) {
|
||||
$this->_render($line, $widths);
|
||||
if ($config['rowSeparator'] === true) {
|
||||
$this->_rowSeparator($widths);
|
||||
}
|
||||
}
|
||||
if ($config['rowSeparator'] !== true) {
|
||||
$this->_rowSeparator($widths);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add style tags
|
||||
*
|
||||
* @param string $text The text to be surrounded
|
||||
* @param string $style The style to be applied
|
||||
* @return string
|
||||
*/
|
||||
protected function _addStyle($text, $style) {
|
||||
return '<' . $style . '>' . $text . '</' . $style . '>';
|
||||
}
|
||||
}
|
|
@ -22,7 +22,6 @@ App::uses('ConsoleInputSubcommand', 'Console');
|
|||
App::uses('ConsoleOptionParser', 'Console');
|
||||
App::uses('ClassRegistry', 'Utility');
|
||||
App::uses('File', 'Utility');
|
||||
App::uses('ClassRegistry', 'Utility');
|
||||
|
||||
/**
|
||||
* Base class for command-line utilities for automating programmer chores.
|
||||
|
@ -31,24 +30,31 @@ App::uses('ClassRegistry', 'Utility');
|
|||
*/
|
||||
class Shell extends Object {
|
||||
|
||||
/**
|
||||
* Default error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE_ERROR = 1;
|
||||
|
||||
/**
|
||||
* Output constant making verbose shells.
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
const VERBOSE = 2;
|
||||
|
||||
/**
|
||||
* Output constant for making normal shells.
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
const NORMAL = 1;
|
||||
|
||||
/**
|
||||
* Output constants for making quiet shells.
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
const QUIET = 0;
|
||||
|
||||
|
@ -62,7 +68,7 @@ class Shell extends Object {
|
|||
/**
|
||||
* If true, the script will ask for permission to perform actions.
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $interactive = true;
|
||||
|
||||
|
@ -167,6 +173,21 @@ class Shell extends Object {
|
|||
*/
|
||||
public $stdin;
|
||||
|
||||
/**
|
||||
* The number of bytes last written to the output stream
|
||||
* used when overwriting the previous message.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_lastWritten = 0;
|
||||
|
||||
/**
|
||||
* Contains helpers which have been previously instantiated
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_helpers = array();
|
||||
|
||||
/**
|
||||
* Constructs this Shell instance.
|
||||
*
|
||||
|
@ -239,7 +260,7 @@ class Shell extends Object {
|
|||
/**
|
||||
* If $uses is an array load each of the models in the array
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
protected function _loadModels() {
|
||||
if (is_array($this->uses)) {
|
||||
|
@ -254,7 +275,7 @@ class Shell extends Object {
|
|||
/**
|
||||
* Lazy loads models using the loadModel() method if declared in $uses
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name The name of the model to look for.
|
||||
* @return void
|
||||
*/
|
||||
public function __isset($name) {
|
||||
|
@ -303,7 +324,7 @@ class Shell extends Object {
|
|||
/**
|
||||
* Loads tasks defined in public $tasks
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function loadTasks() {
|
||||
if ($this->tasks === true || empty($this->tasks) || empty($this->Tasks)) {
|
||||
|
@ -318,7 +339,7 @@ class Shell extends Object {
|
|||
* Check to see if this shell has a task with the provided name.
|
||||
*
|
||||
* @param string $task The task name to check.
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hasTask
|
||||
*/
|
||||
public function hasTask($task) {
|
||||
|
@ -329,7 +350,7 @@ class Shell extends Object {
|
|||
* Check to see if this shell has a callable method by the given name.
|
||||
*
|
||||
* @param string $name The method name to check.
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hasMethod
|
||||
*/
|
||||
public function hasMethod($name) {
|
||||
|
@ -446,7 +467,7 @@ class Shell extends Object {
|
|||
/**
|
||||
* Display the help in the correct format
|
||||
*
|
||||
* @param string $command
|
||||
* @param string $command The command to get help for.
|
||||
* @return void
|
||||
*/
|
||||
protected function _displayHelp($command) {
|
||||
|
@ -477,7 +498,7 @@ class Shell extends Object {
|
|||
/**
|
||||
* Overload get for lazy building of tasks
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name The property name to access.
|
||||
* @return Shell Object of Task
|
||||
*/
|
||||
public function __get($name) {
|
||||
|
@ -492,6 +513,19 @@ class Shell extends Object {
|
|||
return $this->{$name};
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely access the values in $this->params.
|
||||
*
|
||||
* @param string $name The name of the parameter to get.
|
||||
* @return string|bool|null Value. Will return null if it doesn't exist.
|
||||
*/
|
||||
public function param($name) {
|
||||
if (!isset($this->params[$name])) {
|
||||
return null;
|
||||
}
|
||||
return $this->params[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompts the user for input, and returns it.
|
||||
*
|
||||
|
@ -553,7 +587,8 @@ class Shell extends Object {
|
|||
$result = $this->stdin->read();
|
||||
|
||||
if ($result === false) {
|
||||
return $this->_stop(1);
|
||||
$this->_stop(self::CODE_ERROR);
|
||||
return self::CODE_ERROR;
|
||||
}
|
||||
$result = trim($result);
|
||||
|
||||
|
@ -574,13 +609,13 @@ class Shell extends Object {
|
|||
* - `indent` Indent the text with the string provided. Defaults to null.
|
||||
*
|
||||
* @param string $text Text the text to format.
|
||||
* @param string|integer|array $options Array of options to use, or an integer to wrap the text to.
|
||||
* @param string|int|array $options Array of options to use, or an integer to wrap the text to.
|
||||
* @return string Wrapped / indented text
|
||||
* @see String::wrap()
|
||||
* @see CakeText::wrap()
|
||||
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::wrapText
|
||||
*/
|
||||
public function wrapText($text, $options = array()) {
|
||||
return String::wrap($text, $options);
|
||||
return CakeText::wrap($text, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -594,10 +629,10 @@ class Shell extends Object {
|
|||
* present in most shells. Using Shell::QUIET for a message means it will always display.
|
||||
* While using Shell::VERBOSE means it will only display when verbose output is toggled.
|
||||
*
|
||||
* @param string|array $message A string or a an array of strings to output
|
||||
* @param integer $newlines Number of newlines to append
|
||||
* @param integer $level The message's output level, see above.
|
||||
* @return integer|boolean Returns the number of bytes returned from writing to stdout.
|
||||
* @param string|array $message A string or an array of strings to output
|
||||
* @param int $newlines Number of newlines to append
|
||||
* @param int $level The message's output level, see above.
|
||||
* @return int|bool Returns the number of bytes returned from writing to stdout.
|
||||
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::out
|
||||
*/
|
||||
public function out($message = null, $newlines = 1, $level = Shell::NORMAL) {
|
||||
|
@ -609,17 +644,49 @@ class Shell extends Object {
|
|||
$currentLevel = Shell::QUIET;
|
||||
}
|
||||
if ($level <= $currentLevel) {
|
||||
return $this->stdout->write($message, $newlines);
|
||||
$this->_lastWritten = $this->stdout->write($message, $newlines);
|
||||
return $this->_lastWritten;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite some already output text.
|
||||
*
|
||||
* Useful for building progress bars, or when you want to replace
|
||||
* text already output to the screen with new text.
|
||||
*
|
||||
* **Warning** You cannot overwrite text that contains newlines.
|
||||
*
|
||||
* @param array|string $message The message to output.
|
||||
* @param int $newlines Number of newlines to append.
|
||||
* @param int $size The number of bytes to overwrite. Defaults to the length of the last message output.
|
||||
* @return int|bool Returns the number of bytes returned from writing to stdout.
|
||||
*/
|
||||
public function overwrite($message, $newlines = 1, $size = null) {
|
||||
$size = $size ? $size : $this->_lastWritten;
|
||||
|
||||
// Output backspaces.
|
||||
$this->out(str_repeat("\x08", $size), 0);
|
||||
|
||||
$newBytes = $this->out($message, 0);
|
||||
|
||||
// Fill any remaining bytes with spaces.
|
||||
$fill = $size - $newBytes;
|
||||
if ($fill > 0) {
|
||||
$this->out(str_repeat(' ', $fill), 0);
|
||||
}
|
||||
if ($newlines) {
|
||||
$this->out($this->nl($newlines), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a single or multiple error messages to stderr. If no parameters
|
||||
* are passed outputs just a newline.
|
||||
*
|
||||
* @param string|array $message A string or a an array of strings to output
|
||||
* @param integer $newlines Number of newlines to append
|
||||
* @param string|array $message A string or an array of strings to output
|
||||
* @param int $newlines Number of newlines to append
|
||||
* @return void
|
||||
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::err
|
||||
*/
|
||||
|
@ -630,7 +697,7 @@ class Shell extends Object {
|
|||
/**
|
||||
* Returns a single or multiple linefeeds sequences.
|
||||
*
|
||||
* @param integer $multiplier Number of times the linefeed sequence should be repeated
|
||||
* @param int $multiplier Number of times the linefeed sequence should be repeated
|
||||
* @return string
|
||||
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::nl
|
||||
*/
|
||||
|
@ -641,8 +708,8 @@ class Shell extends Object {
|
|||
/**
|
||||
* Outputs a series of minus characters to the standard output, acts as a visual separator.
|
||||
*
|
||||
* @param integer $newlines Number of newlines to pre- and append
|
||||
* @param integer $width Width of the line, defaults to 63
|
||||
* @param int $newlines Number of newlines to pre- and append
|
||||
* @param int $width Width of the line, defaults to 63
|
||||
* @return void
|
||||
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hr
|
||||
*/
|
||||
|
@ -667,7 +734,8 @@ class Shell extends Object {
|
|||
if (!empty($message)) {
|
||||
$this->err($message);
|
||||
}
|
||||
return $this->_stop(1);
|
||||
$this->_stop(self::CODE_ERROR);
|
||||
return self::CODE_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -691,7 +759,7 @@ class Shell extends Object {
|
|||
*
|
||||
* @param string $path Where to put the file.
|
||||
* @param string $contents Content to put in the file.
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::createFile
|
||||
*/
|
||||
public function createFile($path, $contents) {
|
||||
|
@ -705,7 +773,8 @@ class Shell extends Object {
|
|||
|
||||
if (strtolower($key) === 'q') {
|
||||
$this->out(__d('cake_console', '<error>Quitting</error>.'), 2);
|
||||
return $this->_stop();
|
||||
$this->_stop();
|
||||
return true;
|
||||
} elseif (strtolower($key) !== 'y') {
|
||||
$this->out(__d('cake_console', 'Skip `%s`', $path), 2);
|
||||
return false;
|
||||
|
@ -726,10 +795,32 @@ class Shell extends Object {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load given shell helper class
|
||||
*
|
||||
* @param string $name Name of the helper class. Supports plugin syntax.
|
||||
* @return BaseShellHelper Instance of helper class
|
||||
* @throws RuntimeException If invalid class name is provided
|
||||
*/
|
||||
public function helper($name) {
|
||||
if (isset($this->_helpers[$name])) {
|
||||
return $this->_helpers[$name];
|
||||
}
|
||||
list($plugin, $helperClassName) = pluginSplit($name, true);
|
||||
$helperClassName = Inflector::camelize($name) . "ShellHelper";
|
||||
App::uses($helperClassName, $plugin . "Console/Helper");
|
||||
if (!class_exists($helperClassName)) {
|
||||
throw new RuntimeException("Class " . $helperClassName . " not found");
|
||||
}
|
||||
$helper = new $helperClassName($this->stdout);
|
||||
$this->_helpers[$name] = $helper;
|
||||
return $helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action to create a Unit Test
|
||||
*
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
protected function _checkUnitTest() {
|
||||
if (class_exists('PHPUnit_Framework_TestCase')) {
|
||||
|
@ -819,8 +910,8 @@ class Shell extends Object {
|
|||
/**
|
||||
* creates the singular name for use in views.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string $name
|
||||
* @param string $name The plural underscored value.
|
||||
* @return string name
|
||||
*/
|
||||
protected function _singularName($name) {
|
||||
return Inflector::variable(Inflector::singularize($name));
|
||||
|
@ -860,7 +951,7 @@ class Shell extends Object {
|
|||
* Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.
|
||||
*
|
||||
* @param string $pluginName Name of the plugin you want ie. DebugKit
|
||||
* @return string $path path to the correct plugin.
|
||||
* @return string path path to the correct plugin.
|
||||
*/
|
||||
protected function _pluginPath($pluginName) {
|
||||
if (CakePlugin::loaded($pluginName)) {
|
||||
|
@ -874,7 +965,7 @@ class Shell extends Object {
|
|||
* If you don't wish to see in your stdout or stderr everything that is logged
|
||||
* through CakeLog, call this function with first param as false
|
||||
*
|
||||
* @param boolean $enable whether to enable CakeLog output or not
|
||||
* @param bool $enable whether to enable CakeLog output or not
|
||||
* @return void
|
||||
*/
|
||||
protected function _useLogger($enable = true) {
|
||||
|
|
|
@ -43,7 +43,7 @@ class ShellDispatcher {
|
|||
* a status code of either 0 or 1 according to the result of the dispatch.
|
||||
*
|
||||
* @param array $args the argv from PHP
|
||||
* @param boolean $bootstrap Should the environment be bootstrapped.
|
||||
* @param bool $bootstrap Should the environment be bootstrapped.
|
||||
*/
|
||||
public function __construct($args = array(), $bootstrap = true) {
|
||||
set_time_limit(0);
|
||||
|
@ -79,9 +79,11 @@ class ShellDispatcher {
|
|||
}
|
||||
|
||||
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(dirname(__FILE__))));
|
||||
define('CAKEPHP_SHELL', true);
|
||||
if (!defined('DS')) {
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('CORE_PATH')) {
|
||||
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
|
||||
}
|
||||
|
@ -114,7 +116,7 @@ class ShellDispatcher {
|
|||
/**
|
||||
* Initializes the environment and loads the CakePHP core.
|
||||
*
|
||||
* @return boolean Success.
|
||||
* @return bool Success.
|
||||
*/
|
||||
protected function _bootstrap() {
|
||||
if (!defined('ROOT')) {
|
||||
|
@ -175,12 +177,15 @@ class ShellDispatcher {
|
|||
}
|
||||
set_exception_handler($exception['consoleHandler']);
|
||||
set_error_handler($error['consoleHandler'], Configure::read('Error.level'));
|
||||
|
||||
App::uses('Debugger', 'Utility');
|
||||
Debugger::getInstance()->output('txt');
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches a CLI request
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* @throws MissingShellMethodException
|
||||
*/
|
||||
public function dispatch() {
|
||||
|
@ -244,6 +249,11 @@ class ShellDispatcher {
|
|||
App::uses('AppShell', 'Console/Command');
|
||||
App::uses($class, $plugin . 'Console/Command');
|
||||
|
||||
if (!class_exists($class)) {
|
||||
$plugin = Inflector::camelize($shell) . '.';
|
||||
App::uses($class, $plugin . 'Console/Command');
|
||||
}
|
||||
|
||||
if (!class_exists($class)) {
|
||||
throw new MissingShellException(array(
|
||||
'class' => $class
|
||||
|
@ -317,12 +327,13 @@ class ShellDispatcher {
|
|||
/**
|
||||
* Parses out the paths from from the argv
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $args The argv to parse.
|
||||
* @return void
|
||||
*/
|
||||
protected function _parsePaths($args) {
|
||||
$parsed = array();
|
||||
$keys = array('-working', '--working', '-app', '--app', '-root', '--root');
|
||||
$args = (array)$args;
|
||||
foreach ($keys as $key) {
|
||||
while (($index = array_search($key, $args)) !== false) {
|
||||
$keyname = str_replace('-', '', $key);
|
||||
|
@ -357,7 +368,7 @@ class ShellDispatcher {
|
|||
/**
|
||||
* Stop execution of the current script
|
||||
*
|
||||
* @param integer|string $status see http://php.net/exit for values
|
||||
* @param int|string $status see http://php.net/exit for values
|
||||
* @return void
|
||||
*/
|
||||
protected function _stop($status = 0) {
|
||||
|
|
|
@ -43,7 +43,7 @@ class TaskCollection extends ObjectCollection {
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Shell $Shell
|
||||
* @param Shell $Shell The shell this task collection is attached to.
|
||||
*/
|
||||
public function __construct(Shell $Shell) {
|
||||
$this->_Shell = $Shell;
|
||||
|
@ -53,13 +53,13 @@ class TaskCollection extends ObjectCollection {
|
|||
* Loads/constructs a task. Will return the instance in the registry if it already exists.
|
||||
*
|
||||
* You can alias your task as an existing task by setting the 'className' key, i.e.,
|
||||
* {{{
|
||||
* ```
|
||||
* public $tasks = array(
|
||||
* 'DbConfig' => array(
|
||||
* 'className' => 'Bakeplus.DbConfigure'
|
||||
* );
|
||||
* );
|
||||
* }}}
|
||||
* ```
|
||||
* All calls to the `DbConfig` task would use `DbConfigure` found in the `Bakeplus` plugin instead.
|
||||
*
|
||||
* @param string $task Task name to load
|
||||
|
|
|
@ -53,10 +53,10 @@
|
|||
$this-><?php echo $currentModelName; ?>->create();
|
||||
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));
|
||||
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));
|
||||
return $this->redirect(array('action' => 'index'));
|
||||
} else {
|
||||
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
|
||||
$this->Flash->error(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
|
||||
<?php else: ?>
|
||||
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
|
||||
<?php endif; ?>
|
||||
|
@ -94,10 +94,10 @@
|
|||
if ($this->request->is(array('post', 'put'))) {
|
||||
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));
|
||||
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'));
|
||||
return $this->redirect(array('action' => 'index'));
|
||||
} else {
|
||||
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
|
||||
$this->Flash->error(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
|
||||
<?php else: ?>
|
||||
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
|
||||
<?php endif; ?>
|
||||
|
@ -138,9 +138,9 @@
|
|||
$this->request->allowMethod('post', 'delete');
|
||||
if ($this-><?php echo $currentModelName; ?>->delete()) {
|
||||
<?php if ($wannaUseSession): ?>
|
||||
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been deleted.'));
|
||||
$this->Flash->success(__('The <?php echo strtolower($singularHumanName); ?> has been deleted.'));
|
||||
} else {
|
||||
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be deleted. Please, try again.'));
|
||||
$this->Flash->error(__('The <?php echo strtolower($singularHumanName); ?> could not be deleted. Please, try again.'));
|
||||
}
|
||||
return $this->redirect(array('action' => 'index'));
|
||||
<?php else: ?>
|
||||
|
|
|
@ -23,10 +23,10 @@ echo "App::uses('{$plugin}AppController', '{$pluginPath}Controller');\n";
|
|||
?>
|
||||
/**
|
||||
* <?php echo $controllerName; ?> Controller
|
||||
*
|
||||
<?php
|
||||
if (!$isScaffold) {
|
||||
$defaultModel = Inflector::singularize($controllerName);
|
||||
echo " *\n";
|
||||
echo " * @property {$defaultModel} \${$defaultModel}\n";
|
||||
if (!empty($components)) {
|
||||
foreach ($components as $component) {
|
||||
|
@ -74,7 +74,9 @@ class <?php echo $controllerName; ?>Controller extends <?php echo $plugin; ?>App
|
|||
echo ");\n\n";
|
||||
endif;
|
||||
|
||||
echo trim($actions);
|
||||
if (!empty($actions)) {
|
||||
echo trim($actions) . "\n";
|
||||
}
|
||||
|
||||
endif; ?>
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
echo "<?php\n";
|
||||
?>
|
||||
/**
|
||||
* <?php echo $model; ?>Fixture
|
||||
*
|
||||
* <?php echo $model; ?> Fixture
|
||||
*/
|
||||
class <?php echo $model; ?>Fixture extends CakeTestFixture {
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ foreach ($associations as $assoc):
|
|||
if (!empty($assoc)):
|
||||
?>
|
||||
|
||||
//The Associations below have been created with all possible keys, those that are not needed can be removed
|
||||
// The Associations below have been created with all possible keys, those that are not needed can be removed
|
||||
<?php
|
||||
break;
|
||||
endif;
|
||||
|
|
|
@ -24,7 +24,6 @@ App::uses('<?php echo $dependency[0]; ?>', '<?php echo $dependency[1]; ?>');
|
|||
|
||||
/**
|
||||
* <?php echo $fullClassName; ?> Test Case
|
||||
*
|
||||
*/
|
||||
<?php if ($type === 'Controller'): ?>
|
||||
class <?php echo $fullClassName; ?>Test extends ControllerTestCase {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -23,7 +21,7 @@
|
|||
<?php
|
||||
echo "\t<?php\n";
|
||||
foreach ($fields as $field) {
|
||||
if (strpos($action, 'add') !== false && $field == $primaryKey) {
|
||||
if (strpos($action, 'add') !== false && $field === $primaryKey) {
|
||||
continue;
|
||||
} elseif (!in_array($field, array('created', 'modified', 'updated'))) {
|
||||
echo "\t\techo \$this->Form->input('{$field}');\n";
|
||||
|
@ -46,7 +44,7 @@
|
|||
<ul>
|
||||
|
||||
<?php if (strpos($action, 'add') === false): ?>
|
||||
<li><?php echo "<?php echo \$this->Form->postLink(__('Delete'), array('action' => 'delete', \$this->Form->value('{$modelClass}.{$primaryKey}')), null, __('Are you sure you want to delete # %s?', \$this->Form->value('{$modelClass}.{$primaryKey}'))); ?>"; ?></li>
|
||||
<li><?php echo "<?php echo \$this->Form->postLink(__('Delete'), array('action' => 'delete', \$this->Form->value('{$modelClass}.{$primaryKey}')), array('confirm' => __('Are you sure you want to delete # %s?', \$this->Form->value('{$modelClass}.{$primaryKey}')))); ?>"; ?></li>
|
||||
<?php endif; ?>
|
||||
<li><?php echo "<?php echo \$this->Html->link(__('List " . $pluralHumanName . "'), array('action' => 'index')); ?>"; ?></li>
|
||||
<?php
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -19,12 +17,15 @@
|
|||
<div class="<?php echo $pluralVar; ?> index">
|
||||
<h2><?php echo "<?php echo __('{$pluralHumanName}'); ?>"; ?></h2>
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<?php foreach ($fields as $field): ?>
|
||||
<th><?php echo "<?php echo \$this->Paginator->sort('{$field}'); ?>"; ?></th>
|
||||
<?php endforeach; ?>
|
||||
<th class="actions"><?php echo "<?php echo __('Actions'); ?>"; ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
echo "<?php foreach (\${$pluralVar} as \${$singularVar}): ?>\n";
|
||||
echo "\t<tr>\n";
|
||||
|
@ -47,17 +48,18 @@
|
|||
echo "\t\t<td class=\"actions\">\n";
|
||||
echo "\t\t\t<?php echo \$this->Html->link(__('View'), array('action' => 'view', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
|
||||
echo "\t\t\t<?php echo \$this->Html->link(__('Edit'), array('action' => 'edit', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
|
||||
echo "\t\t\t<?php echo \$this->Form->postLink(__('Delete'), array('action' => 'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), array(), __('Are you sure you want to delete # %s?', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
|
||||
echo "\t\t\t<?php echo \$this->Form->postLink(__('Delete'), array('action' => 'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), array('confirm' => __('Are you sure you want to delete # %s?', \${$singularVar}['{$modelClass}']['{$primaryKey}']))); ?>\n";
|
||||
echo "\t\t</td>\n";
|
||||
echo "\t</tr>\n";
|
||||
|
||||
echo "<?php endforeach; ?>\n";
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>
|
||||
<?php echo "<?php
|
||||
echo \$this->Paginator->counter(array(
|
||||
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
|
||||
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
|
||||
));
|
||||
?>"; ?>
|
||||
</p>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -45,7 +43,7 @@ foreach ($fields as $field) {
|
|||
<ul>
|
||||
<?php
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('Edit " . $singularHumanName ."'), array('action' => 'edit', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?> </li>\n";
|
||||
echo "\t\t<li><?php echo \$this->Form->postLink(__('Delete " . $singularHumanName . "'), array('action' => 'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), null, __('Are you sure you want to delete # %s?', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?> </li>\n";
|
||||
echo "\t\t<li><?php echo \$this->Form->postLink(__('Delete " . $singularHumanName . "'), array('action' => 'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), array('confirm' => __('Are you sure you want to delete # %s?', \${$singularVar}['{$modelClass}']['{$primaryKey}']))); ?> </li>\n";
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('List " . $pluralHumanName . "'), array('action' => 'index')); ?> </li>\n";
|
||||
echo "\t\t<li><?php echo \$this->Html->link(__('New " . $singularHumanName . "'), array('action' => 'add')); ?> </li>\n";
|
||||
|
||||
|
@ -119,7 +117,7 @@ echo "\t<?php foreach (\${$singularVar}['{$alias}'] as \${$otherSingularVar}): ?
|
|||
echo "\t\t\t<td class=\"actions\">\n";
|
||||
echo "\t\t\t\t<?php echo \$this->Html->link(__('View'), array('controller' => '{$details['controller']}', 'action' => 'view', \${$otherSingularVar}['{$details['primaryKey']}'])); ?>\n";
|
||||
echo "\t\t\t\t<?php echo \$this->Html->link(__('Edit'), array('controller' => '{$details['controller']}', 'action' => 'edit', \${$otherSingularVar}['{$details['primaryKey']}'])); ?>\n";
|
||||
echo "\t\t\t\t<?php echo \$this->Form->postLink(__('Delete'), array('controller' => '{$details['controller']}', 'action' => 'delete', \${$otherSingularVar}['{$details['primaryKey']}']), null, __('Are you sure you want to delete # %s?', \${$otherSingularVar}['{$details['primaryKey']}'])); ?>\n";
|
||||
echo "\t\t\t\t<?php echo \$this->Form->postLink(__('Delete'), array('controller' => '{$details['controller']}', 'action' => 'delete', \${$otherSingularVar}['{$details['primaryKey']}']), array('confirm' => __('Are you sure you want to delete # %s?', \${$otherSingularVar}['{$details['primaryKey']}']))); ?>\n";
|
||||
echo "\t\t\t</td>\n";
|
||||
echo "\t\t</tr>\n";
|
||||
|
||||
|
@ -133,4 +131,6 @@ echo "\t<?php endforeach; ?>\n";
|
|||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine on
|
||||
RewriteRule ^$ webroot/ [L]
|
||||
RewriteRule (.*) webroot/$1 [L]
|
||||
RewriteEngine on
|
||||
RewriteRule ^$ webroot/ [L]
|
||||
RewriteRule (.*) webroot/$1 [L]
|
||||
</IfModule>
|
|
@ -9,21 +9,34 @@
|
|||
* @since CakePHP(tm) v 0.2.9
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
/**
|
||||
* Using the Schema command line utility
|
||||
* cake schema run create DbAcl
|
||||
*
|
||||
*/
|
||||
class DbAclSchema extends CakeSchema {
|
||||
|
||||
/**
|
||||
* Before event.
|
||||
*
|
||||
* @param array $event The event data.
|
||||
* @return bool success
|
||||
*/
|
||||
public function before($event = array()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* After event.
|
||||
*
|
||||
* @param array $event The event data.
|
||||
* @return void
|
||||
*/
|
||||
public function after($event = array()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* ACO - Access Control Object - Something that is wanted
|
||||
*/
|
||||
public $acos = array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'),
|
||||
'parent_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10),
|
||||
|
@ -35,6 +48,9 @@ class DbAclSchema extends CakeSchema {
|
|||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
|
||||
);
|
||||
|
||||
/**
|
||||
* ARO - Access Request Object - Something that wants something
|
||||
*/
|
||||
public $aros = array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'),
|
||||
'parent_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 10),
|
||||
|
@ -46,6 +62,10 @@ class DbAclSchema extends CakeSchema {
|
|||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
|
||||
);
|
||||
|
||||
/**
|
||||
* Used by the Cake::Model:Permission class.
|
||||
* Checks if the given $aro has access to action $action in $aco.
|
||||
*/
|
||||
public $aros_acos = array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'),
|
||||
'aro_id' => array('type' => 'integer', 'null' => false, 'length' => 10, 'key' => 'index'),
|
||||
|
|
|
@ -38,4 +38,15 @@ CREATE TABLE aros (
|
|||
lft INTEGER(10) DEFAULT NULL,
|
||||
rght INTEGER(10) DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
);
|
||||
|
||||
/* this indexes will improve acl perfomance */
|
||||
CREATE INDEX idx_acos_lft_rght ON `acos` (`lft`, `rght`);
|
||||
|
||||
CREATE INDEX idx_acos_alias ON `acos` (`alias`);
|
||||
|
||||
CREATE INDEX idx_aros_lft_rght ON `aros` (`lft`, `rght`);
|
||||
|
||||
CREATE INDEX idx_aros_alias ON `aros` (`alias`);
|
||||
|
||||
CREATE INDEX idx_aco_id ON `aros_acos` (`aco_id`);
|
||||
|
|
|
@ -4,13 +4,21 @@
|
|||
*
|
||||
* Use it to configure database for i18n
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.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 (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.Config.Schema
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Using the Schema command line utility
|
||||
*
|
||||
* Use it to configure database for i18n
|
||||
|
@ -19,15 +27,37 @@
|
|||
*/
|
||||
class I18nSchema extends CakeSchema {
|
||||
|
||||
/**
|
||||
* The name property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'i18n';
|
||||
|
||||
/**
|
||||
* Before callback.
|
||||
*
|
||||
* @param array $event Schema object properties
|
||||
* @return bool Should process continue
|
||||
*/
|
||||
public function before($event = array()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* After callback.
|
||||
*
|
||||
* @param array $event Schema object properties
|
||||
* @return void
|
||||
*/
|
||||
public function after($event = array()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The i18n table definition
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $i18n = array(
|
||||
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 10, 'key' => 'primary'),
|
||||
'locale' => array('type' => 'string', 'null' => false, 'length' => 6, 'key' => 'index'),
|
||||
|
|
|
@ -4,28 +4,57 @@
|
|||
*
|
||||
* Use it to configure database for Sessions
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.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 (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.Config.Schema
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
/**
|
||||
* Using the Schema command line utility
|
||||
* cake schema run create Sessions
|
||||
*
|
||||
*/
|
||||
class SessionsSchema extends CakeSchema {
|
||||
|
||||
/**
|
||||
* Name property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'Sessions';
|
||||
|
||||
/**
|
||||
* Before callback.
|
||||
*
|
||||
* @param array $event Schema object properties
|
||||
* @return bool Should process continue
|
||||
*/
|
||||
public function before($event = array()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* After callback.
|
||||
*
|
||||
* @param array $event Schema object properties
|
||||
* @return void
|
||||
*/
|
||||
public function after($event = array()) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The cake_sessions table definition
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $cake_sessions = array(
|
||||
'id' => array('type' => 'string', 'null' => false, 'key' => 'primary'),
|
||||
'data' => array('type' => 'text', 'null' => true, 'default' => null),
|
||||
|
|
|
@ -39,7 +39,6 @@ Cache::config('default', array('engine' => 'File'));
|
|||
* 'Vendor' => array('/path/to/vendors/', '/next/path/to/vendors/'),
|
||||
* 'Plugin' => array('/path/to/plugins/', '/next/path/to/plugins/'),
|
||||
* ));
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -48,7 +47,6 @@ Cache::config('default', array('engine' => 'File'));
|
|||
*
|
||||
* Inflector::rules('singular', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
|
||||
* Inflector::rules('plural', array('rules' => array(), 'irregular' => array(), 'uninflected' => array()));
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -57,8 +55,7 @@ Cache::config('default', array('engine' => 'File'));
|
|||
* advanced ways of loading plugins
|
||||
*
|
||||
* CakePlugin::loadAll(); // Loads all plugins at once
|
||||
* CakePlugin::load('DebugKit'); //Loads a single plugin named DebugKit
|
||||
*
|
||||
* CakePlugin::load('DebugKit'); // Loads a single plugin named DebugKit
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
|
@ -138,13 +138,11 @@
|
|||
* Enables:
|
||||
* `admin_index()` and `/admin/controller/index`
|
||||
* `manager_index()` and `/manager/controller/index`
|
||||
*
|
||||
*/
|
||||
//Configure::write('Routing.prefixes', array('admin'));
|
||||
|
||||
/**
|
||||
* Turn off all caching application-wide.
|
||||
*
|
||||
*/
|
||||
//Configure::write('Cache.disable', true);
|
||||
|
||||
|
@ -155,7 +153,6 @@
|
|||
* public $cacheAction inside your controllers to define caching settings.
|
||||
* You can either set it controller-wide by setting public $cacheAction = true,
|
||||
* or in each action using $this->cacheAction = true.
|
||||
*
|
||||
*/
|
||||
//Configure::write('Cache.check', true);
|
||||
|
||||
|
@ -204,7 +201,6 @@
|
|||
*
|
||||
* To use database sessions, run the app/Config/Schema/sessions.php schema using
|
||||
* the cake shell command: cake schema create Sessions
|
||||
*
|
||||
*/
|
||||
Configure::write('Session', array(
|
||||
'defaults' => 'php'
|
||||
|
@ -261,7 +257,6 @@
|
|||
//date_default_timezone_set('UTC');
|
||||
|
||||
/**
|
||||
*
|
||||
* Cache Engine Configuration
|
||||
* Default settings provided below
|
||||
*
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.Config
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
*
|
||||
* from =>
|
||||
* The origin email. See CakeEmail::from() about the valid values
|
||||
*
|
||||
*/
|
||||
class EmailConfig {
|
||||
|
||||
|
|
|
@ -16,20 +16,33 @@
|
|||
* @since CakePHP(tm) v 2.0
|
||||
*/
|
||||
|
||||
$ds = DIRECTORY_SEPARATOR;
|
||||
$dispatcher = 'Cake' . $ds . 'Console' . $ds . 'ShellDispatcher.php';
|
||||
if (!defined('DS')) {
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
$dispatcher = 'Cake' . DS . 'Console' . DS . 'ShellDispatcher.php';
|
||||
|
||||
if (function_exists('ini_set')) {
|
||||
$root = dirname(dirname(dirname(__FILE__)));
|
||||
$appDir = basename(dirname(dirname(__FILE__)));
|
||||
$install = $root . DS . 'lib';
|
||||
$composerInstall = $root . DS . $appDir . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib';
|
||||
|
||||
// the following line differs from its sibling
|
||||
// the following lines differ from its sibling
|
||||
// /app/Console/cake.php
|
||||
ini_set('include_path', $root . PATH_SEPARATOR . __CAKE_PATH__ . PATH_SEPARATOR . ini_get('include_path'));
|
||||
if (file_exists($composerInstall . DS . $dispatcher)) {
|
||||
$install = $composerInstall;
|
||||
} elseif (!file_exists($install . DS . $dispatcher)) {
|
||||
$install = $root . PATH_SEPARATOR . __CAKE_PATH__;
|
||||
}
|
||||
|
||||
ini_set('include_path', $install . PATH_SEPARATOR . ini_get('include_path'));
|
||||
unset($root, $appDir, $install, $composerInstall);
|
||||
}
|
||||
|
||||
if (!include $dispatcher) {
|
||||
trigger_error('Could not locate CakePHP core files.', E_USER_ERROR);
|
||||
}
|
||||
unset($paths, $path, $dispatcher, $root, $ds);
|
||||
unset($dispatcher);
|
||||
|
||||
return ShellDispatcher::run($argv);
|
||||
|
|
|
@ -31,10 +31,9 @@ class PagesController extends AppController {
|
|||
/**
|
||||
* Displays a view
|
||||
*
|
||||
* @param mixed What page to display
|
||||
* @return void
|
||||
* @throws NotFoundException When the view file could not be found
|
||||
* or MissingViewException in debug mode.
|
||||
* or MissingViewException in debug mode.
|
||||
*/
|
||||
public function display() {
|
||||
$path = func_get_args();
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
|
||||
class AllTestsTest extends CakeTestSuite {
|
||||
|
||||
/**
|
||||
* Get the suite object.
|
||||
*
|
||||
* @return CakeTestSuite Suite class instance.
|
||||
*/
|
||||
public static function suite() {
|
||||
$suite = new CakeTestSuite('All application tests');
|
||||
$suite->addTestDirectoryRecursive(TESTS . 'Case');
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<div id="<?php echo $key; ?>Message" class="<?php echo !empty($params['class']) ? $params['class'] : 'message'; ?>"><?php echo $message; ?></div>
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -21,5 +19,4 @@ $content = explode("\n", $content);
|
|||
|
||||
foreach ($content as $line):
|
||||
echo '<p> ' . $line . "</p>\n";
|
||||
endforeach;
|
||||
?>
|
||||
endforeach;
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
|
@ -19,4 +17,3 @@
|
|||
if (Configure::read('debug') > 0):
|
||||
echo $this->element('exception_stack_trace');
|
||||
endif;
|
||||
?>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
|
@ -16,4 +14,3 @@
|
|||
if (Configure::read('debug') > 0):
|
||||
echo $this->element('exception_stack_trace');
|
||||
endif;
|
||||
?>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.View.Layouts.Email.html
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.View.Layouts
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.View.Layouts
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.View.Layouts
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.View.Layouts
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
|
@ -11,9 +9,9 @@
|
|||
<html>
|
||||
<head>
|
||||
<?php echo $this->Html->charset(); ?>
|
||||
<title><?php echo $page_title; ?></title>
|
||||
<title><?php echo $pageTitle; ?></title>
|
||||
|
||||
<?php if (Configure::read('debug') == 0): ?>
|
||||
<?php if (!Configure::read('debug')): ?>
|
||||
<meta http-equiv="Refresh" content="<?php echo $pause; ?>;url=<?php echo $url; ?>"/>
|
||||
<?php endif ?>
|
||||
<style><!--
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.View.Pages
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
|
@ -64,7 +62,7 @@ endif;
|
|||
$settings = Cache::settings();
|
||||
if (!empty($settings)):
|
||||
echo '<span class="notice success">';
|
||||
echo __d('cake_dev', 'The %s is being used for core caching. To change the config edit %s', '<em>'. $settings['engine'] . 'Engine</em>', 'APP/Config/core.php');
|
||||
echo __d('cake_dev', 'The %s is being used for core caching. To change the config edit %s', '<em>' . $settings['engine'] . 'Engine</em>', 'APP/Config/core.php');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
|
@ -143,7 +141,7 @@ if (isset($filePresent)):
|
|||
echo '<span class="notice">';
|
||||
echo __d('cake_dev', 'DebugKit is not installed. It will help you inspect and debug different aspects of your application.');
|
||||
echo '<br/>';
|
||||
echo __d('cake_dev', 'You can install it from %s', $this->Html->link('GitHub', 'https://github.com/cakephp/debug_kit'));
|
||||
echo __d('cake_dev', 'You can install it from %s', $this->Html->link('GitHub', 'https://github.com/cakephp/debug_kit/tree/2.2'));
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
|
@ -183,7 +181,7 @@ You can also add some CSS styles for your pages at: %s.',
|
|||
<p>
|
||||
<ul>
|
||||
<li>
|
||||
<?php echo $this->Html->link('DebugKit', 'https://github.com/cakephp/debug_kit') ?>:
|
||||
<?php echo $this->Html->link('DebugKit', 'https://github.com/cakephp/debug_kit/tree/2.2') ?>:
|
||||
<?php echo __d('cake_dev', 'provides a debugging toolbar and enhanced debugging tools for CakePHP applications.'); ?>
|
||||
</li>
|
||||
<li>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^ index.php [L]
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^ index.php [L]
|
||||
</IfModule>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
@charset "utf-8";
|
||||
/**
|
||||
*
|
||||
* Generic CSS for CakePHP
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
|
@ -84,7 +83,7 @@ p {
|
|||
line-height:20px;
|
||||
background: #003d4c url('../img/cake.icon.png') no-repeat left;
|
||||
color: #fff;
|
||||
padding: 0px 30px;
|
||||
padding: 0 30px;
|
||||
}
|
||||
#header h1 a {
|
||||
color: #fff;
|
||||
|
@ -172,7 +171,7 @@ td.actions {
|
|||
white-space: nowrap;
|
||||
}
|
||||
table td.actions a {
|
||||
margin: 0px 6px;
|
||||
margin: 0 6px;
|
||||
padding:2px 5px;
|
||||
}
|
||||
|
||||
|
@ -334,7 +333,7 @@ option {
|
|||
input[type=checkbox] {
|
||||
clear: left;
|
||||
float: left;
|
||||
margin: 0px 6px 7px 2px;
|
||||
margin: 0 6px 7px 2px;
|
||||
width: auto;
|
||||
}
|
||||
div.checkbox label {
|
||||
|
@ -363,7 +362,7 @@ form .submit input[type=submit] {
|
|||
background-image: -moz-linear-gradient(top, #76BF6B, #3B8230);
|
||||
border-color: #2d6324;
|
||||
color: #fff;
|
||||
text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px;
|
||||
text-shadow: rgba(0, 0, 0, 0.5) 0 -1px 0;
|
||||
padding: 8px 10px;
|
||||
}
|
||||
form .submit input[type=submit]:hover {
|
||||
|
@ -525,11 +524,11 @@ input[type=submit],
|
|||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
text-decoration: none;
|
||||
text-shadow: #fff 0px 1px 0px;
|
||||
text-shadow: #fff 0 1px 0;
|
||||
min-width: 0;
|
||||
-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0px 1px 1px rgba(0, 0, 0, 0.2);
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0px 1px 1px rgba(0, 0, 0, 0.2);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0px 1px 1px rgba(0, 0, 0, 0.2);
|
||||
-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 1px 1px rgba(0, 0, 0, 0.2);
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
@ -549,7 +548,7 @@ input[type=submit]:active,
|
|||
background-image: -ms-linear-gradient(top, #dfdfdf, #eee);
|
||||
background-image: -o-linear-gradient(top, #dfdfdf, #eee);
|
||||
background-image: linear-gradient(top, #dfdfdf, #eee);
|
||||
text-shadow: #eee 0px 1px 0px;
|
||||
text-shadow: #eee 0 1px 0;
|
||||
-moz-box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.3);
|
||||
-webkit-box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.3);
|
||||
box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.3);
|
||||
|
@ -625,15 +624,15 @@ pre {
|
|||
-moz-border-radius: 10px;
|
||||
-webkit-border-radius: 10px;
|
||||
border-radius: 10px;
|
||||
margin: 0px 4px 10px 2px;
|
||||
margin: 0 4px 10px 2px;
|
||||
font-family: sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 14px;
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
-moz-box-shadow: inset 0px 1px 0 rgba(0, 0, 0, 0.3);
|
||||
-webkit-box-shadow: inset 0px 1px 0 rgba(0, 0, 0, 0.3);
|
||||
box-shadow: inset 0px 1px 0 rgba(0, 0, 0, 0.3);
|
||||
-moz-box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.3);
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.3);
|
||||
box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
.cake-code-dump pre {
|
||||
position: relative;
|
||||
|
@ -645,13 +644,13 @@ pre {
|
|||
.cake-stack-trace pre {
|
||||
color: #000;
|
||||
background-color: #F0F0F0;
|
||||
margin: 0px 0 10px 0;
|
||||
margin: 0 0 10px 0;
|
||||
padding: 1em;
|
||||
overflow: auto;
|
||||
text-shadow: none;
|
||||
}
|
||||
.cake-stack-trace li {
|
||||
padding: 10px 5px 0px;
|
||||
padding: 10px 5px 0;
|
||||
margin: 0 0 4px 0;
|
||||
font-family: monospace;
|
||||
border: 1px solid #bbb;
|
||||
|
@ -707,7 +706,7 @@ pre {
|
|||
}
|
||||
.code-coverage-results div.start {
|
||||
border:1px solid #aaa;
|
||||
border-width:1px 1px 0px 1px;
|
||||
border-width:1px 1px 0 1px;
|
||||
margin-top:30px;
|
||||
padding-top:5px;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* Index
|
||||
*
|
||||
* The Front Controller for handling every request
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.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 (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package app.webroot
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -24,7 +31,6 @@ if (!defined('DS')) {
|
|||
|
||||
/**
|
||||
* The full path to the directory which holds "app", WITHOUT a trailing DS.
|
||||
*
|
||||
*/
|
||||
if (!defined('ROOT')) {
|
||||
define('ROOT', dirname(dirname(dirname(__FILE__))));
|
||||
|
@ -32,7 +38,6 @@ if (!defined('ROOT')) {
|
|||
|
||||
/**
|
||||
* The actual directory name for the "app".
|
||||
*
|
||||
*/
|
||||
if (!defined('APP_DIR')) {
|
||||
define('APP_DIR', basename(dirname(dirname(__FILE__))));
|
||||
|
@ -54,10 +59,19 @@ if (!defined('APP_DIR')) {
|
|||
*/
|
||||
//define('CAKE_CORE_INCLUDE_PATH', __CAKE_PATH__);
|
||||
|
||||
/**
|
||||
* This auto-detects CakePHP as a composer installed library.
|
||||
* You may remove this if you are not planning to use composer (not recommended, though).
|
||||
*/
|
||||
$vendorPath = ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib';
|
||||
$dispatcher = 'Cake' . DS . 'Console' . DS . 'ShellDispatcher.php';
|
||||
if (!defined('CAKE_CORE_INCLUDE_PATH') && file_exists($vendorPath . DS . $dispatcher)) {
|
||||
define('CAKE_CORE_INCLUDE_PATH', $vendorPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Editing below this line should NOT be necessary.
|
||||
* Change at your own risk.
|
||||
*
|
||||
*/
|
||||
if (!defined('WEBROOT_DIR')) {
|
||||
define('WEBROOT_DIR', basename(dirname(__FILE__)));
|
||||
|
@ -66,8 +80,8 @@ if (!defined('WWW_ROOT')) {
|
|||
define('WWW_ROOT', dirname(__FILE__) . DS);
|
||||
}
|
||||
|
||||
// for built-in server
|
||||
if (php_sapi_name() === 'cli-server') {
|
||||
// For the built-in server
|
||||
if (PHP_SAPI === 'cli-server') {
|
||||
if ($_SERVER['REQUEST_URI'] !== '/' && file_exists(WWW_ROOT . $_SERVER['PHP_SELF'])) {
|
||||
return false;
|
||||
}
|
||||
|
@ -81,10 +95,8 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) {
|
|||
if (!include 'Cake' . DS . 'bootstrap.php') {
|
||||
$failed = true;
|
||||
}
|
||||
} else {
|
||||
if (!include CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php') {
|
||||
$failed = true;
|
||||
}
|
||||
} elseif (!include CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php') {
|
||||
$failed = true;
|
||||
}
|
||||
if (!empty($failed)) {
|
||||
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
|
||||
|
|
|
@ -18,14 +18,13 @@ if (!defined('DS')) {
|
|||
}
|
||||
|
||||
/**
|
||||
* These defines should only be edited if you have cake installed in
|
||||
* These defines should only be edited if you have CakePHP installed in
|
||||
* a directory layout other than the way it is distributed.
|
||||
* When using custom settings be sure to use the DS and do not add a trailing DS.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The full path to the directory which holds "app", WITHOUT a trailing DS.
|
||||
*
|
||||
*/
|
||||
if (!defined('ROOT')) {
|
||||
define('ROOT', dirname(dirname(dirname(__FILE__))));
|
||||
|
@ -33,7 +32,6 @@ if (!defined('ROOT')) {
|
|||
|
||||
/**
|
||||
* The actual directory name for the "app".
|
||||
*
|
||||
*/
|
||||
if (!defined('APP_DIR')) {
|
||||
define('APP_DIR', basename(dirname(dirname(__FILE__))));
|
||||
|
@ -52,10 +50,19 @@ if (!defined('APP_DIR')) {
|
|||
*/
|
||||
//define('CAKE_CORE_INCLUDE_PATH', __CAKE_PATH__);
|
||||
|
||||
/**
|
||||
* This auto-detects CakePHP as a composer installed library.
|
||||
* You may remove this if you are not planning to use composer (not recommended, though).
|
||||
*/
|
||||
$vendorPath = ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib';
|
||||
$dispatcher = 'Cake' . DS . 'Console' . DS . 'ShellDispatcher.php';
|
||||
if (!defined('CAKE_CORE_INCLUDE_PATH') && file_exists($vendorPath . DS . $dispatcher)) {
|
||||
define('CAKE_CORE_INCLUDE_PATH', $vendorPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Editing below this line should not be necessary.
|
||||
* Change at your own risk.
|
||||
*
|
||||
*/
|
||||
if (!defined('WEBROOT_DIR')) {
|
||||
define('WEBROOT_DIR', basename(dirname(__FILE__)));
|
||||
|
|
|
@ -24,12 +24,12 @@ canonicalize() {
|
|||
if [ -f "$NAME" ]
|
||||
then
|
||||
DIR=$(dirname -- "$NAME")
|
||||
NAME=$(cd -P "$DIR" && pwd -P)/$(basename -- "$NAME")
|
||||
NAME=$(cd -P "$DIR" > /dev/null && pwd -P)/$(basename -- "$NAME")
|
||||
fi
|
||||
while [ -h "$NAME" ]; do
|
||||
DIR=$(dirname -- "$NAME")
|
||||
SYM=$(readlink "$NAME")
|
||||
NAME=$(cd "$DIR" && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
|
||||
NAME=$(cd "$DIR" > /dev/null && cd $(dirname -- "$SYM") > /dev/null && pwd)/$(basename -- "$SYM")
|
||||
done
|
||||
echo "$NAME"
|
||||
}
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
::
|
||||
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
|
||||
:: In order for this script to work as intended, the cake\console\ folder must be in your PATH
|
||||
|
||||
@echo.
|
||||
@echo off
|
||||
|
||||
SET app=%0
|
||||
|
|
|
@ -17,21 +17,24 @@
|
|||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
$ds = DIRECTORY_SEPARATOR;
|
||||
$dispatcher = 'Cake' . $ds . 'Console' . $ds . 'ShellDispatcher.php';
|
||||
if (!defined('DS')) {
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
$dispatcher = 'Cake' . DS . 'Console' . DS . 'ShellDispatcher.php';
|
||||
$found = false;
|
||||
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($path . $ds . $dispatcher)) {
|
||||
if (file_exists($path . DS . $dispatcher)) {
|
||||
$found = $path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
$rootInstall = dirname(dirname(dirname(__FILE__))) . $ds . $dispatcher;
|
||||
$composerInstall = dirname(dirname(__FILE__)) . $ds . $dispatcher;
|
||||
$rootInstall = dirname(dirname(dirname(__FILE__))) . DS . $dispatcher;
|
||||
$composerInstall = dirname(dirname(__FILE__)) . DS . $dispatcher;
|
||||
|
||||
if (file_exists($composerInstall)) {
|
||||
include $composerInstall;
|
||||
|
@ -40,10 +43,12 @@ if (!$found) {
|
|||
} else {
|
||||
trigger_error('Could not locate CakePHP core files.', E_USER_ERROR);
|
||||
}
|
||||
unset($rootInstall, $composerInstall);
|
||||
|
||||
} else {
|
||||
include $found . $ds . $dispatcher;
|
||||
include $found . DS . $dispatcher;
|
||||
}
|
||||
|
||||
unset($paths, $path, $found, $dispatcher, $root, $ds);
|
||||
unset($paths, $path, $found, $dispatcher);
|
||||
|
||||
return ShellDispatcher::run($argv);
|
||||
|
|
|
@ -39,8 +39,8 @@ class CakeErrorController extends AppController {
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CakeRequest $request
|
||||
* @param CakeResponse $response
|
||||
* @param CakeRequest $request Request instance.
|
||||
* @param CakeResponse $response Response instance.
|
||||
*/
|
||||
public function __construct($request = null, $response = null) {
|
||||
parent::__construct($request, $response);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -155,9 +153,9 @@ class Component extends Object {
|
|||
*
|
||||
* @param Controller $controller Controller with components to beforeRedirect
|
||||
* @param string|array $url Either the string or URL array that is being redirected to.
|
||||
* @param integer $status The status code of the redirect
|
||||
* @param boolean $exit Will the script exit.
|
||||
* @return array|void Either an array or null.
|
||||
* @param int $status The status code of the redirect
|
||||
* @param bool $exit Will the script exit.
|
||||
* @return array|null Either an array or null.
|
||||
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRedirect
|
||||
*/
|
||||
public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {
|
||||
|
|
|
@ -28,7 +28,7 @@ interface AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function check($aro, $aco, $action = "*");
|
||||
|
||||
|
@ -38,7 +38,7 @@ interface AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function allow($aro, $aco, $action = "*");
|
||||
|
||||
|
@ -48,7 +48,7 @@ interface AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function deny($aro, $aco, $action = "*");
|
||||
|
||||
|
@ -58,14 +58,14 @@ interface AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function inherit($aro, $aco, $action = "*");
|
||||
|
||||
/**
|
||||
* Initialization method for the Acl implementation
|
||||
*
|
||||
* @param AclComponent $component
|
||||
* @param Component $component The AclComponent instance.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(Component $component);
|
||||
|
|
|
@ -29,11 +29,11 @@ App::uses('ClassRegistry', 'Utility');
|
|||
*
|
||||
* Would point to a tree structure like
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* controllers
|
||||
* Users
|
||||
* edit
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* @package Cake.Controller.Component.Acl
|
||||
*/
|
||||
|
@ -41,7 +41,6 @@ class DbAcl extends Object implements AclInterface {
|
|||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
@ -53,7 +52,7 @@ class DbAcl extends Object implements AclInterface {
|
|||
/**
|
||||
* Initializes the containing component and sets the Aro/Aco objects to it.
|
||||
*
|
||||
* @param AclComponent $component
|
||||
* @param AclComponent $component The AclComponent instance.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(Component $component) {
|
||||
|
@ -67,7 +66,7 @@ class DbAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success (true if ARO has access to action in ACO, false otherwise)
|
||||
* @return bool Success (true if ARO has access to action in ACO, false otherwise)
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html#checking-permissions-the-acl-component
|
||||
*/
|
||||
public function check($aro, $aco, $action = "*") {
|
||||
|
@ -80,8 +79,8 @@ class DbAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $actions Action (defaults to *)
|
||||
* @param integer $value Value to indicate access type (1 to give access, -1 to deny, 0 to inherit)
|
||||
* @return boolean Success
|
||||
* @param int $value Value to indicate access type (1 to give access, -1 to deny, 0 to inherit)
|
||||
* @return bool Success
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html#assigning-permissions
|
||||
*/
|
||||
public function allow($aro, $aco, $actions = "*", $value = 1) {
|
||||
|
@ -94,7 +93,7 @@ class DbAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html#assigning-permissions
|
||||
*/
|
||||
public function deny($aro, $aco, $action = "*") {
|
||||
|
@ -107,7 +106,7 @@ class DbAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function inherit($aro, $aco, $action = "*") {
|
||||
return $this->allow($aro, $aco, $action, 0);
|
||||
|
@ -119,7 +118,7 @@ class DbAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
* @see allow()
|
||||
*/
|
||||
public function grant($aro, $aco, $action = "*") {
|
||||
|
@ -132,7 +131,7 @@ class DbAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
* @see deny()
|
||||
*/
|
||||
public function revoke($aro, $aco, $action = "*") {
|
||||
|
|
|
@ -43,7 +43,7 @@ class IniAcl extends Object implements AclInterface {
|
|||
/**
|
||||
* Initialize method
|
||||
*
|
||||
* @param AclBase $component
|
||||
* @param Component $component The AclComponent instance.
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(Component $component) {
|
||||
|
@ -55,7 +55,7 @@ class IniAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function allow($aro, $aco, $action = "*") {
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ class IniAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function deny($aro, $aco, $action = "*") {
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class IniAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function inherit($aro, $aco, $action = "*") {
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ class IniAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO
|
||||
* @param string $aco ACO
|
||||
* @param string $action Action
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function check($aro, $aco, $action = null) {
|
||||
if (!$this->config) {
|
||||
|
|
|
@ -27,14 +27,14 @@ class PhpAcl extends Object implements AclInterface {
|
|||
/**
|
||||
* Constant for deny
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
const DENY = false;
|
||||
|
||||
/**
|
||||
* Constant for allow
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
const ALLOW = true;
|
||||
|
||||
|
@ -68,7 +68,7 @@ class PhpAcl extends Object implements AclInterface {
|
|||
*/
|
||||
public function __construct() {
|
||||
$this->options = array(
|
||||
'policy' => self::DENY,
|
||||
'policy' => static::DENY,
|
||||
'config' => APP . 'Config' . DS . 'acl.php',
|
||||
);
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ class PhpAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function allow($aro, $aco, $action = "*") {
|
||||
return $this->Aco->access($this->Aro->resolve($aro), $aco, $action, 'allow');
|
||||
|
@ -136,7 +136,7 @@ class PhpAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function deny($aro, $aco, $action = "*") {
|
||||
return $this->Aco->access($this->Aro->resolve($aro), $aco, $action, 'deny');
|
||||
|
@ -148,7 +148,7 @@ class PhpAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO The requesting object identifier.
|
||||
* @param string $aco ACO The controlled object identifier.
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function inherit($aro, $aco, $action = "*") {
|
||||
return false;
|
||||
|
@ -161,7 +161,7 @@ class PhpAcl extends Object implements AclInterface {
|
|||
* @param string $aro ARO
|
||||
* @param string $aco ACO
|
||||
* @param string $action Action
|
||||
* @return boolean true if access is granted, false otherwise
|
||||
* @return bool true if access is granted, false otherwise
|
||||
*/
|
||||
public function check($aro, $aco, $action = "*") {
|
||||
$allow = $this->options['policy'];
|
||||
|
@ -196,7 +196,6 @@ class PhpAcl extends Object implements AclInterface {
|
|||
|
||||
/**
|
||||
* Access Control Object
|
||||
*
|
||||
*/
|
||||
class PhpAco {
|
||||
|
||||
|
@ -252,7 +251,7 @@ class PhpAco {
|
|||
}
|
||||
|
||||
foreach ($root as $node => $elements) {
|
||||
$pattern = '/^' . str_replace(array_keys(self::$modifiers), array_values(self::$modifiers), $node) . '$/';
|
||||
$pattern = '/^' . str_replace(array_keys(static::$modifiers), array_values(static::$modifiers), $node) . '$/';
|
||||
|
||||
if ($node == $aco[$level] || preg_match($pattern, $aco[$level])) {
|
||||
// merge allow/denies with $path of current level
|
||||
|
@ -361,7 +360,6 @@ class PhpAco {
|
|||
|
||||
/**
|
||||
* Access Request Object
|
||||
*
|
||||
*/
|
||||
class PhpAro {
|
||||
|
||||
|
@ -407,9 +405,9 @@ class PhpAro {
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $aro
|
||||
* @param array $map
|
||||
* @param array $aliases
|
||||
* @param array $aro The aro data
|
||||
* @param array $map The identifier mappings
|
||||
* @param array $aliases The aliases to map.
|
||||
*/
|
||||
public function __construct(array $aro = array(), array $map = array(), array $aliases = array()) {
|
||||
if (!empty($map)) {
|
||||
|
@ -462,7 +460,7 @@ class PhpAro {
|
|||
$mapped = '';
|
||||
|
||||
if (is_array($aro)) {
|
||||
if (isset($aro['model']) && isset($aro['foreign_key']) && $aro['model'] == $aroGroup) {
|
||||
if (isset($aro['model']) && isset($aro['foreign_key']) && $aro['model'] === $aroGroup) {
|
||||
$mapped = $aroGroup . '/' . $aro['foreign_key'];
|
||||
} elseif (isset($aro[$model][$field])) {
|
||||
$mapped = $aroGroup . '/' . $aro[$model][$field];
|
||||
|
@ -479,7 +477,7 @@ class PhpAro {
|
|||
|
||||
$aroModel = Inflector::camelize($aroModel);
|
||||
|
||||
if ($aroModel == $model || $aroModel == $aroGroup) {
|
||||
if ($aroModel === $model || $aroModel === $aroGroup) {
|
||||
$mapped = $aroGroup . '/' . $aroValue;
|
||||
}
|
||||
}
|
||||
|
@ -494,7 +492,7 @@ class PhpAro {
|
|||
return $this->aliases[$mapped];
|
||||
}
|
||||
}
|
||||
return self::DEFAULT_ROLE;
|
||||
return static::DEFAULT_ROLE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,8 +21,8 @@ App::uses('AclInterface', 'Controller/Component/Acl');
|
|||
* Access Control List factory class.
|
||||
*
|
||||
* Uses a strategy pattern to allow custom ACL implementations to be used with the same component interface.
|
||||
* You can define by changing `Configure::write('Acl.classname', 'DbAcl');` in your core.php. Concrete ACL
|
||||
* implementations should extend `AclBase` and implement the methods it defines.
|
||||
* You can define by changing `Configure::write('Acl.classname', 'DbAcl');` in your core.php. The adapter
|
||||
* you specify must implement `AclInterface`
|
||||
*
|
||||
* @package Cake.Controller.Component
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/components/access-control-lists.html
|
||||
|
@ -53,8 +53,8 @@ class AclComponent extends Component {
|
|||
/**
|
||||
* Constructor. Will return an instance of the correct ACL class as defined in `Configure::read('Acl.classname')`
|
||||
*
|
||||
* @param ComponentCollection $collection
|
||||
* @param array $settings
|
||||
* @param ComponentCollection $collection Collection instance.
|
||||
* @param array $settings Settings list.
|
||||
* @throws CakeException when Acl.classname could not be loaded.
|
||||
*/
|
||||
public function __construct(ComponentCollection $collection, $settings = array()) {
|
||||
|
@ -79,7 +79,7 @@ class AclComponent extends Component {
|
|||
* Will call the initialize method on the adapter if setting a new one.
|
||||
*
|
||||
* @param AclInterface|string $adapter Instance of AclInterface or a string name of the class to use. (optional)
|
||||
* @return AclInterface|void either null, or the adapter implementation.
|
||||
* @return AclInterface|null Either null, or the adapter implementation.
|
||||
* @throws CakeException when the given class is not an instance of AclInterface
|
||||
*/
|
||||
public function adapter($adapter = null) {
|
||||
|
@ -92,7 +92,7 @@ class AclComponent extends Component {
|
|||
}
|
||||
$this->_Instance = $adapter;
|
||||
$this->_Instance->initialize($this);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
return $this->_Instance;
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class AclComponent extends Component {
|
|||
* @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
|
||||
* @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function check($aro, $aco, $action = "*") {
|
||||
return $this->_Instance->check($aro, $aco, $action);
|
||||
|
@ -117,7 +117,7 @@ class AclComponent extends Component {
|
|||
* @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
|
||||
* @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function allow($aro, $aco, $action = "*") {
|
||||
return $this->_Instance->allow($aro, $aco, $action);
|
||||
|
@ -130,7 +130,7 @@ class AclComponent extends Component {
|
|||
* @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
|
||||
* @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function deny($aro, $aco, $action = "*") {
|
||||
return $this->_Instance->deny($aro, $aco, $action);
|
||||
|
@ -143,7 +143,7 @@ class AclComponent extends Component {
|
|||
* @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
|
||||
* @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @return bool Success
|
||||
*/
|
||||
public function inherit($aro, $aco, $action = "*") {
|
||||
return $this->_Instance->inherit($aro, $aco, $action);
|
||||
|
@ -155,8 +155,8 @@ class AclComponent extends Component {
|
|||
* @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
|
||||
* @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @deprecated Will be removed in 3.0.
|
||||
* @return bool Success
|
||||
* @deprecated 3.0.0 Will be removed in 3.0.
|
||||
*/
|
||||
public function grant($aro, $aco, $action = "*") {
|
||||
trigger_error(__d('cake_dev', '%s is deprecated, use %s instead', 'AclComponent::grant()', 'allow()'), E_USER_WARNING);
|
||||
|
@ -169,8 +169,8 @@ class AclComponent extends Component {
|
|||
* @param array|string|Model $aro ARO The requesting object identifier. See `AclNode::node()` for possible formats
|
||||
* @param array|string|Model $aco ACO The controlled object identifier. See `AclNode::node()` for possible formats
|
||||
* @param string $action Action (defaults to *)
|
||||
* @return boolean Success
|
||||
* @deprecated Will be removed in 3.0.
|
||||
* @return bool Success
|
||||
* @deprecated 3.0.0 Will be removed in 3.0.
|
||||
*/
|
||||
public function revoke($aro, $aco, $action = "*") {
|
||||
trigger_error(__d('cake_dev', '%s is deprecated, use %s instead', 'AclComponent::revoke()', 'deny()'), E_USER_WARNING);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -66,8 +64,8 @@ abstract class AbstractPasswordHasher {
|
|||
* and check against existing hash.
|
||||
*
|
||||
* @param string|array $password Plain text password to hash or data array.
|
||||
* @param string Existing hashed password.
|
||||
* @return boolean True if hashes match else false.
|
||||
* @param string $hashedPassword Existing hashed password.
|
||||
* @return bool True if hashes match else false.
|
||||
*/
|
||||
abstract public function check($password, $hashedPassword);
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -32,7 +30,7 @@ class ActionsAuthorize extends BaseAuthorize {
|
|||
*
|
||||
* @param array $user The user to authorize
|
||||
* @param CakeRequest $request The request needing authorization.
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize($user, CakeRequest $request) {
|
||||
$Acl = $this->_Collection->load('Acl');
|
||||
|
|
|
@ -14,19 +14,21 @@
|
|||
|
||||
App::uses('Security', 'Utility');
|
||||
App::uses('Hash', 'Utility');
|
||||
App::uses('CakeEventListener', 'Event');
|
||||
|
||||
/**
|
||||
* Base Authentication class with common methods and properties.
|
||||
*
|
||||
* @package Cake.Controller.Component.Auth
|
||||
*/
|
||||
abstract class BaseAuthenticate {
|
||||
abstract class BaseAuthenticate implements CakeEventListener {
|
||||
|
||||
/**
|
||||
* Settings for this object.
|
||||
*
|
||||
* - `fields` The fields to use to identify a user by.
|
||||
* - `userModel` The model name of the User, defaults to User.
|
||||
* - `userFields` Array of fields to retrieve from User model, null to retrieve all. Defaults to null.
|
||||
* - `scope` Additional conditions to use when looking up and authenticating users,
|
||||
* i.e. `array('User.is_active' => 1).`
|
||||
* - `recursive` The value of the recursive key passed to find(). Defaults to 0.
|
||||
|
@ -43,6 +45,7 @@ abstract class BaseAuthenticate {
|
|||
'password' => 'password'
|
||||
),
|
||||
'userModel' => 'User',
|
||||
'userFields' => null,
|
||||
'scope' => array(),
|
||||
'recursive' => 0,
|
||||
'contain' => null,
|
||||
|
@ -63,6 +66,15 @@ abstract class BaseAuthenticate {
|
|||
*/
|
||||
protected $_passwordHasher;
|
||||
|
||||
/**
|
||||
* Implemented events
|
||||
*
|
||||
* @return array of events => callbacks.
|
||||
*/
|
||||
public function implementedEvents() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
@ -86,7 +98,7 @@ abstract class BaseAuthenticate {
|
|||
*
|
||||
* @param string|array $username The username/identifier, or an array of find conditions.
|
||||
* @param string $password The password, only used if $username param is string.
|
||||
* @return boolean|array Either false on failure, or an array of user data.
|
||||
* @return bool|array Either false on failure, or an array of user data.
|
||||
*/
|
||||
protected function _findUser($username, $password = null) {
|
||||
$userModel = $this->settings['userModel'];
|
||||
|
@ -105,9 +117,15 @@ abstract class BaseAuthenticate {
|
|||
$conditions = array_merge($conditions, $this->settings['scope']);
|
||||
}
|
||||
|
||||
$userFields = $this->settings['userFields'];
|
||||
if ($password !== null && $userFields !== null) {
|
||||
$userFields[] = $model . '.' . $fields['password'];
|
||||
}
|
||||
|
||||
$result = ClassRegistry::init($userModel)->find('first', array(
|
||||
'conditions' => $conditions,
|
||||
'recursive' => $this->settings['recursive'],
|
||||
'fields' => $userFields,
|
||||
'contain' => $this->settings['contain'],
|
||||
));
|
||||
if (empty($result[$model])) {
|
||||
|
@ -166,7 +184,7 @@ abstract class BaseAuthenticate {
|
|||
*
|
||||
* @param string $password The plain text password.
|
||||
* @return string The hashed form of the password.
|
||||
* @deprecated Since 2.4. Use a PasswordHasher class instead.
|
||||
* @deprecated 3.0.0 Since 2.4. Use a PasswordHasher class instead.
|
||||
*/
|
||||
protected function _password($password) {
|
||||
return Security::hash($password, null, true);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -79,8 +77,8 @@ abstract class BaseAuthorize {
|
|||
* Checks user authorization.
|
||||
*
|
||||
* @param array $user Active user data
|
||||
* @param CakeRequest $request
|
||||
* @return boolean
|
||||
* @param CakeRequest $request Request instance.
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function authorize($user, CakeRequest $request);
|
||||
|
||||
|
@ -107,7 +105,7 @@ abstract class BaseAuthorize {
|
|||
* that need to get information about the plugin, controller, and action being invoked.
|
||||
*
|
||||
* @param CakeRequest $request The request a path is needed for.
|
||||
* @param string $path
|
||||
* @param string $path Path format.
|
||||
* @return string the action path for the given request.
|
||||
*/
|
||||
public function action(CakeRequest $request, $path = '/:plugin/:controller/:action') {
|
||||
|
@ -126,25 +124,25 @@ abstract class BaseAuthorize {
|
|||
*
|
||||
* Create additional mappings for a standard CRUD operation:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* $this->Auth->mapActions(array('create' => array('add', 'register'));
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* Or equivalently:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* $this->Auth->mapActions(array('register' => 'create', 'add' => 'create'));
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* Create mappings for custom CRUD operations:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* $this->Auth->mapActions(array('range' => 'search'));
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* You can use the custom CRUD operations to create additional generic permissions
|
||||
* that behave like CRUD operations. Doing this will require additional columns on the
|
||||
* permissions lookup. For example if one wanted an additional search CRUD operation
|
||||
* permissions lookup. For example if one wanted an additional search CRUD operation
|
||||
* one would create and additional column '_search' in the aros_acos table. One could
|
||||
* create a custom admin CRUD operation for administration functions similarly if needed.
|
||||
*
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -19,24 +17,33 @@ App::uses('BaseAuthenticate', 'Controller/Component/Auth');
|
|||
/**
|
||||
* Basic Authentication adapter for AuthComponent.
|
||||
*
|
||||
* Provides Basic HTTP authentication support for AuthComponent. Basic Auth will authenticate users
|
||||
* against the configured userModel and verify the username and passwords match. Clients using Basic Authentication
|
||||
* must support cookies. Since AuthComponent identifies users based on Session contents, clients using Basic
|
||||
* Auth must support cookies.
|
||||
* Provides Basic HTTP authentication support for AuthComponent. Basic Auth will
|
||||
* authenticate users against the configured userModel and verify the username
|
||||
* and passwords match.
|
||||
*
|
||||
* ### Using Basic auth
|
||||
*
|
||||
* In your controller's components array, add auth + the required settings.
|
||||
* {{{
|
||||
* ```
|
||||
* public $components = array(
|
||||
* 'Auth' => array(
|
||||
* 'authenticate' => array('Basic')
|
||||
* )
|
||||
* );
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* In your login function just call `$this->Auth->login()` without any checks for POST data. This
|
||||
* will send the authentication headers, and trigger the login dialog in the browser/client.
|
||||
* You should also set `AuthComponent::$sessionKey = false;` in your AppController's
|
||||
* beforeFilter() to prevent CakePHP from sending a session cookie to the client.
|
||||
*
|
||||
* Since HTTP Basic Authentication is stateless you don't need a login() action
|
||||
* in your controller. The user credentials will be checked on each request. If
|
||||
* valid credentials are not provided, required authentication headers will be sent
|
||||
* by this authentication provider which triggers the login dialog in the browser/client.
|
||||
*
|
||||
* You may also want to use `$this->Auth->unauthorizedRedirect = false;`.
|
||||
* By default, unauthorized users are redirected to the referrer URL,
|
||||
* `AuthComponent::$loginAction`, or '/'. If unauthorizedRedirect is set to
|
||||
* false, a ForbiddenException exception is thrown instead of redirecting.
|
||||
*
|
||||
* @package Cake.Controller.Component.Auth
|
||||
* @since 2.0
|
||||
|
@ -78,7 +85,7 @@ class BasicAuthenticate extends BaseAuthenticate {
|
|||
$username = env('PHP_AUTH_USER');
|
||||
$pass = env('PHP_AUTH_PW');
|
||||
|
||||
if (empty($username) || empty($pass)) {
|
||||
if (!is_string($username) || $username === '' || !is_string($pass) || $pass === '') {
|
||||
return false;
|
||||
}
|
||||
return $this->_findUser($username, $pass);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -20,13 +18,13 @@ App::uses('FormAuthenticate', 'Controller/Component/Auth');
|
|||
* An authentication adapter for AuthComponent. Provides the ability to authenticate using POST data using Blowfish
|
||||
* hashing. Can be used by configuring AuthComponent to use it via the AuthComponent::$authenticate setting.
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* $this->Auth->authenticate = array(
|
||||
* 'Blowfish' => array(
|
||||
* 'scope' => array('User.active' => 1)
|
||||
* )
|
||||
* )
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* When configuring BlowfishAuthenticate you can pass in settings to which fields, model and additional conditions
|
||||
* are used. See FormAuthenticate::$settings for more information.
|
||||
|
@ -37,7 +35,7 @@ App::uses('FormAuthenticate', 'Controller/Component/Auth');
|
|||
* @package Cake.Controller.Component.Auth
|
||||
* @since CakePHP(tm) v 2.3
|
||||
* @see AuthComponent::$authenticate
|
||||
* @deprecated Since 2.4. Just use FormAuthenticate with 'passwordHasher' setting set to 'Blowfish'
|
||||
* @deprecated 3.0.0 Since 2.4. Just use FormAuthenticate with 'passwordHasher' setting set to 'Blowfish'
|
||||
*/
|
||||
class BlowfishAuthenticate extends FormAuthenticate {
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -40,8 +38,8 @@ class BlowfishPasswordHasher extends AbstractPasswordHasher {
|
|||
* Check hash. Generate hash for user provided password and check against existing hash.
|
||||
*
|
||||
* @param string $password Plain text password to hash.
|
||||
* @param string Existing hashed password.
|
||||
* @return boolean True if hashes match else false.
|
||||
* @param string $hashedPassword Existing hashed password.
|
||||
* @return bool True if hashes match else false.
|
||||
*/
|
||||
public function check($password, $hashedPassword) {
|
||||
return $hashedPassword === Security::hash($password, 'blowfish', $hashedPassword);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue