z0s / console
简单控制台框架,快速创建命令行PHP脚本
1.0.2
2022-10-17 14:55 UTC
Requires
- php: >=8.0
- kcs/class-finder: dev-master
- psr/container: ^2.0
- symfony/console: ^6.0
Requires (Dev)
- roave/security-advisories: dev-latest
This package is not auto-updated.
Last update: 2024-09-15 21:13:44 UTC
README
安装
您可以使用以下命令将其包含到您的项目中:composer require z0s/console
要求
- PSR-11兼容容器
- PHP8.0或更高版本
bin/console example
<?php
$autoloaderPath = __DIR__ . '/../vendor/autoload.php';
if(!file_exists($autoloaderPath)) {
throw new RuntimeException('Error, composer is not setup correctly.. Please run composer install');
}
$autoloader = require $autoloaderPath;
# Container
$container = new \League\Container\Container();
# Autowiring
$container->delegate(new \League\Container\ReflectionContainer());
# Load the CLI
$cli = new \z0s\Console\Console($container, $autoloader);
# Define the class scope to load commands from
$cli->setCommandsNamespace('z0s\\Commands');
# Define the name
$cli->setConsoleName('z0s');
# Define the version
$cli->setVersion('0.0.1');
# Run the cli
$cli->run();
命令示例
<?php
namespace z0s\Commands;
/**
* @property string $stringInput
*/
class Command extends \z0s\Console\ConsoleCommand
{
protected string $signature = 'command {--stringInput=Hello World : Some string to pass into the command }';
protected string $description = 'This is an example command';
public function handle(): void
{
$this->out($this->stringInput);
}
}