You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace jrosset\CliProgram;
|
|
|
|
use Symfony\Component\Console\Application;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
/**
|
|
* Helper methods
|
|
*/
|
|
abstract class CliHelper {
|
|
/**
|
|
* Get the “error” output if exists, else the output itself
|
|
*
|
|
* @param OutputInterface $output The output
|
|
*
|
|
* @return OutputInterface The “error” output if exists, else the output itself
|
|
*/
|
|
public static final function getErrorOutput (OutputInterface $output): OutputInterface {
|
|
return $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
|
|
}
|
|
|
|
/**
|
|
* Get the name of a command class
|
|
*
|
|
* @param Application $application The application
|
|
* @param class-string<Command> $commandClass The command class
|
|
*
|
|
* @return string|null The command name ; Null if not found
|
|
*/
|
|
public static final function getCommandNameFromClass (Application $application, string $commandClass): ?string {
|
|
foreach ($application->all() as $possibleCommand) {
|
|
if (get_class($possibleCommand) == $commandClass) {
|
|
return $possibleCommand->getName();
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
} |