public function testPathForWithBasePath() { $methods = ['GET']; $pattern = '/hello/{first:\\w+}/{last}'; $callable = function ($request, $response, $args) { echo sprintf('Hello %s %s', $args['first'], $args['last']); }; $this->router->setBasePath('/base/path'); $route = $this->router->map($methods, $pattern, $callable); $route->setName('foo'); $this->assertEquals('/base/path/hello/josh/lockhart', $this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart'])); }
} die; } //Globals $cms->addGlobal("baseurl", $config->baseurl); $cms->addGlobal("siteTitle", $config->siteTitle); //session/user globals if ($user->isSinged()) { $cms->addGlobal("isSinged", "1"); $cms->addGlobal("username", $_SESSION['userName']); } // Routing require_once $APP_DIR . "/class/router/route.php"; require_once $APP_DIR . "/class/router/router.php"; $router = new Router(); $router->setBasePath(''); require_once $APP_DIR . "/routes.php"; $route = $router->matchCurrentRequest(); if ($route) { $array = $route->getTarget(); if (isset($array["get"])) { $_GET[$array["get"]] = true; } if (isset($array["post"])) { $_GET[$array["post"]] = true; } foreach ($route->getParameters() as $key => $value) { $_GET[$key] = mysql_real_escape_string($value); $_POST[$key] = mysql_real_escape_string($value); } $loadPage = $APP_DIR . "/controller/" . $array["url"] . ".php";
$RELAY_CONFIG_PATH = '/var/www/etc/relay-fusjonator/relay_fusjonator_TEST.js'; $API_BASE_PATH = '/api/relay-fusjonator'; // Remember to update .htacces as well. Same with a '/' at the end... // $BASE = dirname(__FILE__); // Result or error responses require_once $BASE . '/lib/response.class.php'; // Checks CORS and pulls Dataporten info from headers require_once $BASE . '/lib/dataporten.class.php'; $feide_config = json_decode(file_get_contents($DATAPORTEN_CONFIG_PATH), true); $feide = new Dataporten($feide_config); // 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 */
<?php require 'Router.php'; require 'Route.php'; $router = new Router(); $router->setBasePath('/PHP-Router'); $router->map('/', 'someController:indexAction', array('methods' => 'GET')); $router->map('/users/', 'users#create', array('methods' => 'POST', 'name' => 'users_create')); $router->map('/users/:id/edit/', 'users#edit', array('methods' => 'GET', 'name' => 'users_edit', 'filters' => array('id' => '(\\d+)'))); $router->map('/contact/', array('controller' => 'someController', 'action' => 'contactAction'), array('name' => 'contact')); $router->map('/blog/:slug', array('c' => 'BlogController', 'a' => 'showAction')); // capture rest of URL in "path" parameter (including forward slashes) $router->map('/site-section/:path', 'some#target', array('filters' => array('path' => '(.*)'))); $route = $router->matchCurrentRequest(); ?> <h3>Current URL & HTTP method would route to: </h3> <?php if ($route) { ?> <strong>Target:</strong> <pre><?php var_dump($route->getTarget()); ?> </pre> <strong>Parameters:</strong> <pre><?php var_dump($route->getParameters()); ?> </pre> <?php
<?php session_cache_limiter(false); session_start(); require '../vendor/autoload.php'; require "../settings_routes.php"; $autoloadManager = new autoloadManager(null, autoloadManager::SCAN_ONCE); $autoloadManager->addFolder('../app/controller'); $autoloadManager->addFolder('../app/model'); $autoloadManager->register(); if ($debug) { header('Access-Control-Allow-Origin: *'); } $router = new Router(); $router->setBaseClass($baseClass); $router->setBasePath($basePath); $router->addRoutes($routes); $router->set404Handler($erroHandler); $router->run();