mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Adding changes to other load*() functions in basics.php to create cached paths for loaded classes
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4288 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
de4bd50931
commit
7ad952d5eb
1 changed files with 112 additions and 25 deletions
135
cake/basics.php
135
cake/basics.php
|
@ -157,7 +157,11 @@
|
||||||
$models = Configure::read('Models');
|
$models = Configure::read('Models');
|
||||||
if(is_array($models)) {
|
if(is_array($models)) {
|
||||||
if(array_key_exists($className, $models)) {
|
if(array_key_exists($className, $models)) {
|
||||||
require($models[$className]['path'] . $name . '.php');
|
require($models[$className]['path']);
|
||||||
|
Overloadable::overload($className);
|
||||||
|
return true;
|
||||||
|
} elseif(array_key_exists($className, $models['Core'])) {
|
||||||
|
require($models['Core'][$className]['path']);
|
||||||
Overloadable::overload($className);
|
Overloadable::overload($className);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -166,7 +170,7 @@
|
||||||
$paths = Configure::getInstance();
|
$paths = Configure::getInstance();
|
||||||
foreach($paths->modelPaths as $path) {
|
foreach($paths->modelPaths as $path) {
|
||||||
if (file_exists($path . $name . '.php')) {
|
if (file_exists($path . $name . '.php')) {
|
||||||
Configure::store('Models', 'class.paths', array($className => array('path' => $path)));
|
Configure::store('Models', 'class.paths', array($className => array('path' => $path . $name . '.php')));
|
||||||
require($path . $name . '.php');
|
require($path . $name . '.php');
|
||||||
Overloadable::overload($className);
|
Overloadable::overload($className);
|
||||||
return true;
|
return true;
|
||||||
|
@ -177,6 +181,49 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function paths(){
|
||||||
|
$directories = Configure::getInstance();
|
||||||
|
$paths = array();
|
||||||
|
|
||||||
|
foreach($directories->modelPaths as $path) {
|
||||||
|
$paths['Models'][] = $path;
|
||||||
|
}
|
||||||
|
foreach($directories->behaviorPaths as $path) {
|
||||||
|
$paths['Behaviors'][] = $path;
|
||||||
|
}
|
||||||
|
foreach($directories->controllerPaths as $path) {
|
||||||
|
$paths['Controllers'][] = $path;
|
||||||
|
}
|
||||||
|
foreach($directories->componentPaths as $path) {
|
||||||
|
$paths['Components'][] = $path;
|
||||||
|
}
|
||||||
|
foreach($directories->helperPaths as $path) {
|
||||||
|
$paths['Helpers'][] = $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!class_exists('Folder')){
|
||||||
|
uses('Folder');
|
||||||
|
}
|
||||||
|
|
||||||
|
$folder =& new Folder(APP.'plugins'.DS);
|
||||||
|
$plugins = $folder->ls();
|
||||||
|
$classPaths = array('models', 'models'.DS.'behaviors', 'controllers', 'controllers'.DS.'components', 'views'.DS.'helpers');
|
||||||
|
|
||||||
|
foreach($plugins[0] as $plugin){
|
||||||
|
foreach($classPaths as $path){
|
||||||
|
if(strpos($path, DS) !== false){
|
||||||
|
$key = explode(DS, $path);
|
||||||
|
$key = $key[1];
|
||||||
|
} else {
|
||||||
|
$key = $path;
|
||||||
|
}
|
||||||
|
$folder->path = APP.'plugins'.DS.$plugin.DS.$path;
|
||||||
|
$paths[Inflector::camelize($plugin)][Inflector::camelize($key)][] = $folder->path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $paths;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Loads all controllers.
|
* Loads all controllers.
|
||||||
*/
|
*/
|
||||||
|
@ -209,7 +256,6 @@
|
||||||
* @return boolean Success
|
* @return boolean Success
|
||||||
*/
|
*/
|
||||||
function loadController($name) {
|
function loadController($name) {
|
||||||
$paths = Configure::getInstance();
|
|
||||||
if (!class_exists('AppController')) {
|
if (!class_exists('AppController')) {
|
||||||
if (file_exists(APP . 'app_controller.php')) {
|
if (file_exists(APP . 'app_controller.php')) {
|
||||||
require(APP . 'app_controller.php');
|
require(APP . 'app_controller.php');
|
||||||
|
@ -217,24 +263,37 @@
|
||||||
require(CAKE . 'app_controller.php');
|
require(CAKE . 'app_controller.php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($name === null) {
|
if ($name === null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!class_exists($name . 'Controller')) {
|
$className = $name . 'Controller';
|
||||||
$name = Inflector::underscore($name);
|
if (!class_exists($className)) {
|
||||||
|
$name = Inflector::underscore($className);
|
||||||
foreach($paths->controllerPaths as $path) {
|
$controllers = Configure::read('Controllers');
|
||||||
if (file_exists($path . $name . '_controller.php')) {
|
if(is_array($controllers)) {
|
||||||
require($path . $name . '_controller.php');
|
if(array_key_exists($className, $controllers)) {
|
||||||
|
require($controllers[$className]['path']);
|
||||||
|
return true;
|
||||||
|
} elseif(array_key_exists($className, $controllers['Core'])) {
|
||||||
|
require($controllers['Core'][$className]['path']);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($controller_fn = fileExistsInPath(LIBS . 'controller' . DS . $name . '_controller.php')) {
|
$paths = Configure::getInstance();
|
||||||
if (file_exists($controller_fn)) {
|
foreach($paths->controllerPaths as $path) {
|
||||||
require($controller_fn);
|
if (file_exists($path . $name . '.php')) {
|
||||||
|
Configure::store('Controllers', 'class.paths', array($className => array('path' => $path . $name . '.php')));
|
||||||
|
require($path . $name . '.php');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($controllerFilename = fileExistsInPath(LIBS . 'controller' . DS . $name . '.php')) {
|
||||||
|
if (file_exists($controllerFilename)) {
|
||||||
|
Configure::store('Controllers\'][\'Core', 'class.paths', array($className => array('path' => $controllerFilename)));
|
||||||
|
require($controllerFilename);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -295,7 +354,6 @@
|
||||||
* @return boolean Success
|
* @return boolean Success
|
||||||
*/
|
*/
|
||||||
function loadHelper($name) {
|
function loadHelper($name) {
|
||||||
$paths = Configure::getInstance();
|
|
||||||
if (!class_exists('AppHelper')) {
|
if (!class_exists('AppHelper')) {
|
||||||
if (file_exists(APP . 'app_helper.php')) {
|
if (file_exists(APP . 'app_helper.php')) {
|
||||||
require(APP . 'app_helper.php');
|
require(APP . 'app_helper.php');
|
||||||
|
@ -309,19 +367,34 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!class_exists($name . 'Helper')) {
|
$className = $name . 'Helper';
|
||||||
|
if (!class_exists($className)) {
|
||||||
$name = Inflector::underscore($name);
|
$name = Inflector::underscore($name);
|
||||||
|
$helpers = Configure::read('Helpers');
|
||||||
|
|
||||||
|
if(is_array($helpers)) {
|
||||||
|
if(array_key_exists($className, $helpers)) {
|
||||||
|
require($helpers[$className]['path']);
|
||||||
|
return true;
|
||||||
|
} elseif(array_key_exists($className, $helpers['Core'])) {
|
||||||
|
require($helpers['Core'][$className]['path']);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$paths = Configure::getInstance();
|
||||||
foreach($paths->helperPaths as $path) {
|
foreach($paths->helperPaths as $path) {
|
||||||
if (file_exists($path . $name . '.php')) {
|
if (file_exists($path . $name . '.php')) {
|
||||||
|
Configure::store('Helpers', 'class.paths', array($className => array('path' => $path . $name . '.php')));
|
||||||
require($path . $name . '.php');
|
require($path . $name . '.php');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($helper_fn = fileExistsInPath(LIBS . 'view' . DS . 'helpers' . DS . $name . '.php')) {
|
if ($helperFilename = fileExistsInPath(LIBS . 'view' . DS . 'helpers' . DS . $name . '.php')) {
|
||||||
if (file_exists($helper_fn)) {
|
if (file_exists($helperFilename)) {
|
||||||
require($helper_fn);
|
Configure::store('Helpers\'][\'Core', 'class.paths', array($className => array('path' => $helperFilename)));
|
||||||
|
require($helperFilename);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -359,25 +432,39 @@
|
||||||
* @return boolean Success
|
* @return boolean Success
|
||||||
*/
|
*/
|
||||||
function loadComponent($name) {
|
function loadComponent($name) {
|
||||||
$paths = Configure::getInstance();
|
|
||||||
|
|
||||||
if ($name === null) {
|
if ($name === null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!class_exists($name . 'Component')) {
|
$className = $name . 'Component';
|
||||||
$name=Inflector::underscore($name);
|
if (!class_exists($className)) {
|
||||||
|
$name = Inflector::underscore($name);
|
||||||
|
$components = Configure::read('Components');
|
||||||
|
|
||||||
|
if(is_array($components)) {
|
||||||
|
if(array_key_exists($className, $components)) {
|
||||||
|
require($components[$className]['path']);
|
||||||
|
return true;
|
||||||
|
} elseif(array_key_exists($className, $components['Core'])) {
|
||||||
|
require($components['Core'][$className]['path']);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$paths = Configure::getInstance();
|
||||||
foreach($paths->componentPaths as $path) {
|
foreach($paths->componentPaths as $path) {
|
||||||
if (file_exists($path . $name . '.php')) {
|
if (file_exists($path . $name . '.php')) {
|
||||||
|
Configure::store('Components', 'class.paths', array($className => array('path' => $path . $name . '.php')));
|
||||||
require($path . $name . '.php');
|
require($path . $name . '.php');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($component_fn = fileExistsInPath(LIBS . 'controller' . DS . 'components' . DS . $name . '.php')) {
|
if ($componentFilename = fileExistsInPath(LIBS . 'controller' . DS . 'components' . DS . $name . '.php')) {
|
||||||
if (file_exists($component_fn)) {
|
if (file_exists($componentFilename)) {
|
||||||
require($component_fn);
|
Configure::store('Components\'][\'Core', 'class.paths', array($className => array('path' => $componentFilename)));
|
||||||
|
require($componentFilename);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue