public function createController(RouteRule $routeRule) { $controllerName = ClassName::pathToFullyQualifiedName($routeRule->getController()); foreach ($this->controllerNamespaces as $controllerNamespace) { $controller = $controllerNamespace . $controllerName . "Controller"; if (class_exists($controller)) { return $this->getInstance($routeRule, $controller); } } throw new ControllerNotFoundException('Controller [' . $controllerName . '] for URI [' . $routeRule->getUri() . '] does not exist!'); }
private function _createFunction(RouteRule $routeRule) { $name = $routeRule->getName(); $uri = $routeRule->getUri(); $parameters = $this->_prepareParameters($uri); $uriWithVariables = str_replace(':', '$', $uri); $parametersString = implode(', ', $parameters); $checkParametersStatement = $this->_createCheckParameters($parameters); $function = <<<FUNCTION function {$name}({$parametersString}) { {$checkParametersStatement}return url("{$uriWithVariables}"); } FUNCTION; return $name ? $function : ''; }
private function createFunction(RouteRule $routeRule) { $applicationPrefix = Config::getValue("global", "prefix_system"); $name = $routeRule->getName(); $uri = $routeRule->getUri(); $uriWithVariables = preg_replace('/:(\\w+)/', '" + $1 + "', $uri); $parameters = $this->prepareParameters($uri); $parametersString = implode(', ', $parameters); $checkParametersStatement = $this->createCheckParameters($parameters); $function = <<<FUNCTION function {$name}({$parametersString}) { {$checkParametersStatement}return "{$applicationPrefix}{$uriWithVariables}"; } FUNCTION; return $name ? $function : ''; }
private static function addRoute($method, $uri, $action, $requireAction = true, $options = array(), $isResource = false) { $methods = Arrays::toArray($method); if (self::$isDebug && $requireAction && self::$validate && self::existRouteRule($methods, $uri)) { $methods = implode(', ', $methods); throw new InvalidArgumentException('Route rule for method ' . $methods . ' and URI "' . $uri . '" already exists'); } $elements = explode('#', $action); $controller = Arrays::first($elements); $actionToRule = Arrays::getValue($elements, 1); $routeRule = new RouteRule($method, $uri, $controller, $actionToRule, $requireAction, $options, $isResource); if ($routeRule->hasRequiredAction()) { throw new InvalidArgumentException('Route rule ' . $uri . ' required action'); } self::$routes[] = $routeRule; foreach ($methods as $method) { self::$routeKeys[$method . $uri] = true; } }
private function createParameters(RouteRule $routeRule, Uri $uri) { $parameters = $routeRule->getParameters() ? $routeRule->getParameters() : $uri->getParams(); $requestParameters = Uri::getRequestParameters(); return array_merge($parameters, $_POST, $_GET, $requestParameters); }
private function _printExceptIfExists(RouteRule $rule, $table) { $except = $rule->getExcept(); if ($except) { $table->addRow(array('', '', ' <info>except:</info>', '')); Arrays::map($except, function ($except) use($table) { $table->addRow(array('', '', ' ' . $except, '')); return $except; }); } }