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 callbackCommand::invoke()- Run the command chain from the headCommand::waterfall()- Run only if all downstream commands are invokedchain(Command $first, Command $second)- Chain two commands togetherCommand::isCompleted()- Check if command is completedCommand::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
其他信息
- 授权协议: Unknown
- 更新时间: 2025-07-24