If a Command is not enabled it will not be added.
public addCommands ( array $commands ) | ||
$commands | array | An array of commands |
use Symfony\Component\Console\Application; use App\Console\Commands\HelloCommand; use App\Console\Commands\GoodbyeCommand; $application = new Application('My Console App', '1.0.0'); $application->addCommands([ new HelloCommand(), new GoodbyeCommand(), ]); $application->run();
use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; $application = new Application('My Console App', '1.0.0'); $commandsList = ['command1', 'command2', 'command3']; foreach ($commandsList as $command) { /** @var Command $instance */ $instance = new $command; $application->add($instance); } $application->run();In this alternative example, we register a list of command class names using `foreach` loop and create instance of each class by calling the constructor of the class. At each iteration, it will be dynamically added to the console application using the `$application->add` method. Both examples demonstrate how `addCommands` can be used to easily include custom commands in your Symfony Console application. The package library used in this case is the Symfony Console components.
public addCommands ( array $commands ) | ||
$commands | array | An array of commands |