function run($options = array()) { $options = options()->merge($options); $request = request(); $response = response(); foreach (routes() as $route) { if ($route->matches($request, $matches)) { route($route); $path = isset($matches['path']) ? $matches['path'] : $request->path; $data = $route->run($path, $matches); if ($data) { $response->write($data); } if ($options->get('flush', true)) { $response->flush(); } return $route; } } return null; }
<?php require_once __DIR__ . '/config.php'; require_once __DIR__ . '/lib/utils.php'; require_once __DIR__ . '/lib/routes.php'; require_once __DIR__ . '/lib/pagination.class.php'; require_once __DIR__ . '/lib/views.php'; $request = isset($_GET['r']) ? $_GET['r'] : '/'; $posts = get_posts(); $title = SITE_NAME; routes($request, $posts);
die; } if ($argv[1] == "--ifconfig") { ifconfig_tests(); exit; } if ($argv[1] == "--bridges") { bridges_build(); exit; } if ($argv[1] == "--parse-tests") { ifconfig_parse($argv[2]); exit; } if ($argv[1] == "--routes") { routes(); exit; } if ($argv[1] == "--routes-del") { routes_del($argv[2]); exit; } if ($argv[1] == "--vlans") { build(); exit; } if ($argv[1] == "--postfix-instances") { postfix_multiples_instances(); exit; } if ($argv[1] == "--ping") {
<?php require_once 'sunfish_core/core.php'; $urls = array('/(.*)' => 'Event', '/event/read/(\\d+)' => 'Read', '/event/hello/(\\w+)/(\\d+)/(\\w+)' => 'Hello'); routes($urls); class Event { public function GET() { echo "Hello from Events controller!"; } } class Read { public function GET($id) { echo "reading at id : {$id}"; } } class Hello { public function GET($word, $id, $phrase) { echo "Sprocket Fish {$word} {$id} {$phrase}"; } }
function routes_main_build() { routes(); routes_main(); $unix = new unix(); $route = $unix->find_program("route"); $ip = $unix->find_program("ip"); if (count($GLOBALS["SCRIPTS"]) == 0) { echo "No route to build\n"; return; } while (list($index, $line) = each($GLOBALS["SCRIPTS"])) { $line = trim($line); if ($line == null) { continue; } $md = md5($line); if (isset($AL[$md])) { continue; } $AL[$md] = true; echo "Starting......: " . date("H:i:s") . " `{$line}`\n"; system($line); } }
function dispatch() { $argv = func_get_args(); $path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); $method = \request\method(); $pattern = null; $func = null; $vals = null; // getting all maps $maps = (array) routes()->any; if (isset(routes()->{$method})) { $maps = array_merge((array) routes()->{$method}, $maps); } // iterate over all maps foreach ($maps as $temp) { list($pattern, $callback) = $temp; $pattern = trim($pattern, '/'); $pattern = preg_replace(['@<([^:]+)>@U', '@<([^:]+)(:(.+))?>@U'], ['<$1:[^/]+>', '(?<$1>$3)'], $pattern); // match current path with any maps callback if (preg_match('@^' . $pattern . '$@', $path, $vals)) { $func = $callback; break; } } // valid handler, try to parse out route symbol values if ($func && is_callable($func)) { array_shift($vals); // remove top group from vals // extract route symbols and run the hook()s if ($vals) { // extract any route symbol values $toks = array_filter(array_keys($vals), 'is_string'); $vals = array_map('urldecode', array_intersect_key($vals, array_flip($toks))); array_unshift($argv, $vals); } } else { if (is_callable(routes()->all)) { $argv = array_merge(['method' => $method, 'path' => $path], $argv); return call_user_func_array(routes()->all, $argv); } else { $func = '\\route\\error'; array_unshift($argv, 404); } } return call_user_func_array($func, $argv); }
function yield_to_glue() { map_request_to_handler(request_(), routes()); }
<?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * urls.php * * PHP version 5 * * @category Router * @package Core * @subpackage Core_Router * @author Julien Jouvent-Halle <*****@*****.**> * @license http://www.opensource.org/licenses/mit-license.php MIT License * @link http://github.com/jouvent/Genitura * @since 0.0.2 */ /** * $urls is an array of Route object * - patern (any regexp patern that will be run against the query_string) * - location ( on the form <file_path>::<function_name>, both have to be valid) * - params (any key/value pairs that will be passed to the controler function) */ $urls = array(route('^$', 'flatpages::page', array('page' => 'home')), route('^about$', 'flatpages::page', array('page' => 'about')), route('^login$', 'auth::login_user', array()), route('^logout$', 'auth::logout_user', array()), route('^lang', routes('apps/lang/urls.php')), route('^settings$', 'cms::actions', array()), route('^faq[/]?', routes('apps/cms/urls.php', 'faq_routes')), route('^page/add$', 'cms::page_add', array()), route('^page/list$', 'cms::page_list', array()), route('^page/edit/(?<slug>\\w+)$', 'cms::page_edit', array()), route('^(?<slug>\\w+)$', 'cms::page', array()));
function any($pattern, $options) { $route = new Route($pattern, $options); array_push(routes(), $route); return $route; }
function route_($method, $paths, $funcs, $conditions) { routes(array('method' => $method, 'paths' => $paths, 'funcs' => $funcs, 'conds' => $conditions)); }
<?php include_once(dirname(__FILE__) . '/ressources/class.ldap.inc'); include_once(dirname(__FILE__) . '/ressources/class.templates.inc'); include_once(dirname(__FILE__) . '/framework/class.unix.inc'); include_once(dirname(__FILE__) . '/framework/frame.class.inc'); include_once(dirname(__FILE__) . '/ressources/class.system.network.inc'); include_once(dirname(__FILE__) . '/ressources/class.system.nics.inc'); if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");} if(preg_match("#--verbose#",implode(" ",$argv))){$GLOBALS["VERBOSE"]=true;ini_set_verbosed();} if($argv[1]=="--interfaces"){interfaces_show();die();} if($argv[1]=="--just-add"){routes();die();} if($argv[1]=="--ifconfig"){ifconfig_tests();exit;} if($argv[1]=="--bridges"){bridges_build();exit;} if($argv[1]=="--parse-tests"){ifconfig_parse($argv[2]);exit;} if($argv[1]=="--routes"){routes();exit;} if($argv[1]=="--routes-del"){routes_del($argv[2]);exit;} if($argv[1]=="--vlans"){build();exit;} if($argv[1]=="--postfix-instances"){postfix_multiples_instances();exit;} if($argv[1]=="--ping"){ping($argv[2]);exit;} if($argv[1]=="--ipv6"){Checkipv6();exit;} build(); // //vconfig set_flag eth1.3 1 1 //vconfig set_flag eth1.4 1 1
public function testWrapper() { $this->assertTrue(is_a(routes($this->pwd . '/urls.php'), 'RouteLoader')); }
<?php use Thorazine\Cms\Helpers\Settings; // cms config $config = config('cms'); // patterns Route::pattern('id', '[0-9]+'); Route::pattern('lang', implode('|', $config ? $config['supported_languages'][$config['prefix']] : [])); ##### WITH LANGUAGE IN URL ##### Route::group(['prefix' => '{lang}', 'middleware' => 'cms.language'], function () use($config) { routes($config); }); ##### NO LANGUAGE IN URL ##### routes($config); function routes($config) { // only mess with the cms Route::group(['prefix' => $config['cms_path'], 'middleware' => ['cms.language', 'cms.view']], function () use($config) { Route::group(['namespace' => '\\Thorazine\\Cms\\Http\\Controllers'], function () use($config) { // pickup on first contact Route::get('/', ['as' => 'cms.auth.first', 'uses' => 'AuthController@first']); Route::post('/', ['as' => 'cms.auth.first.create', 'uses' => 'AuthController@create']); // auth Route::post('/login/submit', ['as' => 'cms.auth.check', 'before' => 'csrf', 'uses' => 'AuthController@check']); Route::get('/login', ['as' => 'cms.auth.login', 'uses' => 'AuthController@index']); // All routes that do require auth Route::group(['middleware' => ['cms.auth']], function () use($config) { // logout Route::get('/logout', ['as' => 'cms.auth.logout', 'uses' => 'AuthController@destroy']); // cms home Route::get('/base', ['as' => 'cms.base', 'uses' => 'CmsController@index']);