本文整理汇总了PHP中Router::getRoutes方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::getRoutes方法的具体用法?PHP Router::getRoutes怎么用?PHP Router::getRoutes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::getRoutes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddRoute
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: parseUri
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: Router
<?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: testInterceptCallToUnknownMethodsAndAddNamedRoute
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: Router
// 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: __construct
/**
* @param \Rougin\Slytherin\Dispatching\FastRoute\Router $router
*/
public function __construct(Router $router)
{
$this->dispatcher = \FastRoute\simpleDispatcher($router->getRoutes());
$this->router = $router;
}
示例7: _getSorted
/**
* 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: Dataporten
$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));