mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Implementing lazy loading of plugin models
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5207 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
97879bc516
commit
f916745c87
3 changed files with 67 additions and 5 deletions
|
@ -161,6 +161,27 @@
|
|||
|
||||
if(strpos($name, '.') !== false){
|
||||
list($plugin, $name) = explode('.', $name);
|
||||
|
||||
$pluginAppModel = Inflector::camelize($plugin . '_app_model');
|
||||
$pluginAppModelFile = APP . 'plugins' . DS . $plugin . DS . $plugin . '_app_model.php';
|
||||
if (!class_exists($pluginAppModel)) {
|
||||
if (file_exists($pluginAppModelFile)) {
|
||||
require($pluginAppModelFile);
|
||||
Overloadable::overload($pluginAppModel);
|
||||
}
|
||||
}
|
||||
if (!class_exists($name)) {
|
||||
$className = $name;
|
||||
$name = Inflector::underscore($name);
|
||||
$path = APP . 'plugins' . DS . $plugin . DS . 'models' . DS;
|
||||
if (file_exists($path . $name . '.php')) {
|
||||
require($path . $name . '.php');
|
||||
Overloadable::overload($className);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_null($name) && !class_exists($name)) {
|
||||
|
@ -279,8 +300,45 @@
|
|||
}
|
||||
if(strpos($name, '.') !== false){
|
||||
list($plugin, $name) = explode('.', $name);
|
||||
loadPluginController($plugin, $name);
|
||||
return;
|
||||
|
||||
$pluginAppController = Inflector::camelize($plugin . '_app_controller');
|
||||
$plugin = Inflector::underscore($plugin);
|
||||
$pluginAppControllerFile = APP . 'plugins' . DS . $plugin . DS . $plugin . '_app_controller.php';
|
||||
|
||||
if (!class_exists($pluginAppController)) {
|
||||
if (file_exists($pluginAppControllerFile)) {
|
||||
require($pluginAppControllerFile);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($name)) {
|
||||
if (!class_exists(Inflector::camelize($plugin . 'controller'))) {
|
||||
if (file_exists(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php')) {
|
||||
require(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists($name . 'Controller')) {
|
||||
$name = Inflector::underscore($name);
|
||||
$file = APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $name . '_controller.php';
|
||||
|
||||
if (file_exists($file)) {
|
||||
require($file);
|
||||
return true;
|
||||
} elseif (!class_exists(Inflector::camelize($plugin) . 'Controller')){
|
||||
if(file_exists(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php')) {
|
||||
require(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php');
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
$className = $name . 'Controller';
|
||||
|
|
|
@ -127,7 +127,6 @@ class Dispatcher extends Object {
|
|||
$oldAction = $params['action'];
|
||||
$params = $this->_restructureParams($params);
|
||||
$this->plugin = $plugin;
|
||||
loadPluginModels($plugin);
|
||||
$this->base = $this->base.'/'.Inflector::underscore($ctrlName);
|
||||
|
||||
if(empty($params['controller']) || !class_exists($pluginClass)) {
|
||||
|
|
|
@ -345,10 +345,15 @@ class Controller extends Object {
|
|||
}
|
||||
$cached = false;
|
||||
$object = null;
|
||||
$plugin = null;
|
||||
|
||||
if($this->plugin) {
|
||||
$plugin = $this->plugin . '.';
|
||||
}
|
||||
|
||||
if($this->uses === false) {
|
||||
if(!class_exists($this->modelClass)){
|
||||
loadModel($this->modelClass);
|
||||
loadModel($plugin . $this->modelClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,7 +393,7 @@ class Controller extends Object {
|
|||
$modelKey = Inflector::underscore($modelClass);
|
||||
|
||||
if(!class_exists($modelClass)){
|
||||
loadModel($modelClass);
|
||||
loadModel($plugin . $modelClass);
|
||||
}
|
||||
|
||||
if (class_exists($modelClass)) {
|
||||
|
|
Loading…
Reference in a new issue