Skip to content

Commit

Permalink
Fixing App::objects() and App::setObjects() so all dispatcher tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Feb 22, 2011
1 parent 688e914 commit deae385
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
26 changes: 16 additions & 10 deletions lib/Cake/Core/App.php
Expand Up @@ -19,7 +19,7 @@
/**
* App is responsible for path managment, class location and class loading.
*
* ### Adding paths
* ### Adding paths
*
* You can add paths to the search indexes App uses to find classes using `App::build()`. Adding
* additional controller paths for example would alter where CakePHP looks for controllers.
Expand All @@ -33,7 +33,7 @@
* ### Locating plugins and themes
*
* Plugins and Themes can be located with App as well. Using App::pluginPath('DebugKit') for example, will
* give you the full path to the DebugKit plugin. App::themePath('purple'), would give the full path to the
* give you the full path to the DebugKit plugin. App::themePath('purple'), would give the full path to the
* `purple` theme.
*
* ### Inspecting known objects
Expand Down Expand Up @@ -212,7 +212,7 @@ class App {
private static $__packages = array();

/**
*
*
*
*/
private static $__packageFormat = array();
Expand Down Expand Up @@ -299,7 +299,7 @@ public static function build($paths = array(), $reset = false) {
'View/Helper' => array('%s' . 'views' . DS . 'helpers' . DS),
'Console' => array(
'%s' . 'console' . DS . 'shells' . DS,
'%s' . 'vendors' . DS . 'shells' . DS,
'%s' . 'vendors' . DS . 'shells' . DS,
VENDORS . 'shells' . DS
),
'libs' => array('%s' . 'libs' . DS),
Expand Down Expand Up @@ -413,7 +413,7 @@ public static function core($type = null) {
*
* You can also search only within a plugin's objects by using the plugin dot
* syntax.
*
*
* `App::objects('MyPlugin.model');` returns `array('Post', 'Comment');`
*
* @param string $type Type of object, i.e. 'model', 'controller', 'helper', or 'plugin'
Expand Down Expand Up @@ -468,8 +468,12 @@ public static function objects($type, $path = null, $cache = true) {
if ($dir != APP && is_dir($dir)) {
$files = new RegexIterator(new DirectoryIterator($dir), $extension);
foreach ($files as $file) {
if (!$file->isDot() && (!$file->isDir() || $includeDirectories)) {
$objects[] = substr(basename($file), 0, -4);
if (!$file->isDot()) {
if ($file->isDir() && $includeDirectories) {
$objects[] = basename($file);
} elseif (!$includeDirectories) {
$objects[] = substr(basename($file), 0, -4);
}
}
}
}
Expand All @@ -496,14 +500,16 @@ public static function objects($type, $path = null, $cache = true) {

/**
* Allows you to modify the object listings that App maintains inside of it
* Useful for testing
* Useful for testing
*
* @param string $type Type of object listing you are changing
* @param array $values The values $type should be set to.
* @return void
*/
public static function setObjects($type, $values) {
self::$__objects[$type] = $values;
list($plugin, $type) = pluginSplit($type);
$cacheLocation = empty($plugin) ? 'app' : $plugin;
self::$__objects[$cacheLocation][$type] = $values;
}

public static function uses($className, $location) {
Expand All @@ -523,7 +529,7 @@ public static function load($className) {
if (empty($plugin)) {
$appLibs = empty(self::$__packages['libs']) ? APPLIBS : current(self::$__packages['libs']);
$paths[] = $appLibs . self::$__classMap[$className] . DS;
$paths[] = LIBS . self::$__classMap[$className] . DS;
$paths[] = LIBS . self::$__classMap[$className] . DS;
}

foreach ($paths as $path) {
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Routing/Dispatcher.php
Expand Up @@ -243,6 +243,7 @@ protected function _loadController($request) {
if ($pluginPath . $controller) {
$class = $controller . 'Controller';
App::uses('AppController', 'Controller');
App::uses($pluginName . 'AppController', $pluginPath . 'Controller');
App::uses($class, $pluginPath . 'Controller');
if (class_exists($class)) {
return $class;
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/tests/cases/libs/dispatcher.test.php
Expand Up @@ -1216,7 +1216,7 @@ public function testAssets() {
App::build(array(
'plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
'vendors' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'vendors'. DS),
'views' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'views'. DS)
'View' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));

$Dispatcher = new TestDispatcher();
Expand Down

0 comments on commit deae385

Please sign in to comment.