/** * @description call anonymous function */ public function call() { if ($this->response->getStatusCode() == 202) { $this->response->setStatusCode(200); $this->response->setHeaders(['Content-Type' => 'text/html']); } $params = $this->route->getParameters() == '' ? [] : $this->route->getParameters(); if (is_array($content = call_user_func_array($this->route->getTarget('closure'), $params))) { $this->route->addTarget('data', $content); } elseif (!is_null($content)) { $this->response->setContent($content); } }
/** * @return mixed * @throws \Exception */ public function call() { $reflectionMethod = new ReflectionMethod($this->route->getTarget('controller'), $this->route->getTarget('action')); $dependencies = []; $count = 0; foreach ($reflectionMethod->getParameters() as $arg) { is_null($arg->getClass()) ? $count++ : ($dependencies[] = call_user_func_array($this->route->getTarget('di'), [$arg->getClass()->name])); } if ($count == count($this->route->getParameters()) || $this->route->getParameters() == '' && $count == 0) { $dependencies = array_merge($dependencies, $this->route->getParameters() == '' ? [] : $this->route->getParameters()); if ($this->response->getStatusCode() == 202) { $this->response->setStatusCode(200); } if (is_array($content = $reflectionMethod->invokeArgs($this->getController(), $dependencies))) { $this->route->addTarget('data', $content); } elseif (!is_null($content)) { $this->response->setContent($content); } } else { $this->response->setStatusCode(404); } }