/** * dispatch the controller * * @throws ControllerException * @return \Anonym\Components\Route\Controller */ public function dispatch() { $name = $this->generateClassName($this->namespace, $this->class); // the controller instance $controller = App::make($name); if ($controller instanceof Controller) { // register the parameters $controller->setParameters(ParameterBag::getParameters()); // return the instance return $controller; } else { throw new ControllerException(sprintf('%s is not a controller', $name)); } }
/** * * find and replace parameters * * @return bool */ private function replaceParameters() { if (preg_match($this->regexSchema, $this->getMatchUrl())) { preg_replace_callback($this->getRegexSchema(), [$this, 'resolvePregCallback'], $this->getMatchUrl()); $resolve = $this->resolveParameters($this->getParameters()); // something went wrong! if (false === $resolve) { return false; } ParameterBag::setParameters($this->getParameters()); } elseif ($this->getMatchUrl() !== $this->getRequestedUrl()) { return false; } return true; }
/** *Regex kontrolu yapar * * @param string|null $url * @return bool */ public function match($url = null) { $match = parent::match($url); $regex = $this->getRegex($this->getMatchUrl()); if ($regex !== ' ') { if (preg_match("@" . ltrim($regex) . "@si", $this->getRequestedUrl(), $matches) || true === $match) { unset($matches[0]); ParameterBag::setParameters($matches); return true; } else { return false; } } else { return false; } }
/** * Call the method of controller * * @param Controller $controller the instance of controller * @param string $method the name of a controller method * @return mixed */ private function callControllerMethod(Controller $controller, $method) { return app()->call([$controller, $method], ParameterBag::getParameters()); }