Пример #1
0
 public function testAddRoute()
 {
     $router = new Router();
     $route = $this->getMock('Route');
     $router->addRoute('myroute', $route);
     $routes = $router->getRoutes();
     $this->assertTrue(array_key_exists('myroute', $routes));
 }
Пример #2
0
 public static function parseUri($uriToParse)
 {
     $result = array();
     $routes = Router::getRoutes();
     $hasArea = Router::uriHasArea($uriToParse);
     $normalizedUri = Router::normalizeUri($uriToParse);
     $normalizedSplitUri = explode("/", $normalizedUri);
     // try custom routes
     foreach ($routes as $route) {
         if ($hasArea) {
             if (strstr($normalizedUri, "/") !== false) {
                 $normalizedUri = strstr($normalizedUri, "/");
                 $normalizedUri = substr($normalizedUri, 1);
             }
         }
         if (Router::startsWith($normalizedUri, $route["url"])) {
             if ($hasArea) {
                 $result['area'] = $route['area'];
             }
             $result['controller'] = $route['controller'];
             $result['method'] = $route['method'];
             $paramsUri = str_ireplace($route['url'], "", $normalizedUri);
             $params = explode("/", $paramsUri);
             $result['parameters'] = array_filter($params);
             return $result;
         }
     }
     // default route
     if ($hasArea) {
         $result['area'] = $normalizedSplitUri[0];
         $result['controller'] = $normalizedSplitUri[1] . "Controller";
         if (isset($normalizedSplitUri[2])) {
             $result['method'] = $normalizedSplitUri[2];
             $result['parameters'] = array_slice($normalizedSplitUri, 3);
         } else {
             $result['method'] = 'index';
         }
     } else {
         $result['controller'] = $normalizedSplitUri[0] . "Controller";
         if (isset($normalizedSplitUri[1])) {
             $result['method'] = $normalizedSplitUri[1];
             $result['parameters'] = array_slice($normalizedSplitUri, 2);
         } else {
             $result['method'] = 'index';
         }
     }
     return $result;
 }
Пример #3
0
<?php

//spl_autoload_register();
require '../Core/Router.php';
$router = new Router();
$router->add('', ['controller' => 'Home', 'action' => 'index']);
$router->add('posts', ['controller' => 'Posts', 'action' => 'index']);
//$router->add('posts/new', ['controller' => 'Posts', 'action' => 'new']);
$router->add('{controller}/{action}');
$router->add('admin/{controller}/{action}');
$url = $_SERVER['QUERY_STRING'];
if ($router->match($url)) {
    echo '<pre>';
    var_dump($router->getRoutes());
    var_dump($router->getParams());
    echo '</pre>';
} else {
    echo 'no routes found for URL ' . $url;
}
Пример #4
0
 public function testInterceptCallToUnknownMethodsAndAddNamedRoute()
 {
     $this->Router->person('person/:name');
     $this->assertEqual(1, count($this->Router->getRoutes()));
     $this->assertEqual(array('person'), array_keys($this->Router->getRoutes()));
 }
Пример #5
0
//  http://altorouter.com
require_once $BASE . '/lib/router.class.php';
$router = new Router();
// $router->addMatchTypes(array('userlist' => '[0-9A-Za-z\[\]@.,%]++'));
$router->setBasePath($API_BASE_PATH);
// Relay API
require_once $BASE . '/lib/relay.class.php';
$relay_config = json_decode(file_get_contents($RELAY_CONFIG_PATH), true);
$relay = new Relay($relay_config);
// ---------------------- DEFINE ROUTES ----------------------
/**
 * GET all REST routes
 */
$router->map('GET', '/', function () {
    global $router;
    Response::result($router->getRoutes());
}, 'Routes listing');
/**
 * GET TechSmith Relay version
 */
$router->map('GET', '/version/', function () {
    global $relay;
    Response::result($relay->getRelayVersion());
}, 'TechSmith Relay version');
/**
 * GET Template
 *
 * $router->map('GET', '/PATH/[i:iD]/status/', function ($iD) {
 * global $dataporten;
 * Response::result(array('status' => true, 'data' => $dataporten->SOME_FUNCTION($iD)));
 * }, 'DESCRIPTION OF ROUTE');
Пример #6
0
 /**
  * @param \Rougin\Slytherin\Dispatching\FastRoute\Router $router
  */
 public function __construct(Router $router)
 {
     $this->dispatcher = \FastRoute\simpleDispatcher($router->getRoutes());
     $this->router = $router;
 }
Пример #7
0
 /**
  * TODO Comments.
  */
 private static function _getSorted()
 {
     if (!self::$_sorted) {
         $routes = Router::getRoutes();
         foreach ($routes as $route => $routeData) {
             if (isset($routeData['permissions']) && $routeData['permissions']) {
                 if (!User::current()->hasPermission($routeData['permissions'])) {
                     continue;
                 }
             }
             $ref =& self::$_sorted;
             $routeBits = explode('/', $route);
             $pathBits = array();
             while ($routeBits) {
                 $bit = array_shift($routeBits);
                 $pathBits[] = $bit;
                 $path = implode('/', $pathBits);
                 if (!isset($ref[$path])) {
                     // For parent routes that dont exist, set a null values
                     $ref[$path] = array('title' => null, 'hidden' => false, 'children' => array());
                     if ($path == $route) {
                         if (isset($routeData['title'])) {
                             $ref[$path]['title'] = $routeData['title'];
                         }
                         if (isset($routeData['hidden'])) {
                             $ref[$path]['hidden'] = $routeData['hidden'];
                         }
                         // Always hide param based items
                         if (strstr($path, '%') || strstr($path, ':')) {
                             $ref[$path]['hidden'] = true;
                         }
                     }
                 }
                 $ref =& $ref[$path]['children'];
             }
         }
     }
     return self::$_sorted;
 }
Пример #8
0
 /**
  * @param \Rougin\Slytherin\Dispatching\Phroute\Router $router
  */
 public function __construct(Router $router)
 {
     $this->dispatcher = new \Phroute\Phroute\Dispatcher($router->getRoutes());
     $this->router = $router;
 }
Пример #9
0
$dataporten = new Dataporten($dataporten_config);
//  http://altorouter.com
require_once $BASE . '/lib/router.class.php';
$router = new Router();
$router->setBasePath($API_BASE_PATH);
// Proxy API to Adobe Connect
require_once $BASE . '/lib/adobeconnect.class.php';
$adobe_config = json_decode(file_get_contents($ADOBE_CONNECT_CONFIG_PATH), true);
$connect = new AdobeConnect($adobe_config);
// ---------------------- DEFINE ROUTES ----------------------
/**
 * GET all REST routes
 */
$router->map('GET', '/', function () {
    global $router;
    Response::result(array('status' => true, 'routes' => $router->getRoutes()));
}, 'Routes listing');
/**
 * GET Adobe Connect version
 */
$router->map('GET', '/version/', function () {
    global $connect;
    Response::result($connect->getConnectVersion());
}, 'Adobe Connect version');
/**
 * Get all subfolders for Shared Meetings/{$orgFolderName}
 */
$router->map('GET', '/folder/[a:org]/nav/', function ($orgFolderName) {
    verifyOrgAccess($orgFolderName);
    global $connect;
    Response::result($connect->getOrgFolderNav($orgFolderName));