mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
"Initial refactoring of BehaviorCollection.
Fixed vendor path being the first searched directory for files, this caused unexpected results. Fixed failing DboSource tests" git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6583 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
d8a7097490
commit
a6fbe05964
5 changed files with 25 additions and 18 deletions
|
@ -459,6 +459,7 @@ class Configure extends Object {
|
|||
$paths = Cache::read('core_paths', '_cake_core_');
|
||||
if (!$paths) {
|
||||
$used = array();
|
||||
$vendor = false;
|
||||
$openBasedir = ini_get('open_basedir');
|
||||
|
||||
if ($openBasedir) {
|
||||
|
@ -501,10 +502,14 @@ class Configure extends Object {
|
|||
$paths['class'][] = $path . DS . 'cake' . DS;
|
||||
}
|
||||
if (is_dir($path . DS . 'vendors')) {
|
||||
$paths['vendor'][] = $path . DS . 'vendors' . DS;
|
||||
$vendor['vendor'][] = $path . DS . 'vendors' . DS;
|
||||
}
|
||||
$used[] = $path;
|
||||
}
|
||||
|
||||
if ($vendor) {
|
||||
$paths = array_merge($paths, $vendor);
|
||||
}
|
||||
Cache::write('core_paths', array_filter($paths), '_cake_core_');
|
||||
}
|
||||
if ($type && isset($paths[$type])) {
|
||||
|
|
|
@ -147,7 +147,7 @@ class ModelBehavior extends Object {
|
|||
function onError(&$model, $error) { }
|
||||
/**
|
||||
* Overrides Object::dispatchMethod to account for PHP4's broken reference support
|
||||
*
|
||||
*
|
||||
* @see Object::dispatchMethod
|
||||
* @access public
|
||||
*/
|
||||
|
@ -209,11 +209,11 @@ class ModelBehavior extends Object {
|
|||
class BehaviorCollection extends Object {
|
||||
|
||||
/**
|
||||
* Stores a reference to the attached model
|
||||
* Stores a reference to the attached name
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
var $model = null;
|
||||
var $modelName = null;
|
||||
/**
|
||||
* Lists the currently-attached behavior objects
|
||||
*
|
||||
|
@ -245,8 +245,8 @@ class BehaviorCollection extends Object {
|
|||
*
|
||||
* @access public
|
||||
*/
|
||||
function init(&$model, $behaviors = array()) {
|
||||
$this->model =& $model;
|
||||
function init($modelName, $behaviors = array()) {
|
||||
$this->modelName = $modelName;
|
||||
|
||||
if (!empty($behaviors)) {
|
||||
foreach (Set::normalize($behaviors) as $behavior => $config) {
|
||||
|
@ -289,10 +289,10 @@ class BehaviorCollection extends Object {
|
|||
}
|
||||
ClassRegistry::addObject($class, $this->{$name});
|
||||
}
|
||||
} elseif (isset($this->{$name}->settings) && isset($this->{$name}->settings[$this->model->alias])) {
|
||||
$config = array_merge($this->{$name}->settings[$this->model->alias], $config);
|
||||
} elseif (isset($this->{$name}->settings) && isset($this->{$name}->settings[$this->modelName])) {
|
||||
$config = array_merge($this->{$name}->settings[$this->modelName], $config);
|
||||
}
|
||||
$this->{$name}->setup($this->model, $config);
|
||||
$this->{$name}->setup(ClassRegistry::getObject($this->modelName), $config);
|
||||
|
||||
foreach ($this->{$name}->mapMethods as $method => $alias) {
|
||||
$this->__mappedMethods[$method] = array($alias, $name);
|
||||
|
@ -326,7 +326,7 @@ class BehaviorCollection extends Object {
|
|||
*/
|
||||
function detach($name) {
|
||||
if (isset($this->{$name})) {
|
||||
$this->{$name}->cleanup($this->model);
|
||||
$this->{$name}->cleanup(ClassRegistry::getObject($this->modelName));
|
||||
unset($this->{$name});
|
||||
}
|
||||
foreach ($this->__methods as $m => $callback) {
|
||||
|
|
|
@ -389,7 +389,7 @@ class Model extends Overloadable {
|
|||
}
|
||||
}
|
||||
$this->Behaviors = new BehaviorCollection();
|
||||
$this->Behaviors->init($this, $this->actsAs);
|
||||
$this->Behaviors->init($this->alias, $this->actsAs);
|
||||
}
|
||||
/**
|
||||
* Handles custom method calls, like findBy<field> for DB models,
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
uses('class_registry');
|
||||
App::import('Core', 'ClassRegistry');
|
||||
class ClassRegisterModel extends CakeTestModel {
|
||||
var $useTable = false;
|
||||
}
|
||||
|
|
|
@ -600,13 +600,13 @@ class DboSourceTest extends CakeTestCase {
|
|||
config('database');
|
||||
$config = new DATABASE_CONFIG();
|
||||
if (isset($config->test)) {
|
||||
$config = $config->test;
|
||||
$this->__config = $config->test;
|
||||
} else {
|
||||
$config = $config->default;
|
||||
$this->__config = $config->default;
|
||||
}
|
||||
$this->debug = Configure::read('debug');
|
||||
Configure::write('debug', 1);
|
||||
$this->db =& new DboTest($config);
|
||||
$this->db =& new DboTest($this->__config);
|
||||
$this->Model = new TestModel();
|
||||
$db =& ConnectionManager::getDataSource($this->Model->useDbConfig);
|
||||
}
|
||||
|
@ -631,7 +631,8 @@ class DboSourceTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
function testFieldDoubleEscaping() {
|
||||
$test =& ConnectionManager::create('quoteTest', array('driver' => 'test'));
|
||||
$config = array_merge($this->__config, array('driver' => 'test'));
|
||||
$test =& ConnectionManager::create('quoteTest', $config);
|
||||
|
||||
$this->Model = new Article2(array('name' => 'Article', 'ds' => 'quoteTest'));
|
||||
$this->Model->setDataSource('quoteTest');
|
||||
|
@ -748,7 +749,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
|
||||
function testGenerateInnerJoinAssociationQuery() {
|
||||
$this->Model =& new TestModel9();
|
||||
$test =& ConnectionManager::create('test2', array('driver' => 'test'));
|
||||
$test =& ConnectionManager::create('test2', $this->__config);
|
||||
$this->Model->setDataSource('test2');
|
||||
$this->Model->TestModel8 =& new TestModel8();
|
||||
$this->Model->TestModel8->setDataSource('test2');
|
||||
|
@ -761,7 +762,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
$this->db->read($this->Model, array('recursive' => 1));
|
||||
$result = $this->db->getLastQuery();
|
||||
$this->assertPattern('/`TestModel9` INNER JOIN `test_model8`/', $result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding() {
|
||||
|
@ -2160,6 +2161,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
$result = $this->db->calculate($this->Model, 'max', array('`Model`.`id`', 'id'));
|
||||
$this->assertEqual($result, 'MAX(`Model`.`id`) AS `id`');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Reference in a new issue