定制 tobento/app-console 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tobento/app-console

最新稳定版本:2.0

Composer 安装命令:

composer require tobento/app-console

包简介

App console support.

README 文档

README

Console support for the app using the Console Service.

Table of Contents

Getting Started

Add the latest version of the app console project running this command.

composer require tobento/app-console

Requirements

  • PHP 8.4 or greater

Documentation

App

Check out the App Skeleton if you are using the skeleton.

You may also check out the App to learn more about the app in general.

Console Boot

The console boot does the following:

  • creates app file in the root directory if not exist
  • implements console interfaces
use Tobento\App\AppFactory;
use Tobento\Service\Console\ConsoleInterface;
use Tobento\Service\Console\ConsoleFactoryInterface;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots
$app->boot(\Tobento\App\Console\Boot\Console::class);
$app->booting();

// Implemented interfaces:
$consoleFactory = $app->get(ConsoleFactoryInterface::class);
$console = $app->get(ConsoleInterface::class);

// Run the app
$app->run();

If you are not using the App Skeleton you may adjust the ap file in the root directory with the path to your app:

// Get and run the application.
// (require __DIR__.'/app/app.php')->run();
(require __DIR__.'/path/to/app.php')->run();

Creating Commands

Check out the Console Service - Creating Commands section to learn more about creating commands.

Adding Commands

You can add commands in severval ways:

Using the app

You may use the app on method to register commands only if the console is requested.

use Tobento\App\AppFactory;
use Tobento\Service\Console\ConsoleInterface;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots:
$app->boot(\Tobento\App\Console\Boot\Console::class);

// Adding commands:
$app->on(ConsoleInterface::class, function(ConsoleInterface $console) {
    $console->addCommand($command);
});

// Run the app
$app->run();

Using the console boot

use Tobento\App\Boot;
use Tobento\App\Console\Boot\Console;

class AnyServiceBoot extends Boot
{
    public const BOOT = [
        // you may ensure the console boot.
        Console::class,
    ];
    
    public function boot(Console $console)
    {
        // you may add commands only if running in console:
        if ($console->runningInConsole()) {
            $console->addCommand($command);
        }
    }
}

Invoke Commands

To invoke application command just run:

php ap command:name

To get a list of available commands:

php ap list

Credits

统计信息

  • 总下载量: 131
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 13
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-01