Skip to content

Commit

Permalink
Don't use App::objects() in command shell tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 16, 2014
1 parent 3f10889 commit 65cacbc
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/Console/Command/Task/CommandTask.php
Expand Up @@ -19,6 +19,7 @@
use Cake\Core\App;
use Cake\Core\Plugin;
use Cake\Utility\Inflector;
use Cake\Utility\Folder;
use \ReflectionClass;
use \ReflectionMethod;

Expand All @@ -41,16 +42,18 @@ public function getShellList() {
$shellList = array_fill_keys($plugins, null) + ['CORE' => null, 'app' => null];

$corePath = App::core('Console/Command');
$shells = App::objects('file', $corePath[0]);
$shells = $this->_scanDir($corePath[0]);
$shells = array_diff($shells, $skipFiles, $hiddenCommands);
$this->_appendShells('CORE', $shells, $shellList);

$appShells = App::objects('Console/Command', null, false);
$appPath = App::path('Console/Command');
$appShells = $this->_scanDir($appPath[0]);
$appShells = array_diff($appShells, $shells, $skipFiles);
$this->_appendShells('app', $appShells, $shellList);

foreach ($plugins as $plugin) {
$pluginShells = App::objects($plugin . '.Console/Command');
$pluginPath = Plugin::classPath($plugin) . 'Console' . DS . 'Command';
$pluginShells = $this->_scanDir($pluginPath);
$this->_appendShells($plugin, $pluginShells, $shellList);
}

Expand All @@ -71,6 +74,29 @@ protected function _appendShells($type, $shells, &$shellList) {
}
}

/**
* Scan a directory for .php files and return the class names that
* should be within them.
*
* @param string $dir The directory to read.
* @return array The list of shell classnames based on conventions.
*/
protected function _scanDir($dir) {
$dir = new Folder($dir);
$contents = $dir->read(true, true);
if (empty($contents[1])) {
return [];
}
$shells = [];
foreach ($contents[1] as $file) {
if (substr($file, -4) !== '.php') {
continue;
}
$shells[] = substr($file, 0, -4);
}
return $shells;
}

/**
* Return a list of all commands
*
Expand Down

0 comments on commit 65cacbc

Please sign in to comment.