cakephp2-php8/cake/libs/model/db_acl.php
phpnut c000940e36 Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
Closes #2213, Support multiple plugin paths.
Closes #2234, filepaths to behavior classes should be cached in class.paths.php also
Closes #2345, ability to group components into subfolders
Closes #2645, Improvement to basic.php for class loading.
Fixes #3526, Cache::write, when using just the config name, it fails.
Fixes #3559, loading plugin model as assoc don't work.
Closes #3567 Controller Folders (Note this does not need routing to work, but controller names can not conflict with others in the same application so naming must still be unique)
Fixes #3579, email.php component: Parse error with php 4.

Adding new class and file importer.
Updated most of the core to use the importer.
Added ClassRegsitry::init() that will create and instance of an object and store it in the registry.
Deprecated most of the load functions in basics.php
Plugin model loading now forces using the dot notation, to use models within a plugin, all the model associations must be in the PluginName.Model syntax, if this is not used, the plugin will look for the models in the main app/models directory first, if not found then it will search the plugin directories recursively until it finds a model.
	var $belongsTo = array('SomeModel'); will look for some_model.php in the app/models
	var $belongsTo = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
	var $belongsTo = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
	
The controllers of the plugin will still look for the default models inside the plugin if var $uses is not set:
	var $uses = array('SomeModel'); will look for some_model.php in the app/models
	var $uses = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
	var $uses = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php

All of the above will work between plugins and main app
These changes also allow placing model and controllers is sub directories
Removed old class.paths.php file generation 

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6001 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-16 09:35:19 +00:00

295 lines
No EOL
7.3 KiB
PHP

<?php
/* SVN FILE: $Id$ */
/**
* This is core configuration file.
*
* Use it to configure core behaviour ofCake.
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.model
* @since CakePHP(tm) v 0.2.9
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* Set database config if not defined.
*/
/**
* Load Model and AppModel
*/
App::import('Model', 'App');
/**
* Short description for file.
*
* Long description for file
*
*
* @package cake
* @subpackage cake.cake.libs.model
*/
class AclNode extends AppModel {
/**
* Explicitly disable in-memory query caching for ACL models
*
* @var boolean
* @access public
*/
var $cacheQueries = false;
/**
* ACL models use the Tree behavior
*
* @var array
* @access public
*/
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
*
* @param mixed $ref Array with 'model' and 'foreign_key', model object, or string value
* @return array Node found in database
* @access public
*/
function node($ref = null) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$type = $this->alias;
$prefix = $this->tablePrefix;
$result = null;
if (!empty($this->useTable)) {
$table = $this->useTable;
} else {
$table = Inflector::pluralize(Inflector::underscore($type));
}
if (empty($ref)) {
return null;
} elseif (is_string($ref)) {
$path = explode('/', $ref);
$start = $path[0];
unset($path[0]);
$queryData = array('conditions' => array(
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft"),
$db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght")),
'fields' => array('id', 'parent_id', 'model', 'foreign_key', 'alias'),
'joins' => array(array('table' => $db->name($prefix . $table),
'alias' => "{$type}0",
'type' => 'LEFT',
'conditions' => array("{$type}0.alias" => $start))),
'order' => $db->name("{$type}.lft") . ' DESC');
foreach ($path as $i => $alias) {
$j = $i - 1;
array_push($queryData['joins'], array(
'table' => $db->name($prefix . $table),
'alias' => "{$type}{$i}",
'type' => 'LEFT',
'conditions' => array(
$db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft"),
$db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght"),
$db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias))));
$queryData['conditions'] = array('or' => array(
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght"),
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}{$i}.lft") . ' AND ' . $db->name("{$type}.rght") . ' >= ' . $db->name("{$type}{$i}.rght")));
}
$result = $db->read($this, $queryData, -1);
} elseif (is_object($ref) && is_a($ref, 'Model')) {
$ref = array('model' => $ref->alias, 'foreign_key' => $ref->id);
} elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) {
$name = key($ref);
if (!ClassRegistry::isKeySet($name)) {
if (!App::import($name)) {
trigger_error("Model class '$name' not found in AclNode::node() when trying to bind {$this->alias} object", E_USER_WARNING);
return null;
}
$model =& ClassRegistry::init(array('class' => $name, 'alias' => $name));
} else {
$model =& ClassRegistry::getObject($name);
}
$tmpRef = null;
if (method_exists($model, 'bindNode')) {
$tmpRef = $model->bindNode($ref);
}
if (empty($tmpRef)) {
$ref = array('model' => $name, 'foreign_key' => $ref[$name][$model->primaryKey]);
} else {
if (is_string($tmpRef)) {
return $this->node($tmpRef);
}
$ref = $tmpRef;
}
}
if (is_array($ref)) {
foreach ($ref as $key => $val) {
if (strpos($key, $type) !== 0) {
unset($ref[$key]);
$ref["{$type}0.{$key}"] = $val;
}
}
$queryData = array('conditions' => $ref,
'fields' => array('id', 'parent_id', 'model', 'foreign_key', 'alias'),
'joins' => array(array('table' => $db->name($prefix . $table),
'alias' => "{$type}0",
'type' => 'LEFT',
'conditions' => array(
$db->name("{$type}.lft") . ' <= ' . $db->name("{$type}0.lft"),
$db->name("{$type}.rght") . ' >= ' . $db->name("{$type}0.rght")))),
'order' => $db->name("{$type}.lft") . ' DESC');
$result = $db->read($this, $queryData, -1);
if (!$result) {
trigger_error("AclNode::node() - Couldn't find {$type} node identified by \"" . print_r($ref, true) . "\"", E_USER_WARNING);
}
}
return $result;
}
}
/**
* Access Control Object
*
* @package cake
* @subpackage cake.cake.libs.model
*/
class Aco extends AclNode {
/**
* Model name
*
* @var string
* @access public
*/
var $name = 'Aco';
/**
* Binds to ARO nodes through permissions settings
*
* @var array
* @access public
*/
var $hasAndBelongsToMany = array('Aro' => array('with' => 'Permission'));
}
/**
* Action for Access Control Object
*
* @package cake
* @subpackage cake.cake.libs.model
*/
class AcoAction extends AppModel {
/**
* Model name
*
* @var string
* @access public
*/
var $name = 'AcoAction';
/**
* ACO Actions belong to ACOs
*
* @var array
* @access public
*/
var $belongsTo = array('Aco');
}
/**
* Access Request Object
*
* @package cake
* @subpackage cake.cake.libs.model
*/
class Aro extends AclNode {
/**
* Model name
*
* @var string
* @access public
*/
var $name = 'Aro';
/**
* AROs are linked to ACOs by means of Permission
*
* @var array
* @access public
*/
var $hasAndBelongsToMany = array('Aco' => array('with' => 'Permission'));
}
/**
* Permissions linking AROs with ACOs
*
* @package cake
* @subpackage cake.cake.libs.model
*/
class Permission extends AppModel {
/**
* Model name
*
* @var string
* @access public
*/
var $name = 'Permission';
/**
* Explicitly disable in-memory query caching
*
* @var boolean
* @access public
*/
var $cacheQueries = false;
/**
* Override default table name
*
* @var string
* @access public
*/
var $useTable = 'aros_acos';
/**
* Permissions link AROs with ACOs
*
* @var array
* @access public
*/
var $belongsTo = array('Aro', 'Aco');
/**
* No behaviors for this model
*
* @var array
* @access public
*/
var $actsAs = null;
/**
* Constructor, used to tell this model to use the
* database configured for ACL
*/
function __construct() {
$config = Configure::read('Acl.database');
if (!empty($config)) {
$this->useDbConfig = $config;
}
parent::__construct();
}
}
?>