asgard/console

v0.3.1 2016-05-13 11:31 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:50:30 UTC


README

#Console

Asgard 控制台包是 Symfony 控制台组件的简单扩展,请参阅 Symfony 控制台组件简介

##安装 如果你正在使用 Asgard 项目,则无需安装此库,因为它已经是标准库的一部分。

composer require asgard/console 0.*

##使用

MyCommand 类

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.'],
		];
	}
}

控制台脚本

$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);

命令

php console mycommand theargument --verbose

##命令方法

获取服务容器

$this->getContainer();

调用另一个命令

$this->call('another-command', $arguments=[]);

静默调用另一个命令(无输出)

$this->callSilent('another-command', $arguments=[]);

请求确认

$this->confirm('Are you sure?');

显示信息

$this->info('A message');

显示错误

$this->error('A message');

显示注释

$this->comment('A message');

显示问题

$this->question('A message');

##应用程序方法

$container = $this->getContainer();

###贡献

请将所有问题和拉取请求提交到 asgardphp/asgard 仓库。

许可

Asgard 框架是开源软件,根据 MIT 许可证 许可。