checkValidProcess($process); $this->processes[] = $process; } /** * check if given classname implements Process interface * * @param $classname * * @throws InvalidProcessType */ protected function checkValidProcess($classname) { if (!in_array(Process::class, class_implements($classname))) { throw new InvalidProcessType($classname); } } /** * @param null $beforeStart */ public function setBeforeStart($beforeStart) { $this->checkValidProcess($beforeStart); if (!is_null($this->beforeStart)) { array_unshift($this->processes, $this->beforeStart); } $this->beforeStart = $beforeStart; } /** * @param null $beforeRender */ public function setBeforeRender($beforeRender) { $this->checkValidProcess($beforeRender); if (!is_null($this->beforeRender)) { array_push($this->processes, $this->beforeRender); } $this->beforeRender = $beforeRender; } /** * Run pipeline * * @param Content $page * * @return Content */ function run(Content $page) { $this->runBeforeStart($page); foreach ($this->processes as $process) { /** * @var $run Process */ $run = new $process; $run->handle($page); } $this->runBeforeRender($page); return $page; } private function runBeforeStart($page) { if (!is_null($this->beforeStart)) { $process = new $this->beforeStart; $process->handle($page); } } private function runBeforeRender($page) { if (!is_null($this->beforeRender)) { $process = new $this->beforeRender; $process->handle($page); } } }