function testWildcardCheck() { Router::resetRoutes(); Router::addRoutes(array("foo" => "foo.php")); Router::addRoutes(array(":anything" => "bar.php?key=:anything")); try { // because things are added in reverse order, this rule can never fire due to // the wildcard above Router::addRoutes(array("ignored" => "ignored.php")); $this->fail("Should have thrown an exception"); } catch (\Openclerk\RouterException $e) { // expected } }
<?php /** * Defines routes. */ // load up API routes foreach (DiscoveredComponents\Apis::getAllInstances() as $uri => $handler) { \Openclerk\Router::addRoutes(array($handler->getEndpoint() => $handler)); } \Openclerk\Router::addRoutes(array("admin/:key" => "../pages/admin_:key.php", "help/:key" => "../pages/kb.php?q=:key", ":anything" => "../pages/:anything.php"));
PageRenderer::addTemplatesLocation(__DIR__ . "/../templates"); PageRenderer::addTemplatesLocation(__DIR__ . "/../config/templates"); /** * Include compiled header code, this was a hack to work around * Grunt/build/deploy issues. TODO clean this up and remove this workaround */ function include_head_compiled() { echo "<!-- compiled head -->"; $head_compiled = __DIR__ . "/head-compiled.html"; if (file_exists($head_compiled)) { require $head_compiled; } else { // fix relative paths $input = file_get_contents(__DIR__ . "/../layout/head.html"); $input = str_replace("src=\"", "src=\"" . htmlspecialchars(calculate_relative_path()), $input); echo $input; } echo "<!-- /compiled head -->"; } try { \Openclerk\Router::process($path); } catch (\Openclerk\RouterException $e) { header("HTTP/1.0 404 Not Found"); $errors = array(); $errors[] = htmlspecialchars($e->getMessage()); if (is_localhost()) { $errors[] = htmlspecialchars($e->getPrevious()->getMessage()); } require __DIR__ . "/404.php"; }
function absolute_url_for($module, $arguments = array()) { return Config::get('absolute_url') . Router::absoluteUrlFor($module, $arguments); }
function testProcessAbsolute() { $this->assertFalse($this->empty->rendered); Router::process("api/v1/currenciesAbsolute"); $this->assertTrue($this->empty->rendered); }
/** * Tests that {@link Rotuer::urlAdd()} can delete keys with {@code null}. */ function testKeyDeleteAbsolute() { $this->assertEquals("http://openclerk.org/url", Router::urlAdd('http://openclerk.org/url', array('key' => null))); $this->assertEquals("http://openclerk.org/url", Router::urlAdd('http://openclerk.org/url?key=bar', array('key' => null))); }
<?php require __DIR__ . "/../vendor/autoload.php"; require __DIR__ . "/functions.php"; // set up config Openclerk\Config::merge(array("site_name" => "genealogy", "absolute_url" => is_localhost() ? "http://localhost/genealogy/" : "http://example.com/", "display_errors" => is_localhost())); // set up routes \Openclerk\Router::addRoutes(array(":page" => "pages/:page.php")); // set up pages \Pages\PageRenderer::addTemplatesLocation(__DIR__ . "/../site/templates"); \Pages\PageRenderer::addStylesheet(\Openclerk\Router::urlFor("css/default.css")); \Pages\PageRenderer::addJavascript("https://code.jquery.com/jquery-2.1.1.min.js"); \Pages\PageRenderer::addJavascript(\Openclerk\Router::urlFor("js/default.js")); require __DIR__ . "/tree.php";