z0s/console

简单控制台框架,快速创建命令行PHP脚本

维护者

详细信息

gitlab.com/z0s/console

源代码

问题

安装次数: 23

依赖项: 0

建议者: 0

安全性: 0

星标: 0

分支: 0

类型:composer-package

1.0.2 2022-10-17 14:55 UTC

This package is not auto-updated.

Last update: 2024-09-15 21:13:44 UTC


README

安装

您可以使用以下命令将其包含到您的项目中:composer require z0s/console

要求

  1. PSR-11兼容容器
  2. 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);
    }
}