skillberto/command-handler
Composer 安装命令:
composer require skillberto/command-handler
包简介
Simple isolated command handler library.
README 文档
README
Install
Install from composer:
$ composer require skillberto/command-handler "~1.0"
Authors and contributors
- Norbert Heiszler (Creator, developer)
Usage
The following example show you how you can us it:
use Symfony\Component\Console\Output\ConsoleOutput;
use Skillberto\CommandHandler\CommandHandler;
use Skillberto\CommandHandler\Command;
$output = new ConsoleOutput();
$handler = new CommandHandler($output);
$handler->add( 'some commands' );
... or
$handler->addCommand(new Command('some commands'));
$handler->execute();
You can define collections too:
$handler->addCollection(array('some commands'));
... or
$handler->addCommands(array(new Command('some commands')));
If you want to skip a command if it's not required:
$handler->addSkippable('some commands');
... or
$handler->addCommand(new Command('some commands', false));
... or add more commands
$handler->addSkippableCollection( array( 'some commands' ) );
... or
$handler->addCommands(array(new Command('some commands', false)));
$handler->execute();
...after that you can get these commands:
$handler->getSkippedMessages();
But, if you don't skip a command, and it's not successful:
$handler->getErrorMessage();
Advanced usage
Prefix
The following example show you have can you use the prefix:
...
$handler = new CommandHandler($output, "php ");
... or
$handler = new CommandHandler($output);
$handler->addPrefix("php ");
... then
$handler->add("--version");
$handler->execute();
In this case, you will execute php --version.
Timeout
It can be defined for each command, or only for some commands, or both of them.
$handler = new CommandHandler($output, "", 0.2);
... or
$handler = new CommandHandler($output);
$handler->setTimeout(0.2);
... then
$handler->addCommand(new Command("php --version", true, 0.3);
$handler->add('something');
$handler->execute();
In the previous example every command will have "0.2 seconds" for execution, except php --version, it has got "0.3 seconds".
Let's see how can you define group timeout:
$handler = new CommandHandler($output);
$handler->setTimeout(0.2);
$handler->addCollection(array('some command'));
$handler->setTimeout(0.3);
$handler->addCollection(array('some command'));
$handler->execute();
In this example the first collection have "0.2 seconds", the second "0.3 seconds".
Handler injection, merge
In some case, we need to define more then one handler, eg.: for different prefixes. But don't worry about it, we have got a useful method:
$handler_1->addHandler($handler_2);
It's good, but what will be with prefixes and timeout?
For these problems, CommandHandler has got three different merge types:
MERGE_ALL, MERGE_NON, MERGE_NOT_DEFINED
The default is MERGE_NON, but you can change it:
$handler_1->addHandler($handler_2, CommandHandler::MERGE_ALL, CommandHandler::MERGE_NOT_DEFINED);
In the previous example prefix merge has got MERGE_ALL type, timeout has got MERGE_NOT_DEFINED type.
MERGE_ALL means that $handler_1 prefix / timeout will use for all of them.
MERGE_NOT_DEFINED means that $handler_1 prefix / timeout will use, if it's not defined for $handler_2 command(s).
MERGE_NON means that prefixes and timeouts will be separated.
Callback
You can define a callback for each execution:
...
use Symfony\Component\Process\Process;
use Skillberto\CommandHandler\Command;
...
$handler->execute(function(Progress $progress, Command $command) {
//something more
});
skillberto/command-handler 适用场景与选型建议
skillberto/command-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 78 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「command」 「install」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 skillberto/command-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 skillberto/command-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 skillberto/command-handler 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Wrapper for exec and it's results
Symfony bundle to monitor and execute commands
Install Plugin for NetCommons3
Shell command module for PHP.
Library with classes to help you do batch.
统计信息
- 总下载量: 78
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-08