infotechnohelp/lite-console

轻量级独立(仅限'nikolajev'包)PHP控制台工具

安装: 24

依赖项: 0

建议者: 0

安全: 0

星标: 0

分支: 0

类型:实用程序

dev-master 2022-01-22 11:46 UTC

This package is not auto-updated.

Last update: 2024-09-29 00:53:46 UTC


README

确保您的项目 composer.json 文件中包含

{
  "minimum-stability": "dev",
  "config": {
    "bin-dir": "bin"
  }
}

composer require infotechnohelp/lite-console

这将在您的项目内部创建一个 bin/lite (composer符号链接)文件。

配置Lite控制台

在项目根目录下创建 /lite-console.json 文件

namespace - 必需

命名异常 - 可选

如果包含LiteConsole命令文件的目录位于 src

{
  "namespace": "App\\LiteConsole\\"
}

如果composer自动加载psr-4命名空间 LiteConsole 已注册

{
  "namespace": "LiteConsole\\",
  "naming exceptions": {
    "new": "NewCommand"
  }
}

命名约定

bin/lite create 命令将执行 <AnyNamespace\>LiteConsole\Create

new 词汇已在PHP中保留,无法声明 class New

在这种情况下,您可以在 naming exceptions 部分指定此类异常

配置composer

NB!!! 如果包含LiteConsole命令文件的目录位于 src 中,则不需要此步骤

在您的项目 composer.json 内部

{
  "autoload": {
    "psr-4": {
      "LiteConsole\\": "LiteConsole/"
    }
  }
}

composer dump-autoload

创建命令类文件

/LiteConsole/NewCommand.php/src/LiteConsole/NewCommand.php

<?php

namespace LiteConsole; // || namespace App\LiteConsole;

use Infotechnohelp\LiteConsole\ConsoleCommand;

class NewCommand extends ConsoleCommand
{
    public function exec()
    {
        $this->getArguments(); // array ['file']
        $this->getArgument(0); // string 'file' 
        $this->getOptions(); // array ['ext' => 'txt']
        $this->optionIsSet('ext'); // bool true
        $this->getOptionValue('ext'); // string 'txt'
        
        // Any execution logics here
    }
}

现在您可以使用 bin/lite new file --ext=txt