Permalink
Browse files

App::objects() should skip directories and files starting with

`.`.  These generally contain version control or OS metadata, and
not code CakePHP can use.
Fixes #1933
  • Loading branch information...
1 parent 4a7bd03 commit 9ff922cbc7274cf5d4dddf73dbccb8e954cc31f9 @markstory markstory committed Aug 28, 2011
Showing with 22 additions and 3 deletions.
  1. +7 −3 lib/Cake/Core/App.php
  2. +15 −0 lib/Cake/Test/Case/Core/AppTest.php
View
@@ -427,6 +427,9 @@ public static function core($type) {
*
* `App::objects('MyPlugin.Model');` returns `array('MyPluginPost', 'MyPluginComment');`
*
+ * When scanning directories, files and directories beginning with `.` will be excluded as these
+ * are commonly used by version control systems.
+ *
* @param string $type Type of object, i.e. 'Model', 'Controller', 'View/Helper', 'file', 'class' or 'plugin'
* @param mixed $path Optional Scan only the path given. If null, paths for the chosen type will be used.
* @param boolean $cache Set to false to rescan objects of the chosen type. Defaults to true.
@@ -476,12 +479,13 @@ 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()) {
+ $fileName = basename($file);
+ if (!$file->isDot() && $fileName[0] !== '.') {
$isDir = $file->isDir() ;
if ($isDir && $includeDirectories) {
- $objects[] = basename($file);
+ $objects[] = $fileName;
} elseif (!$includeDirectories && !$isDir) {
- $objects[] = substr(basename($file), 0, -4);
+ $objects[] = substr($fileName, 0, -4);
}
}
}
@@ -306,6 +306,21 @@ public function testListObjects() {
}
/**
+ * Make sure that .svn and friends are excluded from App::objects('plugin')
+ */
+ public function testListObjectsIgnoreDotDirectories() {
+ $path = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
+ App::build(array(
+ 'plugins' => array($path)
+ ), true);
+ mkdir($path . '.svn');
+ $result = App::objects('plugin', null, false);
+ rmdir($path . '.svn');
+
+ $this->assertNotContains('.svn', $result);
+ }
+
+/**
* Tests listing objects within a plugin
*
* @return void

0 comments on commit 9ff922c

Please sign in to comment.