/var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/Console/Command
Edit: /var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/Console/Command/HelpCommand.php (6817B)
commands = $commands;
}
/**
* Main function Prints out the list of commands.
*
* @param \Cake\Console\Arguments $args The command arguments.
* @param \Cake\Console\ConsoleIo $io The console io
* @return int
*/
public function execute(Arguments $args, ConsoleIo $io): ?int
{
$commands = $this->commands->getIterator();
if ($commands instanceof ArrayIterator) {
$commands->ksort();
}
if ($args->getOption('xml')) {
$this->asXml($io, $commands);
return static::CODE_SUCCESS;
}
$this->asText($io, $commands);
return static::CODE_SUCCESS;
}
/**
* Output text.
*
* @param \Cake\Console\ConsoleIo $io The console io
* @param iterable $commands The command collection to output.
* @return void
*/
protected function asText(ConsoleIo $io, iterable $commands): void
{
$invert = [];
foreach ($commands as $name => $class) {
if (is_object($class)) {
$class = get_class($class);
}
if (!isset($invert[$class])) {
$invert[$class] = [];
}
$invert[$class][] = $name;
}
$grouped = [];
$plugins = Plugin::loaded();
foreach ($invert as $class => $names) {
preg_match('/^(.+)\\\\(Command|Shell)\\\\/', $class, $matches);
// Probably not a useful class
if (empty($matches)) {
continue;
}
$namespace = str_replace('\\', '/', $matches[1]);
$prefix = 'App';
if ($namespace === 'Cake') {
$prefix = 'CakePHP';
} elseif (in_array($namespace, $plugins, true)) {
$prefix = $namespace;
}
$shortestName = $this->getShortestName($names);
if (strpos($shortestName, '.') !== false) {
[, $shortestName] = explode('.', $shortestName, 2);
}
$grouped[$prefix][] = $shortestName;
}
ksort($grouped);
$this->outputPaths($io);
$io->out('
Available Commands:', 2);
foreach ($grouped as $prefix => $names) {
$io->out("
{$prefix}:");
sort($names);
foreach ($names as $name) {
$io->out(' - ' . $name);
}
$io->out('');
}
$root = $this->getRootName();
$io->out("To run a command, type
`{$root} command_name [args|options]`");
$io->out("To get help on a specific command, type
`{$root} command_name --help`", 2);
}
/**
* Output relevant paths if defined
*
* @param \Cake\Console\ConsoleIo $io IO object.
* @return void
*/
protected function outputPaths(ConsoleIo $io): void
{
$paths = [];
if (Configure::check('App.dir')) {
$appPath = rtrim(Configure::read('App.dir'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
// Extra space is to align output
$paths['app'] = ' ' . $appPath;
}
if (defined('ROOT')) {
$paths['root'] = rtrim(ROOT, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}
if (defined('CORE_PATH')) {
$paths['core'] = rtrim(CORE_PATH, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}
if (!count($paths)) {
return;
}
$io->out('
Current Paths:', 2);
foreach ($paths as $key => $value) {
$io->out("* {$key}: {$value}");
}
$io->out('');
}
/**
* @param string[] $names Names
* @return string
*/
protected function getShortestName(array $names): string
{
if (count($names) <= 1) {
return array_shift($names);
}
usort($names, function ($a, $b) {
return strlen($a) - strlen($b);
});
return array_shift($names);
}
/**
* Output as XML
*
* @param \Cake\Console\ConsoleIo $io The console io
* @param iterable $commands The command collection to output
* @return void
*/
protected function asXml(ConsoleIo $io, iterable $commands): void
{
$shells = new SimpleXMLElement('
');
foreach ($commands as $name => $class) {
if (is_object($class)) {
$class = get_class($class);
}
$shell = $shells->addChild('shell');
$shell->addAttribute('name', $name);
$shell->addAttribute('call_as', $name);
$shell->addAttribute('provider', $class);
$shell->addAttribute('help', $name . ' -h');
}
$io->setOutputAs(ConsoleOutput::RAW);
$io->out($shells->saveXML());
}
/**
* Gets the option parser instance and configures it.
*
* @param \Cake\Console\ConsoleOptionParser $parser The parser to build
* @return \Cake\Console\ConsoleOptionParser
*/
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
$parser->setDescription(
'Get the list of available commands for this application.'
)->addOption('xml', [
'help' => 'Get the listing as XML.',
'boolean' => true,
]);
return $parser;
}
}