定制 kennyyuen/shark-sequential-command 二次开发

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

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

kennyyuen/shark-sequential-command

最新稳定版本:0.1.0

Composer 安装命令:

composer require kennyyuen/shark-sequential-command

包简介

README 文档

README

Sequential Command is a lightweight PHP library for building and managing chains of commands that execute sequentially. Ideal for workflow orchestration, task pipelines, and scenarios where ordered execution is required.

Installation

You can install the library via Composer:

composer require kennyyuen/shark-sequential-command

Features

  • Chain commands together for sequential execution
  • Waterfall and invoke execution modes
  • Easy to extend and integrate
  • Exception handling for completed commands

Usage

Basic Example

use Shark\Extensions\SequentialCommand\Command;
use function Shark\Extensions\SequentialCommand\chain;

$cmd1 = new Command(function () {
    echo "First command\n";
    return 'first';
});
$cmd2 = new Command(function () {
    echo "Second command\n";
    return 'second';
});
$cmd3 = new Command(function () {
    echo "Third command\n";
    return 'third';
});

chain($cmd1, $cmd2);
chain($cmd2, $cmd3);

$cmd3->invoke();
$cmd2->invoke();
$cmd1->invoke();

// Commands are executed after all in the chain has been invoked.
// Execution order: cmd1 -> cmd2 -> cmd3

Waterfall Execution

$cmd1->waterfall(); // Only runs if all downstream commands are invoked

Exception Handling

try {
    $cmd1->invoke();
    $cmd1->invoke(); // Throws RuntimeException: already completed
} catch (RuntimeException $e) {
    echo $e->getMessage();
}

Methods

  • Command::__construct(callable $callback) - Create a command with a callback
  • Command::invoke() - Run the command chain from the head
  • Command::waterfall() - Run only if all downstream commands are invoked
  • chain(Command $first, Command $second) - Chain two commands together
  • Command::isCompleted() - Check if command is completed
  • Command::getCallbackResult() - Get the result of the callback

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.

License

This project is licensed under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-07-24