mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Beging of an experiment: a class utoloader for cakephp through emulating the keyword "use" of php 5.3
This commit is contained in:
parent
aa0bad9247
commit
da7c53b374
2 changed files with 25 additions and 7 deletions
|
@ -201,6 +201,12 @@ class App {
|
||||||
*/
|
*/
|
||||||
private static $__objects = array();
|
private static $__objects = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds the location of each class
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static $__classMap = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to read information stored path
|
* Used to read information stored path
|
||||||
*
|
*
|
||||||
|
@ -430,6 +436,17 @@ class App {
|
||||||
self::$__objects[$type] = $values;
|
self::$__objects[$type] = $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function uses($className, $location) {
|
||||||
|
self::$__classMap[$className] = $location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function load($className) {
|
||||||
|
if (isset(self::$__classMap[$className])) {
|
||||||
|
return App::import(self::$__classMap[$className], $className, false);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds classes based on $name or specific file(s) to search. Calling App::import() will
|
* Finds classes based on $name or specific file(s) to search. Calling App::import() will
|
||||||
* not construct any classes contained in the files. It will only find and require() the file.
|
* not construct any classes contained in the files. It will only find and require() the file.
|
||||||
|
@ -887,3 +904,5 @@ class App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spl_autoload_register(array('App', 'load'));
|
|
@ -24,10 +24,12 @@
|
||||||
/**
|
/**
|
||||||
* List of helpers to include
|
* List of helpers to include
|
||||||
*/
|
*/
|
||||||
App::import('Core', 'Router', false);
|
App::uses('Router', 'Core');
|
||||||
App::import('Core', 'CakeRequest', false);
|
App::uses('CakeRequest', 'Core');
|
||||||
App::import('Core', 'CakeResponse', false);
|
App::uses('CakeResponse', 'Core');
|
||||||
App::import('Controller', 'Controller', false);
|
App::uses('Controller', 'Controller');
|
||||||
|
App::uses('View', 'View');
|
||||||
|
App::uses('Debugger', 'Core');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatcher converts Requests into controller actions. It uses the dispatched Request
|
* Dispatcher converts Requests into controller actions. It uses the dispatched Request
|
||||||
|
@ -270,9 +272,6 @@ class Dispatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists($filename)) {
|
if (file_exists($filename)) {
|
||||||
if (!class_exists('View')) {
|
|
||||||
App::import('View', 'View', false);
|
|
||||||
}
|
|
||||||
$controller = null;
|
$controller = null;
|
||||||
$view = new View($controller);
|
$view = new View($controller);
|
||||||
return $view->renderCache($filename, microtime(true));
|
return $view->renderCache($filename, microtime(true));
|
||||||
|
|
Loading…
Add table
Reference in a new issue