mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Simplifying datasources loading, it now requires datasources to be configured with the 'datasource' array key, which is a relative path from Model/Datasource/
This commit is contained in:
parent
be1263d476
commit
7dc8d5e746
2 changed files with 19 additions and 34 deletions
|
@ -161,15 +161,20 @@ class ConnectionManager {
|
||||||
$conn = $_this->_connectionsEnum[$connName];
|
$conn = $_this->_connectionsEnum[$connName];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (class_exists($conn['classname'])) {
|
if (class_exists($conn['classname'], false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn = array_merge(array('plugin' => null, 'classname' => null, 'parent' => null), $conn);
|
$plugin = $package = null;
|
||||||
$class = trim("{$conn['plugin']}.{$conn['classname']}", '.');
|
if (!empty($conn['plugin'])) {
|
||||||
|
$plugin .= '.';
|
||||||
|
}
|
||||||
|
if (!empty($conn['package'])) {
|
||||||
|
$package = '/' . $conn['package'];
|
||||||
|
}
|
||||||
|
|
||||||
App::uses($class, 'Model/Datasource');
|
App::uses($conn['classname'], $plugin . 'Model/Datasource' . $package);
|
||||||
if (class_exists($class)) {
|
if (!class_exists($conn['classname'])) {
|
||||||
trigger_error(sprintf(__('ConnectionManager::loadDataSource - Unable to import DataSource class %s'), $class), E_USER_ERROR);
|
trigger_error(sprintf(__('ConnectionManager::loadDataSource - Unable to import DataSource class %s'), $class), E_USER_ERROR);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -230,36 +235,14 @@ class ConnectionManager {
|
||||||
* @return array An indexed array with: filename, classname, plugin and parent
|
* @return array An indexed array with: filename, classname, plugin and parent
|
||||||
*/
|
*/
|
||||||
private function __connectionData($config) {
|
private function __connectionData($config) {
|
||||||
if (!isset($config['datasource'])) {
|
$package = $classname = $plugin = null;
|
||||||
$config['datasource'] = 'dbo';
|
|
||||||
}
|
|
||||||
$filename = $classname = $parent = $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']);
|
list($plugin, $classname) = pluginSplit($config['datasource']);
|
||||||
if ($plugin) {
|
if (strpos($classname, '/') !== false) {
|
||||||
$filename = Inflector::underscore($classname);
|
$package = dirname($classname);
|
||||||
} else {
|
$classname = basename($classname);
|
||||||
$filename = Inflector::underscore($config['datasource']);
|
|
||||||
}
|
}
|
||||||
if (substr($filename, -7) != '_source') {
|
return compact('package', 'classname', 'plugin');
|
||||||
$filename .= '_source';
|
|
||||||
}
|
|
||||||
$classname = Inflector::camelize(strtolower($filename));
|
|
||||||
}
|
|
||||||
return compact('filename', 'classname', 'parent', 'plugin');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
App::uses('DboSource', 'Model/Datasource');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MySQL DBO driver object
|
* MySQL DBO driver object
|
||||||
*
|
*
|
||||||
|
@ -26,7 +28,7 @@
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.datasources.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
*/
|
*/
|
||||||
class DboMysql extends DboSource {
|
class Mysql extends DboSource {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Datasource description
|
* Datasource description
|
||||||
|
|
Loading…
Reference in a new issue