From 9ff922cbc7274cf5d4dddf73dbccb8e954cc31f9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 28 Aug 2011 15:36:19 -0400 Subject: [PATCH] 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 --- lib/Cake/Core/App.php | 10 +++++++--- lib/Cake/Test/Case/Core/AppTest.php | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 1e92aa76c..d36ff7966 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -427,6 +427,9 @@ class App { * * `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 @@ class App { 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); } } } diff --git a/lib/Cake/Test/Case/Core/AppTest.php b/lib/Cake/Test/Case/Core/AppTest.php index 9f51fd1a1..945a76062 100644 --- a/lib/Cake/Test/Case/Core/AppTest.php +++ b/lib/Cake/Test/Case/Core/AppTest.php @@ -305,6 +305,21 @@ class AppTest extends CakeTestCase { App::build(); } +/** + * 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 *