php管道模式手测
先写在这里,待完善 interface PipelineInterface{ public function send($traveler); public function through($stops); public function via($method); public function process();}interface StageInterface{ public function handle($payload);}class StageOne implements StageInterface{ public function handle($payload) { echo $payload . ' He is a '; }} class StageTwo implements StageInterface{ public function handle($payload) { echo 'awesomeman'; }} class Pipe implements PipelineInterface{ protected $container; protected $passable; protected $pipes = []; protected $via = 'handle'; public function __construct($container) { $this->container = $container; } public function send($passable) { $this->passable = $passable; return $this; } public function through($pipes) { $this->pipes = is_array($pipes) ? $pipes : func_get_args(); return $this; } public function via($method) { $this->via = $method; return $this; } public function process() { foreach ($this->pipes as $pipe) { call_user_func([$pipe, $this->via], $this->passable); } }}$container = 'a';$payload = 'wa';$pipe = new Pipe($container);$pipe->send($payload)->through([(new StageOne), (new StageTwo)])->process();