承接 duncan3dc/console 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

duncan3dc/console

Composer 安装命令:

composer require duncan3dc/console

包简介

Create command line php applications using symfony/console

README 文档

README

Create command line php applications using symfony/console.
This is basically a fork of symfony/console which does things a little differently and adds some extra features.
Most of the features are useful when running commands in a background context (such as via crontab).

release build coverage

Loading Commands

Commands can be automatically created from classes (meaning you don't need to call setName() inside your command class) using the following criteria:

  • Files/classes must be named using CamelCase and must end in "Command" (with files having the .php extension)
  • Each uppercase character will be converted to lowercase and preceded by a hyphen
  • Directories will represent namespaces and each separater will be replaced with a colon
    Using the example below, the file src/commands/Category/Topic/RunCommand.php will create a command called category:topic:run
$application->loadCommands("src/commands");

Of course, they can still be added the symfony way

Output

We use league/climate for terminal output, whilst also maintaining support for the symfony way.
So all of the following is possible:

$output->blue()->out("Blue? Wow!");
$output->dump($complexArrayForCLImate);
$output->writeln("<error>I am a symfony/console error</error>");
$output->error("I am a league/climate error");

Time Limit Commands

Commands can limit how long they are run for, and end in a controlled way when the limit is reached.
Inside your command's class you can call the timeout() method and pass the number of seconds your command should run for.

class LimitedCommand extends \duncan3dc\Console\Command
{
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        while (true) {
            # If the command has been running for more than 10 minutes then end now
            if ($this->timeout(60 * 10)) {
                break;
            }
        }
    {
}

This behaviour can be overridden by passing the --no-time-limit when running the application, this will cause the timeout() method to always return false

Calling An Existing Command

The symfony way of calling an existing command can be a little long-winded, with steps that seem unnecessary (eg, specifying the command name twice).
The runCommand() method provides a simplified way of doing this (using the example from the symfony docs):

$returnCode = $this->getApplication()->runCommand("demo:greet", [
    "name"      =>  "Fabien",
    "--yell"    =>  true,
], $input, $output);

This also ensures any command event listeners that have been registered are called, which symfony does not do

Command Locking

All commands are automatically locked to prevent the same command being run simultaneously on the same host.
You can prevent particular commands from locking using the doNotLock() method:

protected function configure()
{
    $this
        ->doNotLock()
        ->setDescription("This command can run as many times as it likes, whether the previous run has finished or not");
}

When a command cannot run it will exit with status 201, represented by the class constant Application::STATUS_LOCKED

Tab Completion

Tab completion is provided by stecman/symfony-console-completion and instructions on setting it up for your application can be found in the README.md of that repository.

Namespace Listing

When you are entering commands in completion mode, it can often be useful to view the list of available commands in the namespace.
For example you might type cat then press tab which would complete the namespace, and the namespace separator:

:~$ console category:

But when you press tab again, you might be presented with a list of commands (or sub-namespaces) you don't entirely recognise. At this point the symfony way would be to delete the colon, run your cursor back to before your namespace, and type list:

:~$ console list category

Then having identified the command you need from the listing you would then need to type what you had earlier, before entering the command you require:

:~$ console category:

To make this use case easier, we have made running a command with a trailing colon, an alias for the list command shown above, so you can actually run:

:~$ console category:

Which will list all your available commands, then you can press the up arrow to retrieve that same command from your shell's history and carry on entering the command name, much quicker

duncan3dc/console 适用场景与选型建议

duncan3dc/console 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 263.49k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2014 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「cli」 「console」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 duncan3dc/console 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 duncan3dc/console 我们能提供哪些服务?
定制开发 / 二次开发

基于 duncan3dc/console 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 263.49k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 15
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2014-11-23