From 7dc8d5e74678b56ce7958511897a8170857478ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Lorenzo=20Rodri=CC=81guez?= Date: Sat, 4 Dec 2010 12:24:15 -0430 Subject: [PATCH] Simplifying datasources loading, it now requires datasources to be configured with the 'datasource' array key, which is a relative path from Model/Datasource/ --- lib/Cake/Model/ConnectionManager.php | 49 +++++++------------- lib/Cake/Model/Datasource/Database/Mysql.php | 4 +- 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/lib/Cake/Model/ConnectionManager.php b/lib/Cake/Model/ConnectionManager.php index b6ff55252..4f67db5f5 100644 --- a/lib/Cake/Model/ConnectionManager.php +++ b/lib/Cake/Model/ConnectionManager.php @@ -161,15 +161,20 @@ class ConnectionManager { $conn = $_this->_connectionsEnum[$connName]; } - if (class_exists($conn['classname'])) { + if (class_exists($conn['classname'], false)) { return false; } - $conn = array_merge(array('plugin' => null, 'classname' => null, 'parent' => null), $conn); - $class = trim("{$conn['plugin']}.{$conn['classname']}", '.'); + $plugin = $package = null; + if (!empty($conn['plugin'])) { + $plugin .= '.'; + } + if (!empty($conn['package'])) { + $package = '/' . $conn['package']; + } - App::uses($class, 'Model/Datasource'); - if (class_exists($class)) { + App::uses($conn['classname'], $plugin . 'Model/Datasource' . $package); + if (!class_exists($conn['classname'])) { trigger_error(sprintf(__('ConnectionManager::loadDataSource - Unable to import DataSource class %s'), $class), E_USER_ERROR); return null; } @@ -230,36 +235,14 @@ class ConnectionManager { * @return array An indexed array with: filename, classname, plugin and parent */ private function __connectionData($config) { - if (!isset($config['datasource'])) { - $config['datasource'] = 'dbo'; - } - $filename = $classname = $parent = $plugin = null; + $package = $classname = $plugin = null; - if (!empty($config['driver'])) { - $parent = $this->__connectionData(array('datasource' => $config['datasource'])); - $parentSource = preg_replace('/_source$/', '', $parent['filename']); - - list($plugin, $classname) = pluginSplit($config['driver']); - if ($plugin) { - $source = Inflector::underscore($classname); - } else { - $source = $parentSource . '_' . $config['driver']; - $classname = Inflector::camelize(strtolower($source)); - } - $filename = $parentSource . DS . $source; - } else { - list($plugin, $classname) = pluginSplit($config['datasource']); - if ($plugin) { - $filename = Inflector::underscore($classname); - } else { - $filename = Inflector::underscore($config['datasource']); - } - if (substr($filename, -7) != '_source') { - $filename .= '_source'; - } - $classname = Inflector::camelize(strtolower($filename)); + list($plugin, $classname) = pluginSplit($config['datasource']); + if (strpos($classname, '/') !== false) { + $package = dirname($classname); + $classname = basename($classname); } - return compact('filename', 'classname', 'parent', 'plugin'); + return compact('package', 'classname', 'plugin'); } /** diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 069cf089a..882aa61e0 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -18,6 +18,8 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::uses('DboSource', 'Model/Datasource'); + /** * MySQL DBO driver object * @@ -26,7 +28,7 @@ * @package cake * @subpackage cake.cake.libs.model.datasources.dbo */ -class DboMysql extends DboSource { +class Mysql extends DboSource { /** * Datasource description