From a6fbe05964dab12d7fea50c12b9a8bf4b606ef0e Mon Sep 17 00:00:00 2001 From: phpnut Date: Sun, 16 Mar 2008 05:44:20 +0000 Subject: [PATCH] "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 --- cake/libs/configure.php | 7 ++++++- cake/libs/model/behavior.php | 18 +++++++++--------- cake/libs/model/model.php | 2 +- cake/tests/cases/libs/class_registry.test.php | 2 +- .../libs/model/datasources/dbo_source.test.php | 14 ++++++++------ 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/cake/libs/configure.php b/cake/libs/configure.php index ce622d572..0a9ee2993 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -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])) { diff --git a/cake/libs/model/behavior.php b/cake/libs/model/behavior.php index 112c8843f..24e64fbb1 100644 --- a/cake/libs/model/behavior.php +++ b/cake/libs/model/behavior.php @@ -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) { diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index b67a05494..aa43bb843 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -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 for DB models, diff --git a/cake/tests/cases/libs/class_registry.test.php b/cake/tests/cases/libs/class_registry.test.php index 48c512cc8..b1c21dd22 100644 --- a/cake/tests/cases/libs/class_registry.test.php +++ b/cake/tests/cases/libs/class_registry.test.php @@ -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; } diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index f88984057..d32e4b4d6 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -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`'); } + } ?> \ No newline at end of file