net_bazzline/php_component_process_pipe

免费如自由PHP组件,简化PHP中管道进程的创建

1.1.1 2016-07-29 07:00 UTC

This package is auto-updated.

Last update: 2024-08-29 12:33:41 UTC


README

此免费如自由的组件简化了在PHP中创建进程管道的过程。

实际上,它是一个伪管道(进程集合或进程批处理),因为PHP进程至今仍然是单线程的。

目前,没有计划在代码库中添加STDINSTDOUTSTDERR的实现。错误可以通过抛出的异常来处理。输入由ExecutableInterface定义,以及输出(返回值)。

当前主分支的构建状态由Travis CI跟踪:Build Status Latest stable

scrutinizer状态为:code quality

versioneye状态为:dependencies

下载量:Downloads this Month

它还可在openhub.net找到。

变更日志可在此处找到。

为什么?

  • 将复杂操作分解为更简单的操作
  • 简化小型进程的单元测试
  • 分离责任(数据生成器/转换器/验证器/流程操纵器)
  • 创建可在代码中阅读的进程链(将集成代码与操作代码分开)
  • 无依赖关系(除非您想加入开发团队)

示例

安装

手动

mkdir -p vendor/net_bazzline/php_component_process_pipe
cd vendor/net_bazzline/php_component_process_pipe
git clone https://github.com/bazzline/php_component_process_pipe

使用Packagist

composer require net_bazzline/php_component_process_pipe:dev-master

使用方法

使用管道方法进行多个进程

use Net\Bazzline\Component\ProcessPipe\ExecutableException;
use Net\Bazzline\Component\ProcessPipe\InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\Pipe;

try {
    $pipe = new Pipe();
    
    $pipe->pipe(
        new ProcessOne(), 
        new ProcessTwo()
    );
    
    $output = $pipe->execute($input);
} catch (ExecutableException) {
    //handle process exception
} catch (InvalidArgumentException) {
    //handle pipe exception
}

为每个进程使用一次管道方法

use Net\Bazzline\Component\ProcessPipe\ExecutableException;
use Net\Bazzline\Component\ProcessPipe\InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\Pipe;

try {
    $pipe = new Pipe();
    
    $pipe->pipe(new ProcessOne());
    $pipe->pipe(new ProcessTwo());
    
    $output = $pipe->execute($input);
} catch (ExecutableException) {
    //handle process exception
} catch (InvalidArgumentException) {
    //handle pipe exception
}

通过实例化

use Net\Bazzline\Component\ProcessPipe\ExecutableException;
use Net\Bazzline\Component\ProcessPipe\InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\Pipe;

try {
    $pipe = new Pipe(
        new ProcessOne(),
        new ProcessTwo()
    );
    
    $output = $pipe->execute($input);
} catch (ExecutableException) {
    //handle process exception
} catch (InvalidArgumentException) {
    //handle pipe exception
}

全部完成

use Net\Bazzline\Component\ProcessPipe\ExecutableException;
use Net\Bazzline\Component\ProcessPipe\InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\Pipe;

try {
    $pipe = new Pipe(
        new ProcessOne(),
        new ProcessTwo()
    );
    
    $pipe->pipe(new ProcessThree());
    $pipe->pipe(
        new ProcessFour(),
        new ProcessFive()
    );

    $output = $pipe->execute($input);
} catch (ExecutableException) {
    //handle process exception
} catch (InvalidArgumentException) {
    //handle pipe exception
}

API

API 可在 bazzline.net 获取。

开发注意事项

代码更改后,请运行

composer check
./vendor/bin/rector process
./vendor/bin/php-cs-fixer fix example
./vendor/bin/php-cs-fixer fix source
./vendor/bin/php-cs-fixer fix test

链接

感谢

其他管道实现

结语

如果你喜欢,请给它点星 :-). 如果需要,请添加问题。如果你喜欢它,请拉取补丁。如果你使用了它,请写一篇博客。如果你热爱它,请捐赠 :-]。