From f916745c87cc0eb8457578ce239a5d5596f95091 Mon Sep 17 00:00:00 2001 From: phpnut Date: Sun, 27 May 2007 02:32:27 +0000 Subject: [PATCH] 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 --- cake/basics.php | 62 ++++++++++++++++++++++++++++- cake/dispatcher.php | 1 - cake/libs/controller/controller.php | 9 ++++- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index d0b3d6ced..02e9dd5b1 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -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'; diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 259890d72..9426d3c06 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -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)) { diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 8ef6fdcc1..fcf9fe814 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -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)) {