updating Acl to use Configure, adding config stack to CacheEngine, adding notices for defines to Configure, modifying bootstrap for Cache::config() updating tests for acl, auth, and cache.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5752 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-10-14 01:09:21 +00:00
parent 52f582bf44
commit 1eea608e0c
19 changed files with 392 additions and 431 deletions

View file

@ -98,7 +98,7 @@
/**
* A random string used in session management.
*/
define('CAKE_SESSION_STRING', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
define('CAKE_SESSION_STRING', '0qyJfIxDYhG93bfs2guVoUubWwvniR2G0FgaC9mi');
/**
* The name of CakePHP's session cookie.
*/
@ -157,55 +157,60 @@
* The classname and database used in CakePHP's
* access control lists.
*/
define('ACL_CLASSNAME', 'DB_ACL');
define('ACL_DATABASE', 'default');
Configure::write('Acl.classname', 'DB_ACL');
Configure::write('Acl.database', 'default');
/**
* Cache Engine Configuration
*
* File storage engine.
* default dir is /app/tmp/cache/
* $cakeCache = array('File', array(
* [optional] 'duration'=> 3600,
* [optional] 'probability'=> 100,
* [optional] 'dir' => '/tmp', // use system tmp directory - remember to use absolute path
* [optional] 'prefix' => 'cake_', // prefix every cache file with this string
* [optional] 'lock' => false, // use file locking
* [optional] 'serialize' => true,
* ));
* Cache::config('default', array('engine' => 'File' //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'path' => '/tmp', //[optional] use system tmp directory - remember to use absolute path
* 'prefix' => 'cake_', //[optional] prefix every cache file with this string
* 'lock' => false, //[optional] use file locking
* 'serialize' => true, [optional]
* )
* );
*
* APC (Alternative PHP Cache)
* $cakeCache = array('Apc', array(
* [optional] 'duration'=> 3600,
* [optional] 'probability'=> 100
* ));
* Cache::config('default', array('engine' => 'Apc' //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* )
* );
*
* Xcache (PHP opcode cacher)
* $cakeCache = array('Xcache', array(
* [optional] 'duration'=> 3600,
* [optional] 'probability'=> 100,
* 'user' => 'admin', // user from xcache.admin.user settings
* 'password' => 'your_password', // plaintext password (xcache.admin.pass)
* ));
* Cache::config('default', array('engine' => 'Xcache' //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'user' => 'admin', //user from xcache.admin.user settings
* password' => 'your_password', //plaintext password (xcache.admin.pass)
* )
* );
*
* Memcache
* $cakeCache = array('Memcache', array(
* [optional] 'duration'=> 3600,
* [optional] 'probability'=> 100,
* [optional] 'servers' => array(
* '127.0.0.1', // localhost, default port
* '10.0.0.1:12345', // port 12345
* ),
* [optional] 'compress' => true, // compress data in Memcache (slower, but uses less memory)
* ));
* Cache::config('default', array('engine' => 'Memcache' //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'servers' => array(
* '127.0.0.1', // localhost, default port
* '10.0.0.1:12345', // port 12345
* ), //[optional]
* 'compress' => true, // [optional] compress data in Memcache (slower, but uses less memory)
* )
* );
*
* Cake Model
* $cakeCache = array('Model', array(
* [optional] 'duration'=> 3600,
* [optional] 'probability'=> 100,
* [optional] 'className' => 'Cache',
* [optional] 'fields' => array('data' => 'data', 'expires => 'expires'),
* [optional] 'serialize' => true,
* ));
* Cache::config('default', array('engine' => 'Model' //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'className' => 'Cache', //[optional]
* 'fields' => array('data' => 'data', 'expires => 'expires'), //[optional]
* 'serialize' => true, [optional]
* )
* );
*/
$cakeCache = array('File');
Cache::config('default', array('engine' => 'File'));
?>

View file

@ -43,25 +43,20 @@ if (!defined('SERVER_IIS') && php_sapi_name() == 'isapi') {
require LIBS . 'inflector.php';
require LIBS . 'configure.php';
}
require LIBS . 'cache.php';
Configure::getInstance();
$cache = Cache::settings();
if(empty($cache)) {
trigger_error('Cache not configured. Please use Cache::config(); in APP/config/core.php', E_USER_WARNING);
Cache::config('default', array('engine' => 'File'));
}
require LIBS . 'session.php';
require LIBS . 'security.php';
require LIBS . 'string.php';
if (isset($cakeCache)) {
$cache = 'File';
if (isset($cakeCache[0])) {
$cache = $cakeCache[0];
}
$settings = array();
if (isset($cakeCache[1])) {
$settings = $cakeCache[1];
}
Cache::engine($cache, $settings);
} else {
Cache::engine();
}
Configure::store(null, 'class.paths');
Configure::load('class.paths');

View file

@ -40,8 +40,7 @@ class AclShell extends Shell {
* @var object
* @access public
*/
var $acl;
/**
var $Acl;
/**
* Contains arguments parsed from the command line.
*
@ -238,6 +237,7 @@ class AclShell extends Shell {
//add existence checks for nodes involved
$aro = ife(is_numeric($this->args[0]), intval($this->args[0]), $this->args[0]);
$aco = ife(is_numeric($this->args[1]), intval($this->args[1]), $this->args[1]);
if ($this->Acl->allow($aro, $aco, $this->args[2])) {
$this->out(__("Permission granted.", true), true);
}

View file

@ -156,55 +156,61 @@
* The classname and database used in CakePHP's
* access control lists.
*/
define('ACL_CLASSNAME', 'DB_ACL');
define('ACL_DATABASE', 'default');
Configure::write('Acl.classname', 'DB_ACL');
Configure::write('Acl.database', 'default');
/**
* Cache Engine Configuration
*
* File storage engine.
* default dir is /app/tmp/cache/
* $cakeCache = array('File', array(
* [optional] 'duration'=> 3600,
* [optional] 'probability'=> 100,
* [optional] 'dir' => '/tmp', // use system tmp directory - remember to use absolute path
* [optional] 'prefix' => 'cake_', // prefix every cache file with this string
* [optional] 'lock' => false, // use file locking
* [optional] 'serialize' => true,
* ));
* Cache::config('default', array('engine' => 'File' //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'path' => '/tmp', //[optional] use system tmp directory - remember to use absolute path
* 'prefix' => 'cake_', //[optional] prefix every cache file with this string
* 'lock' => false, //[optional] use file locking
* 'serialize' => true, [optional]
* )
* );
*
* APC (Alternative PHP Cache)
* $cakeCache = array('Apc', array(
* [optional] 'duration'=> 3600,
* [optional] 'probability'=> 100
* ));
* Cache::config('default', array('engine' => 'Apc' //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* )
* );
*
* Xcache (PHP opcode cacher)
* $cakeCache = array('Xcache', array(
* [optional] 'duration'=> 3600,
* [optional] 'probability'=> 100,
* 'user' => 'admin', // user from xcache.admin.user settings
* 'password' => 'your_password', // plaintext password (xcache.admin.pass)
* ));
* Cache::config('default', array('engine' => 'Xcache' //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'user' => 'admin', //user from xcache.admin.user settings
* password' => 'your_password', //plaintext password (xcache.admin.pass)
* )
* );
*
* Memcache
* $cakeCache = array('Memcache', array(
* [optional] 'duration'=> 3600,
* [optional] 'probability'=> 100,
* [optional] 'servers' => array(
* '127.0.0.1', // localhost, default port
* '10.0.0.1:12345', // port 12345
* ),
* [optional] 'compress' => true, // compress data in Memcache (slower, but uses less memory)
* ));
* Cache::config('default', array('engine' => 'Memcache' //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'servers' => array(
* '127.0.0.1', // localhost, default port
* '10.0.0.1:12345', // port 12345
* ), //[optional]
* 'compress' => true, // [optional] compress data in Memcache (slower, but uses less memory)
* )
* );
*
* Cake Model
* $cakeCache = array('Model', array(
* [optional] 'duration'=> 3600,
* [optional] 'probability'=> 100,
* [optional] 'className' => 'Cache',
* [optional] 'fields' => array('data' => 'data', 'expires => 'expires'),
* [optional] 'serialize' => true,
* ));
* Cache::config('default', array('engine' => 'Model' //[required]
* 'duration'=> 3600, //[optional]
* 'probability'=> 100, //[optional]
* 'className' => 'Cache', //[optional]
* 'fields' => array('data' => 'data', 'expires => 'expires'), //[optional]
* 'serialize' => true, [optional]
* )
* );
*/
$cakeCache = array('File');
Cache::config('default', array('engine' => 'File'));
?>

View file

@ -24,7 +24,7 @@ endif;
__('Your cache is set up and initialized properly.');
\$settings = Cache::settings();
echo '<p>';
echo sprintf(__('%s is being used to cache, to change this edit config'.DS.'core.php ', true), \$settings['name'] . 'Engine');
echo sprintf(__('%s is being used to cache, to change this edit config'.DS.'core.php ', true), \$settings['engine'] . 'Engine');
echo '</p>';
echo 'Settings: <ul>';

View file

@ -45,11 +45,21 @@ class Cache extends Object {
* @access protected
*/
var $_Engine = null;
/**
* Create cache.
* Cache configuration stack
*
* @var array
* @access private
*/
function __construct() {
}
var $__config = array();
/**
* Holds name of the current configuration being used
*
* @var array
* @access private
*/
var $__currentConfig = null;
/**
* Returns a singleton instance
*
@ -80,7 +90,47 @@ class Cache extends Object {
return true;
}
/**
* Set the cache engine to use
* Set the cache configuration to use
*
* @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(engine, settings) on success, false on failure
* @access public
*/
function config($name = 'default', $settings = array()) {
$_this =& Cache::getInstance();
if(is_array($name)) {
$config = array_merge(array('name' => 'default', 'settings'=> $settings), $name);
extract($config);
}
if(isset($_this->__config[$name])) {
$settings = array_merge($_this->__config[$name], $settings);
} elseif (!empty($settings)) {
$settings = $_this->__config[$name] = array_merge(array('engine' => 'File'), $settings);
} else {
$name = 'default';
$settings = $_this->__config['default'];
}
if(!empty($settings['engine'])) {
$engine = $settings['engine'];
}
if($name !== $_this->__currentConfig) {
if($_this->engine($engine, $settings)) {
$_this->__currentConfig = $name;
$settings = $_this->settings($engine);
$_this->__config[$name] = array_merge(array('engine' => $engine), $settings);
return compact('engine', 'settings');
}
return false;
}
return compact('engine', 'settings');
}
/**
* Set the cache engine to use or modify settings for one instance
*
* @param string $name Name of the engine (without 'Engine')
* @param array $settings Optional associative array of settings passed to the engine
@ -88,29 +138,27 @@ class Cache extends Object {
* @access public
*/
function engine($name = 'File', $settings = array()) {
if (Configure::read('Cache.disable')) {
if (!$name || Configure::read('Cache.disable')) {
return false;
}
$cacheClass = $name . 'Engine';
$_this =& Cache::getInstance();
if (!isset($_this->_Engine)) {
if (!isset($_this->_Engine[$name])) {
if ($_this->__loadEngine($name) === false) {
return false;
}
$_this->_Engine[$name] =& new $cacheClass();
}
if (!isset($_this->_Engine) || (isset($_this->_Engine) && $_this->_Engine->name !== $name)) {
$_this->_Engine =& new $cacheClass($name);
}
if ($_this->_Engine->init($settings)) {
if (time() % $_this->_Engine->settings['probability'] == 0) {
$_this->_Engine->gc();
if ($_this->_Engine[$name]->init($settings)) {
if (time() % $_this->_Engine[$name]->settings['probability'] == 0) {
$_this->_Engine[$name]->gc();
}
return true;
}
$_this->_Engine = null;
$_this->_Engine[$name] = null;
return false;
}
/**
@ -118,13 +166,23 @@ class Cache extends Object {
*
* @param string $key Identifier for the data
* @param mixed $value Data to be cached - anything except a resource
* @param mixed $duration Optional - how long to cache the data, either in seconds or a string that can be parsed by the strtotime() function
* @return boolean True if the data was succesfully cached, false on failure
* @param mixed $duration Optional - string configuration name OR how long to cache the data, either in seconds or a
* string that can be parsed by the strtotime() function OR array('config' => 'default', 'duration' => '3600')
* @return boolean True if the data was successfully cached, false on failure
* @access public
*/
function write($key, $value, $duration = null) {
$_this =& Cache::getInstance();
if (!$_this->isInitialized()) {
if(is_array($duration)) {
extract($duration);
} else {
$config = $duration;
}
$config = $_this->config($config);
extract($config);
if (!$_this->isInitialized($engine)) {
return false;
}
@ -135,90 +193,124 @@ class Cache extends Object {
if (is_resource($value)) {
return false;
}
if ($duration == null) {
$duration = $_this->_Engine->settings['duration'];
if(!$duration) {
$duration = $settings['duration'];
}
$duration = ife(is_string($duration), strtotime($duration) - time(), intval($duration));
if ($duration < 1) {
return false;
}
return $_this->_Engine->write($key, $value, $duration);
$success = $_this->_Engine[$engine]->write($key, $value, $duration);
$_this->_Engine[$engine]->init($settings);
return $success;
}
/**
* Read a key from the cache
*
* @param string $key Identifier for the data
* @param string $config name of the configuration to use
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
* @access public
*/
function read($key) {
function read($key, $config = null) {
$_this =& Cache::getInstance();
if (!$_this->isInitialized()) {
$config = $_this->config($config);
extract($config);
if (!$_this->isInitialized($engine)) {
return false;
}
$key = strval($key);
if (empty($key)) {
return false;
}
return $_this->_Engine->read($key);
$success = $_this->_Engine[$engine]->read($key);
$_this->_Engine[$engine]->init($settings);
return $success;
}
/**
* Delete a key from the cache
*
* @param string $key Identifier for the data
* @param string $config name of the configuration to use
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
* @access public
*/
function delete($key) {
function delete($key, $config = null) {
$_this =& Cache::getInstance();
if (!$_this->isInitialized()) {
$config = $_this->config($config);
extract($config);
if (!$_this->isInitialized($engine)) {
return false;
}
$key = strval($key);
if (empty($key)) {
return false;
}
return $_this->_Engine->delete($key);
$success = $_this->_Engine[$engine]->delete($key);
$_this->_Engine[$engine]->init($settings);
return $success;
}
/**
* Delete all keys from the cache
*
* @param boolean $check if true will check expiration, otherwise delete all
* @param string $config name of the configuration to use
* @return boolean True if the cache was succesfully cleared, false otherwise
* @access public
*/
function clear($check = false) {
function clear($check = false, $config = null) {
$_this =& Cache::getInstance();
if (!$_this->isInitialized()) {
$config = $_this->config($config);
extract($config);
if (!$_this->isInitialized($engine)) {
return false;
}
return $_this->_Engine->clear($check);
$success = $_this->_Engine[$engine]->clear($check);
$_this->_Engine[$engine]->init($settings);
return $success;
}
/**
* Check if Cache has initialized a working storage engine
*
* @param string $engine Name of the engine
* @param string $config Name of the configuration setting
* @return boolean
* @access public
*/
function isInitialized() {
function isInitialized($engine = null) {
if (Configure::read('Cache.disable')) {
return false;
}
$_this =& Cache::getInstance();
return isset($_this->_Engine);
if(!$engine) {
$engine = $_this->__config[$_this->__currentConfig]['engine'];
}
return isset($_this->_Engine[$engine]);
}
/**
* Return the settings for current cache engine
*
* @param string $engine Name of the engine
* @return array list of settings for this engine
* @access public
*/
function settings() {
function settings($engine = null) {
$_this =& Cache::getInstance();
if (!is_null($_this->_Engine)) {
return $_this->_Engine->settings();
if(!$engine && isset($_this->__config[$_this->__currentConfig]['engine'])) {
$engine = $_this->__config[$_this->__currentConfig]['engine'];
}
if (!is_null($_this->_Engine[$engine])) {
return $_this->_Engine[$engine]->settings();
}
return array();
}
}
/**
@ -229,13 +321,6 @@ class Cache extends Object {
*/
class CacheEngine extends Object {
/**
* Name of engine being used
*
* @var int
* @access public
*/
var $name;
/**
* settings of current engine instance
*
@ -244,15 +329,7 @@ class CacheEngine extends Object {
*/
var $settings;
/**
* Constructor
*
* @access private
*/
function __construct($name = null) {
$this->name = $name;
}
/**
* Set up the cache engine
* Iitialize the cache engine
*
* Called automatically by the cache frontend
*
@ -262,6 +339,7 @@ class CacheEngine extends Object {
*/
function init($settings = array()) {
$this->settings = am(array('duration'=> 3600, 'probability'=> 100), $settings);
return true;
}
/**
* Garbage collection
@ -319,7 +397,7 @@ class CacheEngine extends Object {
* @access public
*/
function settings() {
return am($this->settings, array('name'=> $this->name));
return $this->settings;
}
}
?>

View file

@ -82,13 +82,14 @@ class FileEngine extends CacheEngine {
function init($settings = array()) {
parent::init($settings);
$defaults = array('path' => CACHE, 'prefix'=> 'cake_', 'lock'=> false, 'serialize'=> true);
$this->settings = am($this->settings, $defaults, $settings);
$this->__Folder =& new Folder($this->settings['path']);
$this->settings['path'] = $this->__Folder->pwd();
$this->settings = am($defaults, $this->settings, $settings);
if(!isset($this->__Folder)) {
$this->__Folder =& new Folder();
}
$this->settings['path'] = $this->__Folder->cd($this->settings['path']);
if (!is_writable($this->settings['path'])) {
return false;
}
return true;
}
/**
@ -117,12 +118,10 @@ class FileEngine extends CacheEngine {
if ($duration == null) {
$duration = $this->settings['duration'];
}
if (isset($this->settings['serialize'])) {
if (!empty($this->settings['serialize'])) {
$data = serialize($data);
}
if (!$data) {
return false;
}
$file = $this->fullpath($key);
if ($file === false) {
return false;
@ -160,7 +159,8 @@ class FileEngine extends CacheEngine {
$data .= fgets($fp, 4096);
}
$data = trim($data);
if (isset($this->settings['serialize'])) {
if (!empty($this->settings['serialize'])) {
return unserialize($data);
}
return $data;
@ -228,9 +228,12 @@ class FileEngine extends CacheEngine {
}
$parts = array_map(array($this->__File , 'safe'), explode(DS, $key));
$key = array_pop($parts);
$dir = implode(DS, $parts) . DS;
$path = str_replace(DS . DS, DS, $this->settings['path'] . $dir);
$fullpath = $this->__Folder->realpath($path . $this->settings['prefix'] . $key);
$dir = null;
if(count($parts) > 0) {
$dir = implode(DS, $parts) . DS;
}
$path = str_replace(DS . DS, DS, $this->settings['path'] . DS . $dir . $this->settings['prefix'] . $key);
$fullpath = $this->__Folder->realpath($path);
if (!$this->__Folder->inPath($fullpath, true)) {
return false;
}

View file

@ -531,9 +531,8 @@ class Configure extends Object {
$componentPaths = null;
$behaviorPaths = null;
$pluginPaths = null;
if ($boot) {
if (!require_once(APP_PATH . 'config' . DS . 'core.php')) {
if (!include(APP_PATH . 'config' . DS . 'core.php')) {
trigger_error(sprintf(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", true), CONFIGS), E_USER_ERROR);
}
if (!include(APP_PATH . 'config' . DS . 'bootstrap.php')) {
@ -556,17 +555,25 @@ class Configure extends Object {
$_this->write('App', array('base' => false, 'baseUrl' => $baseUrl, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR));
if (defined('DEBUG')) {
trigger_error('Deprecated: Use Configure::write(\'debug\', ' . DEBUG . ');', E_USER_WARNING);
trigger_error('Deprecated: Use Configure::write(\'debug\', ' . DEBUG . '); in APP/config/core.php', E_USER_WARNING);
$_this->write('debug', DEBUG);
}
if (defined('CAKE_ADMIN')) {
trigger_error('CAKE_ADMIN Deprecated: Use Configure::write(\'Routing.admin\', \'' . CAKE_ADMIN . '\');', E_USER_WARNING);
trigger_error('CAKE_ADMIN Deprecated: Use Configure::write(\'Routing.admin\', \'' . CAKE_ADMIN . '\'); in APP/config/core.php', E_USER_WARNING);
$_this->write('Routing.admin', CAKE_ADMIN);
}
if (defined('WEBSERVICES')) {
trigger_error('WEBSERVICES Deprecated: Use Router::parseExtensions();', E_USER_WARNING);
$_this->write('Routing.webservices', WEBSERVICES);
}
if (defined('ACL_CLASSNAME')) {
trigger_error('ACL_CLASSNAME Deprecated. Use Configure::write(\'Acl.classname\'); in APP/config/core.php', E_USER_WARNING);
$_this->write('Acl.classname', ACL_CLASSNAME);
}
if (defined('ACL_DATABASE')) {
trigger_error('ACL_DATABASE Deprecated. Use Configure::write(\'Acl.database\'); in APP/config/core.php', E_USER_WARNING);
$_this->write('Acl.database', ACL_CLASSNAME);
}
}
}
?>

View file

@ -37,37 +37,31 @@
class AclComponent extends Object {
var $_instance = null;
var $name = ACL_CLASSNAME;
/**
* Constructor. Will return an instance of the correct ACL class.
*
*/
function startup(&$controller) {
$this->getACL();
function __construct() {
$name = Configure::read('Acl.classname');
if (!class_exists($name)) {
if (loadComponent($name)) {
if (strpos($name, '.') !== false) {
list($plugin, $name) = explode('.', $name);
}
$name .= 'Component';
} else {
trigger_error(sprintf(__('Could not find %s.', true), $name), E_USER_WARNING);
}
}
$this->_instance =& new $name();
$this->_instance->initialize($this);
}
/**
* Static function used to gain an instance of the correct ACL class.
* startup is not used
*
* @return MyACL
*/
function &getACL() {
if ($this->_instance == null) {
$name = $this->name;
if (!class_exists($name)) {
if (loadComponent($name)) {
if (strpos($name, '.') !== false) {
list($plugin, $name) = explode('.', $name);
}
$name .= 'Component';
} else {
trigger_error(sprintf(__('Could not find %s.', true), $name), E_USER_WARNING);
}
}
$this->_instance =& new $name();
$this->_instance->initialize($this);
}
return $this->_instance;
function startup(&$controller) {
return true;
}
/**
* Empty class defintion, to be overridden in subclasses.
@ -226,7 +220,9 @@ class DB_ACL extends AclBase {
*
*/
function __construct() {
uses('model' . DS . 'db_acl');
if(!class_exists('DB_ACL')) {
uses('model' . DS . 'db_acl');
}
parent::__construct();
$this->Aro =& new Aro();
$this->Aco =& new Aco();

View file

@ -26,9 +26,6 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
if (!defined('ACL_DATABASE')) {
define('ACL_DATABASE', 'default');
}
/**
* Short description for file
*

View file

@ -29,9 +29,6 @@
/**
* Set database config if not defined.
*/
if (!defined('ACL_DATABASE')) {
define('ACL_DATABASE', 'default');
}
/**
* Load Model and AppModel
*/
@ -46,8 +43,6 @@ loadModel();
* @subpackage cake.cake.libs.model
*/
class AclNode extends AppModel {
var $useDbConfig = ACL_DATABASE;
/**
* Explicitly disable in-memory query caching for ACL models
*
@ -60,6 +55,17 @@ class AclNode extends AppModel {
* @var mixed
*/
var $actsAs = array('Tree' => 'nested');
/**
* Constructor
*
*/
function __construct() {
$config = Configure::read('Acl.database');
if(isset($config)) {
$this->useDbConfig = $config;
}
parent::__construct();
}
/**
* Retrieves the Aro/Aco node for this model
*
@ -218,8 +224,6 @@ class Aro extends AclNode {
* @subpackage cake.cake.libs.model
*/
class Permission extends AppModel {
var $useDbConfig = ACL_DATABASE;
/**
* Enter description here...
*
@ -250,5 +254,16 @@ class Permission extends AppModel {
* @var unknown_type
*/
var $actsAs = null;
/**
* Constructor
*
*/
function __construct() {
$config = Configure::read('Acl.database');
if(isset($config)) {
$this->useDbConfig = $config;
}
parent::__construct();
}
}
?>

View file

@ -47,7 +47,7 @@ endif;
__('Your cache is set up and initialized properly.');
$settings = Cache::settings();
echo '<p>';
echo sprintf(__('%s is being used to cache, to change this edit config'.DS.'core.php ', true), $settings['name'] . 'Engine');
echo sprintf(__('%s is being used to cache, to change this edit config'.DS.'core.php ', true), $settings['engine'] . 'Engine');
echo '</p>';
echo 'Settings: <ul>';

View file

@ -36,7 +36,34 @@ uses('cache');
class CacheTest extends UnitTestCase {
function skip() {
$this->skipif (true, 'CacheTest not implemented');
$this->skipif (false, 'CacheTest not implemented');
}
function testConfig() {
$settings = array('engine' => 'File', 'path' => TMP . 'tests', 'prefix' => 'cake_test_');
$results = Cache::config('new', $settings);
$this->assertEqual($results, Cache::config('new'));
}
function testConfigChange() {
$result = Cache::config('sessions', array('engine'=> 'File', 'path' => TMP . 'sessions'));
$this->assertEqual($result['settings'], Cache::settings('File'));
$result = Cache::config('tests', array('engine'=> 'File', 'path' => TMP . 'tests'));
$this->assertEqual($result['settings'], Cache::settings('File'));
}
function testInitSettings() {
Cache::engine('File', array('path' => TMP . 'tests'));
$settings = Cache::settings();
$expecting = array('duration'=> 3600,
'probability' => 100,
'path'=> TMP . 'tests',
'prefix'=> 'cake_',
'lock' => false,
'serialize'=> true,
);
$this->assertEqual($settings, $expecting);
}
}
?>

View file

@ -42,6 +42,10 @@ class APCEngineTest extends UnitTestCase {
}
$this->skipif ($skip, 'APCEngineTest not implemented');
}
function setUp() {
Cache::config('apc', array('engine'=>'Apc'));
}
function testReadAndWriteCache() {
$result = Cache::read('test');
@ -87,5 +91,9 @@ class APCEngineTest extends UnitTestCase {
$result = Cache::delete('delete_test');
$this->assertTrue($result);
}
function tearDown() {
Cache::config('default');
}
}
?>

View file

@ -35,31 +35,32 @@ uses('cache', 'cache' . DS . 'file');
*/
class FileEngineTest extends UnitTestCase {
function setUp() {
Cache::engine();
function startTest() {
Cache::config();
}
function testSettings() {
Cache::engine('File', array('path' => TMP . 'tests'));
$settings = Cache::settings();
$expecting = array('duration'=> 3600,
'probability' => 100,
'path'=> TMP . 'tests',
'prefix'=> 'cake_',
'lock' => false,
'serialize'=> true,
'name' => 'File'
);
$this->assertEqual($settings, $expecting);
function testCacheDirChange() {
$result = Cache::config('sessions', array('engine'=> 'File', 'path' => TMP . 'sessions'));
$this->assertEqual($result['settings'], Cache::settings('File'));
$this->assertNotEqual($result, Cache::settings('File'));
$result = Cache::config('tests', array('engine'=> 'File', 'path' => TMP . 'tests'));
$this->assertEqual($result['settings'], Cache::settings('File'));
$this->assertNotEqual($result, Cache::settings('File'));
}
function testCacheName() {
Cache::config();
$cache =& Cache::getInstance();
$result = $cache->_Engine->fullpath('models' . DS . 'default_posts');
$engine = $cache->_Engine['File'];
$result = $engine->fullpath('models' . DS . 'default_posts');
$expecting = CACHE . 'models' . DS .'cake_default_posts';
$this->assertEqual($result, $expecting);
$result = $cache->_Engine->fullpath('default_posts');
$engine = $cache->_Engine['File'];
$result = $engine->fullpath('default_posts');
$expecting = CACHE . 'cake_default_posts';
$this->assertEqual($result, $expecting);
@ -108,19 +109,30 @@ class FileEngineTest extends UnitTestCase {
$result = Cache::delete('delete_test');
$this->assertTrue($result);
$this->assertFalse(file_exists(TMP . 'tests' . DS . 'delete_test'));
}
function testSerialize() {
Cache::engine('File', array('serialize' => true));
$data = 'this is a test of the emergency broadcasting system';
$write = Cache::write('seriailze_test', $data, 1);
$this->assertTrue($write);
Cache::engine('File', array('serialize' => false));
$read = Cache::read('seriailze_test');
$result = Cache::delete('seriailze_test');
$newread = Cache::read('seriailze_test');
$this->assertNotIdentical($write, $read);
$delete = Cache::delete('seriailze_test');
$this->assertIdentical($read, serialize($data));
$this->assertIdentical($newread, $data);
}
function tearDown() {
Cache::config('default');
}
}

View file

@ -44,7 +44,7 @@ class MemcacheEngineTest extends UnitTestCase {
}
function setUp() {
Cache::engine('Memcache');
Cache::config('memcache', array('engine'=>'Memcache'));
}
function testSettings() {
@ -53,14 +53,14 @@ class MemcacheEngineTest extends UnitTestCase {
'probability' => 100,
'servers' => array('127.0.0.1'),
'compress' => false,
'name' => 'Memcache'
'engine' => 'Memcache'
);
$this->assertEqual($settings, $expecting);
}
function testConnect() {
$Cache =& Cache::getInstance();
$result = $Cache->_Engine->connect('127.0.0.1');
$result = $Cache->_Engine['Memcache']->connect('127.0.0.1');
$this->assertTrue($result);
}
@ -109,5 +109,9 @@ class MemcacheEngineTest extends UnitTestCase {
$result = Cache::delete('delete_test');
$this->assertTrue($result);
}
function tearDown() {
Cache::config('default');
}
}
?>

View file

@ -44,16 +44,16 @@ class XcacheEngineTest extends UnitTestCase {
}
function setUp() {
Cache::engine('Xcache');
Cache::config('xcache', array('engine'=>'Xcache'));
}
function testSettings() {
$settings = Cache::settings();
$expecting = array('duration'=> 3600,
'probability' => 100,
'engine' => 'Xcache',
'PHP_AUTH_USER' => 'cake',
'PHP_AUTH_PW' => '',
'name' => 'Xcache'
'PHP_AUTH_PW' => 'cake',
);
$this->assertEqual($settings, $expecting);
}
@ -102,5 +102,9 @@ class XcacheEngineTest extends UnitTestCase {
$result = Cache::delete('delete_test');
$this->assertTrue($result);
}
function tearDown() {
Cache::config('default');
}
}
?>

View file

@ -29,95 +29,6 @@
uses('controller' . DS . 'components' . DS .'acl');
uses('controller'.DS.'components'.DS.'acl', 'model'.DS.'db_acl');
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
if(!class_exists('aclnodetestbase')) {
class AclNodeTestBase extends AclNode {
var $useDbConfig = 'test_suite';
var $cacheSources = false;
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
if(!class_exists('arotest')) {
class AroTest extends AclNodeTestBase {
var $name = 'AroTest';
var $useTable = 'aros';
var $hasAndBelongsToMany = array('AcoTest' => array('with' => 'PermissionTest'));
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
if(!class_exists('acotest')) {
class AcoTest extends AclNodeTestBase {
var $name = 'AcoTest';
var $useTable = 'acos';
var $hasAndBelongsToMany = array('AroTest' => array('with' => 'PermissionTest'));
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
if(!class_exists('permissiontest')) {
class PermissionTest extends CakeTestModel {
var $name = 'PermissionTest';
var $useTable = 'aros_acos';
var $cacheQueries = false;
var $belongsTo = array('AroTest' => array('foreignKey' => 'aro_id'),
'AcoTest' => array('foreignKey' => 'aco_id')
);
var $actsAs = null;
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
if(!class_exists('acoactiontest')) {
class AcoActionTest extends CakeTestModel {
var $name = 'AcoActionTest';
var $useTable = 'aco_actions';
var $belongsTo = array('AcoTest' => array('foreignKey' => 'aco_id'));
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
if(!class_exists('db_acl_test')) {
class DB_ACL_TEST extends DB_ACL {
function __construct() {
$this->Aro =& new AroTest();
$this->Aro->Permission =& new PermissionTest();
$this->Aco =& new AcoTest();
$this->Aro->Permission =& new PermissionTest();
}
}
}
/**
* Short description for class.
*
@ -125,22 +36,21 @@ if(!class_exists('db_acl_test')) {
* @subpackage cake.tests.cases.libs.controller.components
*/
class AclComponentTest extends CakeTestCase {
var $name = 'AclComponent';
var $fixtures = array('core.aro', 'core.aco', 'core.aros_aco', 'core.aco_action');
function skip() {
$this->skipif (true, 'AclComponentTest almost implemented');
$this->skipif (false, 'AclComponentTest almost implemented');
}
function setUp() {
function startTest() {
Configure::write('Acl.classname', 'DB_ACL');
Configure::write('Acl.database', 'test_suite');
$this->Acl =& new AclComponent();
$this->__testInitDbAcl();
}
function testInitDbAcl() {
$this->Acl->name = 'DB_ACL_TEST';
$controller = null;
$this->Acl->startup($controller);
function __testInitDbAcl() {
$this->Acl->Aro->id = null;
$this->Acl->Aro->create(array('alias'=>'Roles'));
@ -167,26 +77,18 @@ class AclComponentTest extends CakeTestCase {
$this->assertTrue($result);
$this->Acl->Aco->setParent(1, 2);
}
function testDbAclAllow() {
$this->Acl->name = 'DB_ACL_TEST';
$controller = null;
$this->Acl->startup($controller);
$result = $this->Acl->allow('Roles/Admin', 'Root');
$this->assertTrue($result);
$result = $this->Acl->allow('Roles/Admin', 'Root/AuthTest');
$this->assertTrue($result);
}
function testDbAclCheck() {
$this->Acl->name = 'DB_ACL_TEST';
$controller = null;
$this->Acl->startup($controller);
$aro = null;
$aco = null;
@ -199,9 +101,8 @@ class AclComponentTest extends CakeTestCase {
function testDbAclDeny() {
$this->Acl->name = 'DB_ACL_TEST';
$controller = null;
$this->Acl->startup($controller);
$action = "*";
$result = $this->Acl->deny('Roles/Admin', 'Root/AuthTest', $action);
$this->assertTrue($result);
@ -212,21 +113,17 @@ class AclComponentTest extends CakeTestCase {
}
function testDbAclInherit() {
$this->Acl->name = 'DB_ACL_TEST';
$controller = null;
$this->Acl->startup($controller);
$action = "*";
$result = $this->Acl->inherit('Roles/Admin', 'Root/AuthTest', $action);
$this->assertTrue($result);
}
function testDbAclGrant() {
$this->Acl->name = 'DB_ACL_TEST';
$controller = null;
$this->Acl->startup($controller);
$aro = null;
$aco = null;
$aro = 'Roles/Admin';
$aco = 'Root/AuthTest';
$action = "*";
$result = $this->Acl->grant($aro, $aco, $action);
@ -234,12 +131,9 @@ class AclComponentTest extends CakeTestCase {
}
function testDbAclRevoke() {
$this->Acl->name = 'DB_ACL_TEST';
$controller = null;
$this->Acl->startup($controller);
$aro = null;
$aco = null;
$aro = 'Roles/Admin';
$aco = 'Root/AuthTest';
$action = "*";
$result = $this->Acl->revoke($aro, $aco, $action);
@ -247,7 +141,7 @@ class AclComponentTest extends CakeTestCase {
}
function tearDown() {
function endTest() {
unset($this->Acl);
}
}

View file

@ -29,95 +29,6 @@
uses('controller' . DS . 'components' . DS .'auth', 'controller' . DS . 'components' . DS .'acl');
uses('controller'.DS.'components'.DS.'acl', 'model'.DS.'db_acl');
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
if(!class_exists('aclnodetestbase')) {
class AclNodeTestBase extends AclNode {
var $useDbConfig = 'test_suite';
var $cacheSources = false;
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
if(!class_exists('arotest')) {
class AroTest extends AclNodeTestBase {
var $name = 'AroTest';
var $useTable = 'aros';
var $hasAndBelongsToMany = array('AcoTest' => array('with' => 'PermissionTest'));
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
if(!class_exists('acotest')) {
class AcoTest extends AclNodeTestBase {
var $name = 'AcoTest';
var $useTable = 'acos';
var $hasAndBelongsToMany = array('AroTest' => array('with' => 'PermissionTest'));
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
if(!class_exists('permissiontest')) {
class PermissionTest extends CakeTestModel {
var $name = 'PermissionTest';
var $useTable = 'aros_acos';
var $cacheQueries = false;
var $belongsTo = array('AroTest' => array('foreignKey' => 'aro_id'),
'AcoTest' => array('foreignKey' => 'aco_id')
);
var $actsAs = null;
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
if(!class_exists('acoactiontest')) {
class AcoActionTest extends CakeTestModel {
var $name = 'AcoActionTest';
var $useTable = 'aco_actions';
var $belongsTo = array('AcoTest' => array('foreignKey' => 'aco_id'));
}
}
/**
* Short description for class.
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.controller.components
*/
if(!class_exists('db_acl_test')) {
class DB_ACL_TEST extends DB_ACL {
function __construct() {
$this->Aro =& new AroTest();
$this->Aro->Permission =& new PermissionTest();
$this->Aco =& new AcoTest();
$this->Aro->Permission =& new PermissionTest();
}
}
}
/**
* Short description for class.
*
@ -195,7 +106,7 @@ class AuthTest extends CakeTestCase {
var $fixtures = array('core.auth_user', 'core.aro', 'core.aco', 'core.aros_aco', 'core.aco_action');
function setUp() {
function startTest() {
$this->Controller =& new AuthTestController();
restore_error_handler();
@$this->Controller->_initComponents();
@ -295,7 +206,6 @@ class AuthTest extends CakeTestCase {
$this->Controller->params['action'] = 'add';
$this->Controller->Acl->name = 'DB_ACL_TEST';
$this->Controller->Acl->startup($this->Controller);
$this->Controller->Acl->Aro->id = null;
$this->Controller->Acl->Aro->create(array('alias'=>'Roles'));