nowise/uup-application
Composer 安装命令:
composer require nowise/uup-application
包简介
Run monitored command action for CLI command line and HTTP requests.
README 文档
README
Run the same command action both for CLI command line and HTTP requests with monitoring.
ACTIONS:
The action class handles business logic and the runner executes and monitor the action.
Example
<?php declare(strict_types=1); require_once(__DIR__ . '/../vendor/autoload.php'); use UUP\Application\Actions\HelloWorldAction; use UUP\Application\Command\ApplicationRunner; $action = new HelloWorldAction(); $runner = new ApplicationRunner($action); $runner->execute();
LIFETIME:
The action class derives from ApplicationAction and implements the lifetime methods usage(), setup(),
execute() and cleanup(). At least the setup method should be implemented, the other are optional.
class HelloWorldAction extends ApplicationAction { public function setup(): void { if ($this->options->isMissing('my-name')) { $this->options->setOption('my-name', "Anders"); } } public function execute(): void { if ($this->options->hasOption('my-name')) { printf("Hello world, %s!\n", $this->options->getString('my-name')); } } }
OPTIONS:
Command options are passed from CLI command options or HTTP request depending on execution context. The runner takes
are of handling help or quiet options. The standard options help, version and quiet are transparent handled along
with their short option equivalents.
MONITOR:
The runner execute the action class and provides error monitoring. By default, runner will terminate action when a throwable get caught. The error behavior can be overridden by action class.
INLINE:
For simple tasks, use an anonymous (java-style) class with implementations of wanted methods:
<?php declare(strict_types=1); require_once(__DIR__ . '/../vendor/autoload.php'); use UUP\Application\Command\ApplicationAction; use UUP\Application\Command\ApplicationRunner; (new ApplicationRunner(new class extends ApplicationAction { public function execute(): void { // TODO: Implement the business logic for script (this method is required). } }))->execute();
See example directory for code examples.
INFORMATION:
Provide help and version information by overriding base class methods in your action class.
HELP
Override the usage() method. Call parent method to output standard options.
class HelloWorldAction extends ApplicationAction { public function usage(): void { printf("Sample greeter action class.\n"); printf("\n"); printf("Options:\n"); printf(" my-name: Set caller name.\n"); printf("\n"); parent::usage(); } ... }
VERSION
Similar to usage, but override the version() instead. This method gives full control of version output.
class HelloWorldAction extends ApplicationAction { public function version(): void { printf("hello-world %s\n", $this->getVersion()); } public function getVersion(): string { return "1.2.2"; } ... }
If default version format is OK, then overriding the getVersion() method should be sufficient.
ZERO MAINTENANCE:
Hint: Consider reading version string from your package composer.json file instead of using a hard coded string that requires manual update!
nowise/uup-application 适用场景与选型建议
nowise/uup-application 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「http」 「cli」 「command」 「application」 「monitor」 「action」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nowise/uup-application 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nowise/uup-application 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nowise/uup-application 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Wrapper for exec and it's results
repository php library
Symfony bundle to monitor and execute commands
Shell command module for PHP.
Library with classes to help you do batch.
Command bus implementation: Commands and domain events
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2022-01-07