Beispiel #1
0
 public static function addRoute(Route $route)
 {
     static::$routes[] = $route;
     $method = $route->getMethod();
     $addr = $route->getAddr();
     $argsSize = $route->getArgsSize();
     $route->addToTree(static::$routesTree);
     return $route;
 }
Beispiel #2
0
 public function add(Route $route)
 {
     $path = $route->getParsed()->getPathPattern();
     $method = $route->getMethod();
     if (!isset($this->pathMethodMap[$path])) {
         $this->pathMethodMap[$path] = [];
     } else {
         if (in_array($method, $this->pathMethodMap[$path])) {
             throw new \InvalidArgumentException("Method {$method} is already defined for {$path}");
         }
     }
     $name = $route->getName();
     if ($name !== null) {
         if (isset($this->routeNames[$name])) {
             throw new \InvalidArgumentException("Route {$name} is already defined");
         }
         $this->routeNames[$name] = $route;
     }
     $this->pathMethodMap[$path][] = $method;
     $this->routes[] = $route;
 }
Beispiel #3
0
 /**
  *
  */
 private function addVariableRoute($routeData, Route $route)
 {
     list($regex, $arguments) = $this->buildRegexForRoute($routeData);
     foreach ($route->getMethod() as $method) {
         if (isset($this->dynamicRoutes[$method][$regex])) {
             throw new Exception("Cannot register two routes matching \"{$regex}\" for method \"{$method}\"");
         }
         $route->regex = $regex;
         $route->arguments = $arguments;
         $this->dynamicRoutes[$method][$regex] = $route;
     }
 }
Beispiel #4
0
<?php

//This Application Development by ITGET Business Solution
//Powered by ITGET PHP Framework Version 1.0.alpha.1
//www.itget.net info@itget.net
include 'url_rewrite.php';
include 'auto_load.php';
$className = Route::getClass();
$obj = new $className();
if (($methodName = Route::getMethod()) !== null) {
    $obj->{$methodName}();
}
//$home->$_URL[1]();
 /**
  * Checks if the URL matches the transmitted rule.
  *
  * @param Route $route Object
  *
  * @return bool
  */
 protected function matchRoute($route)
 {
     $params = array();
     $key_params = array_keys($route->getParams());
     $value_params = $route->getParams();
     foreach ($key_params as $key) {
         $params['<' . $key . '>'] = $value_params[$key];
     }
     $url = $this->basePath . $route->getPath();
     // Replaces the corresponding marks on regular expressions
     $url = str_replace(array_keys($params), $params, $url);
     // If no tag in the $ params array allows for any character
     $url = preg_replace('/<\\w+>/', '.*', $url);
     // checks pattern matching
     preg_match("#^{$url}\$#", $this->url, $results);
     if ($results) {
         $this->class = $route->getClass();
         $this->method = $route->getMethod();
         return true;
     }
     return false;
 }
Beispiel #6
0
 public function testMethod()
 {
     // all
     $route = new Route("/");
     $this->assertEquals("", $route->getMethod());
     $this->assertSame(null, $route->getMethod());
     // GET
     $route->setMethod("GET");
     $this->assertEquals("GET", $route->getMethod());
     // lowercase
     $route->setMethod("post");
     $this->assertEquals("POST", $route->getMethod());
     // all
     $route->setMethod(null);
     $this->assertEquals("", $route->getMethod());
     $this->assertSame(null, $route->getMethod());
     // several
     $route->setMethod("GET|POST|PUT");
     $this->assertEquals("GET|POST|PUT", $route->getMethod());
     // all
     $route->setMethod("");
     $this->assertEquals("", $route->getMethod());
     $this->assertSame(null, $route->getMethod());
 }
Beispiel #7
0
 public function __construct()
 {
     if (Route::getMethod() == null) {
         echo "This is constuctor method";
     }
 }