rogerthomas84 / ohconsole

3.0.0 2020-05-06 10:34 UTC

This package is auto-updated.

Last update: 2024-09-06 20:15:58 UTC


README

在Packagist上查看

OhConsole

OhConsole 是一个简单的接口,通过将命令抽象为独立的类来创建高级 PHP CLI 应用程序。

理论

参数被转换为命名空间。最终的路由类必须命名为 <你的名字>Route;

例如,命令 config get url 将寻找一个名为 Config\Get\UrlRoute 的类

快速开始

为了快速开始,首先创建你的核心命令文件。通常这可以是 bin/console。此文件应包含类似以下内容:

<?php
include 'vendor/autoload.php'; // Your autoloader.

use OhConsole\OhConsole;
// Map any injectables that you want to pass
$injectables = array(
    'config' => array(
        // Put any configuration here.
    )
);

// Start OhConsole
$command = new OhConsole($argv, $injectables);

// Run OhConsole
$command->run();

示例

一旦你设置了示例,调用你的主脚本(见下文),并传递在 PHP 文件中定义的一个命令。

php bin/console ohconsole examples one
php bin/console ohconsole examples two

以下是一个你可以用来开始的示例 script。你可以随意用你的自动加载器替换 include

<?php
include 'vendor/autoload.php'; // Your autoloader.

use OhConsole\OhConsole;

include 'OhConsole/Examples/ExampleOneRoute.php';
include 'OhConsole/Examples/ExampleTwoRoute.php';

$injectables = array(
    'config' => array(
        'db.name' => 'MyDatabaseName',
        'db.user' => 'root',
        'db.password' => 'password',
    )
);

$command = new OhConsole($argv, $injectables);
$command->run();