mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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
This commit is contained in:
parent
4a7bd031e5
commit
9ff922cbc7
2 changed files with 22 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue