Example #1
0
 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!');
 }
Example #2
0
    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 : '';
    }
Example #3
0
    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 : '';
    }
Example #4
0
 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;
     }
 }
Example #5
0
 private function createParameters(RouteRule $routeRule, Uri $uri)
 {
     $parameters = $routeRule->getParameters() ? $routeRule->getParameters() : $uri->getParams();
     $requestParameters = Uri::getRequestParameters();
     return array_merge($parameters, $_POST, $_GET, $requestParameters);
 }
Example #6
0
 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;
         });
     }
 }