Skip to content

Commit fcd23b0

Browse files
committed
Starting to change the class loading for app classes
1 parent 0249518 commit fcd23b0

File tree

7 files changed

+51
-42
lines changed

7 files changed

+51
-42
lines changed

lib/Cake/Controller/PagesController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
2121
*/
2222

23+
App::uses('AppController', 'Controller');
24+
2325
/**
2426
* Static content controller
2527
*

lib/Cake/Core/App.php

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ class App {
207207
*/
208208
private static $__classMap = array();
209209

210+
/**
211+
* Holds the possible paths for each package name
212+
*
213+
*/
214+
private static $__packages = array();
215+
210216
/**
211217
* Used to read information stored path
212218
*
@@ -218,10 +224,10 @@ class App {
218224
* @return string array
219225
*/
220226
public static function path($type) {
221-
if (!isset(self::${$type})) {
227+
if (!isset(self::$__packages[$type])) {
222228
return array();
223229
}
224-
return self::${$type};
230+
return self::$__packages[$type];
225231
}
226232

227233
/**
@@ -234,14 +240,14 @@ public static function path($type) {
234240
*/
235241
public static function build($paths = array(), $reset = false) {
236242
$defaults = array(
237-
'models' => array(MODELS),
238-
'behaviors' => array(BEHAVIORS),
239-
'datasources' => array(MODELS . 'datasources'),
240-
'controllers' => array(CONTROLLERS),
241-
'components' => array(COMPONENTS),
243+
'Model' => array(MODELS),
244+
'Model/Behavior' => array(BEHAVIORS),
245+
'Datasource' => array(MODELS . 'datasources'),
246+
'Controller' => array(CONTROLLERS),
247+
'Controller/Component' => array(COMPONENTS),
242248
'libs' => array(APPLIBS),
243-
'views' => array(VIEWS),
244-
'helpers' => array(HELPERS),
249+
'View' => array(VIEWS),
250+
'View/Helper' => array(HELPERS),
245251
'locales' => array(APP . 'locale' . DS),
246252
'shells' => array(
247253
APP . 'console' . DS . 'shells' . DS,
@@ -254,7 +260,7 @@ public static function build($paths = array(), $reset = false) {
254260

255261
if ($reset == true) {
256262
foreach ($paths as $type => $new) {
257-
self::${$type} = (array)$new;
263+
self::$__packages[$type] = (array)$new;
258264
}
259265
return $paths;
260266
}
@@ -263,27 +269,19 @@ public static function build($paths = array(), $reset = false) {
263269
$app = array('models' => true, 'controllers' => true, 'helpers' => true);
264270

265271
foreach ($defaults as $type => $default) {
266-
$merge = array();
267272

268-
if (isset($app[$type])) {
269-
$merge = array(APP);
270-
}
271-
if (isset($core[$type])) {
272-
$merge = array_merge($merge, (array)$core[$type]);
273-
}
274-
275-
if (empty(self::${$type}) || empty($paths)) {
276-
self::${$type} = $default;
273+
if (empty(self::$__packages[$type]) || empty($paths)) {
274+
self::$__packages[$type] = $default;
277275
}
278276

279277
if (!empty($paths[$type])) {
280278
$path = array_flip(array_flip(array_merge(
281-
(array)$paths[$type], self::${$type}, $merge
279+
(array)$paths[$type], self::$__packages[$type], $merge
282280
)));
283-
self::${$type} = array_values($path);
281+
self::$__packages[$type] = array_values($path);
284282
} else {
285-
$path = array_flip(array_flip(array_merge(self::${$type}, $merge)));
286-
self::${$type} = array_values($path);
283+
$path = array_flip(array_flip(self::$__packages[$type]));
284+
self::$__packages[$type] = array_values($path);
287285
}
288286
}
289287
}
@@ -442,9 +440,15 @@ public static function uses($className, $location) {
442440

443441
public static function load($className) {
444442
if (isset(self::$__classMap[$className])) {
445-
$file = LIBS . self::$__classMap[$className] . DS . $className . '.php';
446-
if (file_exists($file)) {
447-
return include $file;
443+
$package = self::$__classMap[$className];
444+
$paths = self::path($package);
445+
$paths[] = LIBS . self::$__classMap[$className] . DS;
446+
447+
foreach ($paths as $path) {
448+
$file = $path . $className . '.php';
449+
if (file_exists($file)) {
450+
return include $file;
451+
}
448452
}
449453
}
450454
return false;
@@ -900,6 +904,4 @@ public static function shutdown() {
900904
Cache::write('object_map', self::$__objects, '_cake_core_');
901905
}
902906
}
903-
}
904-
905-
spl_autoload_register(array('App', 'load'));
907+
}
File renamed without changes.

lib/Cake/Routing/Dispatcher.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,7 @@ protected function _getController($request) {
223223
if (!$ctrlClass) {
224224
return false;
225225
}
226-
$ctrlClass .= 'Controller';
227-
if (class_exists($ctrlClass)) {
228-
return new $ctrlClass($request);
229-
}
226+
return new $ctrlClass($request);
230227
}
231228

232229
/**
@@ -245,8 +242,11 @@ protected function _loadController($request) {
245242
$controller = Inflector::camelize($request->params['controller']);
246243
}
247244
if ($pluginPath . $controller) {
248-
if (App::import('Controller', $pluginPath . $controller)) {
249-
return $controller;
245+
$class = $controller . 'Controller';
246+
App::uses('AppController', 'Controller');
247+
App::uses($class, $pluginPath . 'Controller');
248+
if (class_exists($class)) {
249+
return $class;
250250
}
251251
}
252252
return false;

lib/Cake/Utility/ClassRegistry.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,17 @@ public static function &init($class, $type = null) {
134134
return $model;
135135
}
136136

137-
if (class_exists($class) || App::import($type, $pluginPath . $class)) {
137+
App::uses('Model', 'Model');
138+
App::uses('AppModel', 'Model');
139+
App::uses($class, $pluginPath . $type);
140+
if (class_exists($class)) {
138141
${$class} = new $class($settings);
139142
} elseif ($type === 'Model') {
140-
if ($plugin && class_exists($plugin . 'AppModel')) {
141-
$appModel = $plugin . 'AppModel';
142-
} else {
143+
//if ($plugin && class_exists($plugin . 'AppModel')) {
144+
// $appModel = $plugin . 'AppModel';
145+
//} else {
143146
$appModel = 'AppModel';
144-
}
147+
//}
145148
$settings['name'] = $class;
146149
${$class} = new $appModel($settings);
147150
}

lib/Cake/View/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ protected function _paths($plugin = null, $cached = true) {
799799
return $this->__paths;
800800
}
801801
$paths = array();
802-
$viewPaths = App::path('views');
802+
$viewPaths = App::path('View');
803803
$corePaths = array_flip(App::core('views'));
804804

805805
if (!empty($plugin)) {

lib/Cake/bootstrap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@
222222
require LIBS . 'Core' . DS .'App.php';
223223
require LIBS . 'Error' . DS . 'exceptions.php';
224224

225+
spl_autoload_register(array('App', 'load'));
226+
225227
App::uses('ErrorHandler', 'Error');
226228
App::uses('Configure', 'Core');
227229
App::uses('Cache', 'Cache');

0 commit comments

Comments
 (0)