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:
phpnut 2007-05-27 02:32:27 +00:00
parent 97879bc516
commit f916745c87
3 changed files with 67 additions and 5 deletions

View file

@ -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';

View file

@ -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)) {

View file

@ -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)) {