在发出命令时,是否可以创建一种命令管道?
例如:
$this->dispatch(new UploadFileCommand)会打给ValidateFileCommand,WhateverCommand。
它类似于pipeThrough,但会触发特定的命令。
发布于 2015-06-22 12:13:08
在和一些人交谈后,我意识到我想得太多了。解决办法比我想象的要简单。若要浏览命令,只需执行:
public function whateverMethod(Dispatcher $dispacher) {
$dispached->pipeThrough([]) // arrays with commands
}碟子经过漂亮的拉拉5方法注射!
发布于 2015-06-21 12:25:35
我知道你刚才问过这个问题,但我还是觉得我会回答。
手工制作:中间件WhateverPipeline
然后,您将不得不添加
使用DispatchesCommands;
然后
$this->分派(新的WhateverCommand());
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Foundation\Bus\DispatchesCommands;
class WhateverPipeline {
use DispatchesCommands;
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$this->dispatch(new WhateverCommand());
return $next($request);
}
}WhateverCommand必须不是队列命令才能在那里执行,然后在管道中执行。
您还可以从WhateverCommand内部发出任何命令
使用DispatchesCommands;
https://stackoverflow.com/questions/28461390
复制相似问题