Console
The Asgard Console package is an simple extension to the Symfony Console component., (*1)
, (*2)
Installation
If you are working on an Asgard project you don't need to install this library as it is already part of the standard libraries., (*3)
composer require asgard/console 0.*
, (*4)
Usage
MyCommand class, (*5)
class MyCommand extends Asgard\Console\Command {
protected $name = 'mycommand';
protected $description = 'This is my command';
protected function getOptions() {
return [
['verbose', null, InputOption::VALUE_NONE, 'Verbose output.', null]
];
}
protected function getArguments() {
return [
['argument', InputArgument::REQUIRED, 'An argument.'],
];
}
}
Console script:, (*6)
$command = new MyCommand; #extends Asgard\Console\Command
containerlication = new MyApplication('MyApp', 5.6, new \Asgard\Container\Container); #extends Asgard\Console\Application
#application constructor parameters are optional
containerlication->add($command);
Command:, (*7)
php console mycommand theargument --verbose
, (*8)
Command methods
Get the services container, (*9)
$this->getContainer();
Call another command, (*10)
$this->call('another-command', $arguments=[]);
Call another command silently (no output), (*11)
$this->callSilent('another-command', $arguments=[]);
Ask for confirmation, (*12)
$this->confirm('Are you sure?');
Display an information, (*13)
$this->info('A message');
Display an error, (*14)
$this->error('A message');
Display a comment, (*15)
$this->comment('A message');
Display a question, (*16)
$this->question('A message');
, (*17)
Application methods
$container = $this->getContainer();
Contributing
Please submit all issues and pull requests to the asgardphp/asgard repository., (*18)
License
The Asgard framework is open-sourced software licensed under the MIT license, (*19)