本文整理汇总了PHP中Router::run方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::run方法的具体用法?PHP Router::run怎么用?PHP Router::run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMatchingCheckesHost
public function testMatchingCheckesHost()
{
$this->setExpectedException('Vexillum\\Http\\PageNotFoundException');
$route = Router::get('/apath', function () {
}, array('host' => 'localyacht.dev'));
Router::run('GET', 'localboat.dev', '/apath');
}
示例2: route
public function route($model, $form, $fieldName, $fieldType, $path)
{
$field = $form->fields()->{$fieldName};
if (!$field or $field->type() !== $fieldType) {
throw new Exception('Invalid field');
}
$routes = $field->routes();
$router = new Router($routes);
if ($route = $router->run($path)) {
if (is_callable($route->action()) and is_a($route->action(), 'Closure')) {
return call($route->action(), $route->arguments());
} else {
$controllerFile = $field->root() . DS . 'controller.php';
$controllerName = $fieldType . 'FieldController';
if (!file_exists($controllerFile)) {
throw new Exception(l('fields.error.missing.controller'));
}
require_once $controllerFile;
if (!class_exists($controllerName)) {
throw new Exception(l('fields.error.missing.class'));
}
$controller = new $controllerName($model, $field);
return call(array($controller, $route->action()), $route->arguments());
}
} else {
throw new Exception(l('fields.error.route.invalid'));
}
}
示例3: run
public static function run()
{
Connection::connect();
Session::start();
Router::run();
Connection::disconnect();
}
示例4: request
public function request()
{
$request = Router::run();
$matches = [];
foreach ($request['matches'] as $k => $v) {
if (is_int($k)) {
continue;
}
$matches[$k] = $v;
}
unset($request['matches'], $request['pattern']);
$request = array_merge($request, $matches);
foreach ($request as $k => $v) {
$request[$k] = $v;
}
$request['action'] = isset($request['action']) && !empty($request['action']) ? $request['action'] : 'index';
// set default action
if (!empty($_REQUEST)) {
$request['params'] = $_REQUEST;
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
// check if ajax call
$request['ajax'] = true;
}
return $request;
}
示例5: run
public function run()
{
// 添加router的配置处理
if ($routerRules = $this->get('routers')) {
Router::set($routerRules);
}
Router::run();
}
示例6: testRunWithError
/**
* @covers Zepto\Router::run()
* @covers Zepto\Router::match()
* @covers Zepto\Router::error()
*/
public function testRunWithError()
{
$_SERVER['REQUEST_URL'] = '/zepto/failure';
$_SERVER['REQUEST_URI'] = '/zepto/failure';
$this->mock_request->expects($this->any())->method('getPathInfo')->will($this->returnValue('/failure'));
$this->router->get('/failure', function () {
throw new \Exception('Proving another point');
});
$this->assertFalse($this->router->run());
$this->assertEquals(500, $this->router->current_http_status());
}
示例7: call_action
private function call_action($uri, $method)
{
global $map;
$map = new Router($uri);
include 'config/routes.php';
try {
$this->controller = $map->run($method);
} catch (RedirectException $ex) {
$this->handle_redirect_exception($ex);
}
if (count($this->expected_redirects) > 0) {
$this->fail("Didn't redirect as expected");
}
}
示例8: handleError
/**
* Register or run error
*
* @param string $type
* @param callable $route
* @throws \InvalidArgumentException
* @throws \Exception
*/
public function handleError($type, $route = null)
{
if (!isset($this->injectors['errors'][$type])) {
throw new \InvalidArgumentException('Unknown error type "' . $type . '" to call');
}
if (is_string($route) && class_exists($route) || $route instanceof \Closure) {
// Set error handle
$this->injectors['errors'][$type][2] = $route;
} else {
if (!$this->injectors['exception'] && $route instanceof \Exception) {
// Not handle exception and throw it
throw $route;
} else {
// Clean the output buffer
ob_get_level() && ob_clean();
// Check handle route and run it
if (empty($this->injectors['errors'][$type][2]) || !$this->router->run($this->injectors['errors'][$type][2], array('error' => array('type' => $type, 'error' => $route, 'message' => $this->injectors['errors'][$type])))) {
/**
* Get error information
*/
$error = $route instanceof \Exception ? $route : null;
$title = $error ? $error->getMessage() : $this->injectors['errors'][$type][1];
$code = $this->injectors['errors'][$type][0];
$message = $route ? $error ? $error->getFile() . ' [' . $error->getLine() . ']' : (string) $route : '';
if ($this->injectors['cli']) {
// Cli error show
$this->halt($code, Console::text('[' . $title . '] ' . ($message ? $message : '"' . $this->input->path() . '"') . ' ', 'redbg') . "\n" . ($this->injectors['debug'] && $error ? Console::text("\n[Error]\n", "yellow") . $error . "\n" : ''));
} else {
// Http error show
$this->output->status($this->injectors['errors'][$type][0]);
if ($this->injectors['debug']) {
// Debug error show
$this->renderView('Error', array('title' => $title, 'message' => $message ? $message : 'Could not ' . $this->input->method() . ' ' . $this->input->path(), 'stacks' => $this->injectors['debug'] && $error ? $error->getTraceAsString() : null));
} else {
// Normal error show
$this->renderView('Error', array('title' => $title, 'message' => $message ? $message : 'Could not ' . $this->input->method() . ' ' . $this->input->path()));
}
$this->stop();
}
}
}
}
}
示例9: handleError
/**
* Register or run error
*
* @param string $type
* @param callable $route
* @throws \InvalidArgumentException
*/
public function handleError($type, $route = null)
{
if (!isset($this->injectors['errors'][$type])) {
throw new \InvalidArgumentException('Unknown error type "' . $type . '" to call');
}
if (is_string($route) && is_subclass_of($route, Route::_CLASS_, true) || $route instanceof \Closure) {
$this->injectors['errors'][$type][2] = $route;
} else {
ob_get_level() && ob_clean();
ob_start();
if (empty($this->injectors['errors'][$type][2]) || !$this->router->run($this->injectors['errors'][$type][2], array('error' => array('type' => $type, 'error' => $route, 'message' => $this->injectors['errors'][$type])))) {
if ($this->injectors['cli']) {
$this->halt($this->injectors['errors'][$type][0], $this->injectors['errors'][$type][1]);
} else {
$this->output->status($this->injectors['errors'][$type][0]);
$this->render('pagon/views/error.php', array('title' => $this->injectors['errors'][$type][1], 'message' => $route ? $route instanceof \Exception ? $route->getMessage() : (string) $route : 'Could not ' . $this->input->method() . ' ' . $this->input->path()));
$this->stop();
}
}
}
}
示例10: response
public function response()
{
// this will trigger the configuration
$site = $this->site();
$router = new Router($this->routes());
$route = $router->run($this->path());
// check for a valid route
if (is_null($route)) {
header::status('500');
header::type('json');
die(json_encode(array('status' => 'error', 'message' => 'Invalid route or request method')));
}
$response = call($route->action(), $route->arguments());
if (is_string($response)) {
$this->response = static::render(page($response));
} else {
if (is_array($response)) {
$this->response = static::render(page($response[0]), $response[1]);
} else {
if (is_a($response, 'Response')) {
$this->response = $response;
} else {
if (is_a($response, 'Page')) {
$this->response = static::render($response);
} else {
$this->response = null;
}
}
}
}
return $this->response;
}
示例11: exit
<?php
if (!defined('__ROOT__')) {
exit('Sorry,Please from entry!');
}
/**
* init 入口引入文件
* 项目自动初始化文件
* 创建时间:2014-08-08 14:56 PGF
*/
Loader::core('Debug');
//加载DEBUG类
Debug::start();
//程序开始
Loader::func('Base');
//加载基础全局函数
Loader::core('Cache');
//加载缓存处理类
Cache::init();
//初始化缓存类
//向日志中添加已经加载的Loader
Debug::add(__ROOT__ . Config::config('core_dir') . '/bases/' . 'Loader.class.php', 1);
Loader::core('Router');
//加载Router
Router::run();
//Router运行
Debug::stop();
//程序结束
//==================== END Initialize.php ========================//
示例12: builderForm
<?php
/**
* Builder Plugin
*
* @author Tim Ötting <email@tim-oetting.de>
* @version 0.9
*/
$router = new Router(array(array('pattern' => 'views/editor/builder2/(:all)/(:any)/(:any)/(:any)', 'action' => 'builderForm', 'filter' => 'auth', 'method' => 'POST|GET', 'modal' => true)));
if ($route = $router->run()) {
call($route->action(), $route->arguments());
exit;
}
function builderForm($id, $fieldName, $fieldsetName, $context)
{
$kirby = kirby();
$kirby->extensions();
$kirby->plugins();
$root = $kirby->roots->index . DS . 'panel';
$panel = new Panel($kirby, $root);
$panel->i18n();
$roots = new Panel\Roots($panel, $root);
$site = $kirby->site();
$page = empty($id) ? site() : page($id);
if (!$page) {
throw new Exception('The page could not be found');
}
$blueprint = blueprint::find($page);
$field = null;
$fields = $context == 'file' ? $blueprint->files()->fields() : $blueprint->fields();
// make sure to get fields by case insensitive field names
示例13: array
{
$flash = $_SESSION['flash'];
if (!$init_only) {
session_destroy();
session_start();
}
if (!array_key_exists('flash', $_SESSION)) {
$_SESSION['flash'] = is_array($flash) ? $flash : array();
}
}
session_restart(true);
// Helpers
require_once 'lib/system/helpers.php';
require_once 'lib/system/html_helpers.php';
if (file_exists(MODULES_PATH . 'main/application/application_helpers.php')) {
include MODULES_PATH . 'main/application/application_helpers.php';
}
// Models
require_once 'lib/system/model.php';
// Controllers
require_once 'lib/system/controller.php';
if (!file_exists(MODULES_PATH . 'main/application/application_controller.php')) {
error();
}
include MODULES_PATH . 'main/application/application_controller.php';
// Router
require_once 'lib/system/router.php';
$map = new Router($_GET['uri']);
include 'config/routes.php';
$map->run();
示例14: dirname
<?php
//Frong Controller
//1. Общие настройки**************
ini_set('display_errors', 1);
error_reporting(E_ALL);
session_start();
//2. Подключение файлов системы**************
define('ROOT', dirname(__FILE__));
require_once ROOT . '/components/Autoload.php';
//3. Подключение к Базе Данных
//4. Вызов Router
$rou = new Router();
$rou->run();
示例15: __construct
header('Access-Control-Allow-Origin: *');
$_identifier = '[\\w\\d_-\\s]+';
$_number = '\\d+';
$r = new Router();
$r->map("", array("controller" => "serverinfo", "action" => "hello"));
$r->map("root.xml", array("controller" => "TileMapService", "action" => "root"));
$r->map("1.0.0", array("controller" => "TileMapService", "action" => "service"));
$r->map("1.0.0/:layer", array("controller" => "TileMapService", "action" => "resource"), array("layer" => $_identifier));
$r->map("1.0.0/:layer/:z/:x/:y.:ext", array("controller" => "maptile", "action" => "serveTmsTile"), array("layer" => $_identifier, "x" => $_number, "y" => $_number, "z" => $_number, "ext" => "(png|jpg|jpeg|json)"));
$r->map(":layer/:z/:x/:y.:ext", array("controller" => "maptile", "action" => "serveTile"), array("layer" => $_identifier, "x" => $_number, "y" => $_number, "z" => $_number, "ext" => "(png|jpg|jpeg|json)"));
$r->map(":layer/:z/:x/:y.:ext\\?:argument=:callback", array("controller" => "maptile", "action" => "serveTile"), array("layer" => $_identifier, "x" => $_number, "y" => $_number, "z" => $_number, "ext" => "(json|jsonp)", "argument" => $_identifier, "callback" => $_identifier));
$r->map(":layer/:z/:x/:y.grid.:ext", array("controller" => "maptile", "action" => "serveTile"), array("layer" => $_identifier, "x" => $_number, "y" => $_number, "z" => $_number, "ext" => "(json|jsonp)", "argument" => $_identifier, "callback" => $_identifier));
$r->map(":layer/:z/:x/:y.grid.:ext\\?:argument=:callback", array("controller" => "maptile", "action" => "serveTile"), array("layer" => $_identifier, "x" => $_number, "y" => $_number, "z" => $_number, "ext" => "(json|jsonp)", "argument" => $_identifier, "callback" => $_identifier));
$r->map(":layer.tilejson", array("controller" => "maptile", "action" => "tilejson"), array("layer" => $_identifier));
$r->map(":layer.tilejsonp\\?:argument=:callback", array("controller" => "maptile", "action" => "tilejson"), array("layer" => $_identifier, "argument" => $_identifier, "callback" => $_identifier));
$r->run();
class BaseClass
{
protected $layer;
protected $db;
public function __construct()
{
}
protected function getMBTilesName()
{
return $this->layer . ".mbtiles";
}
protected function openDB()
{
$filename = $this->getMBTilesName();
if (file_exists($filename)) {