middleWares[] = $call; return $this; } /** * @param array $array * @return $this */ public function setMiddleWares(array $array) { $this->middleWares = $array; return $this; } /** * @param $dispatch * @return mixed * @throws Exception */ public function getGenerate($dispatch) { $last = function ($passable) use ($dispatch) { return Dispatch::create($dispatch, $passable)->dispatch(); }; $data = array_reduce(array_reverse($this->middleWares), $this->core(), $last); $this->middleWares = []; return $data; } /** * @return Closure */ public function core() { return function ($stack, $pipe) { return function ($passable) use ($stack, $pipe) { if ($pipe instanceof \HttpServer\IInterface\Middleware) { return $pipe->handler($passable, $stack); } else { return $pipe($passable, $stack); } }; }; } }