Example #1
0
 public function testMatchingCheckesHost()
 {
     $this->setExpectedException('Vexillum\\Http\\PageNotFoundException');
     $route = Router::get('/apath', function () {
     }, array('host' => 'localyacht.dev'));
     Router::run('GET', 'localboat.dev', '/apath');
 }
Example #2
0
 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'));
     }
 }
Example #3
0
 public static function run()
 {
     Connection::connect();
     Session::start();
     Router::run();
     Connection::disconnect();
 }
Example #4
0
 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;
 }
Example #5
0
 public function run()
 {
     // 添加router的配置处理
     if ($routerRules = $this->get('routers')) {
         Router::set($routerRules);
     }
     Router::run();
 }
Example #6
0
 /**
  * @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());
 }
 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");
     }
 }
Example #8
0
 /**
  * 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();
                 }
             }
         }
     }
 }
Example #9
0
File: App.php Project: pagon/core
 /**
  * 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();
             }
         }
     }
 }
Example #10
0
 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;
 }
Example #11
0
<?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      ========================//
Example #12
0
<?php

/**
 * Builder Plugin
 *
 * @author Tim Ötting <*****@*****.**>
 * @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
Example #13
0
{
    $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();
Example #14
0
<?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();
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)) {
Example #16
0
 /**
  * run
  *
  * Run application
  *
  * @return null
  */
 public static function run()
 {
     Request::init();
     if (self::getConfig('main')->system->session_handler == 'database') {
         Storage::setDatabaseHandler();
     }
     Storage::init();
     Member::init();
     Router::run();
 }
Example #17
0
<?php

// Front 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. Вызов Router
$router = new Router();
echo $router->run();
<?php

require_once 'route.php';
$route_config = array('home' => 'Home', 'logout' => 'Logout');
$route = new Router($route_config);
$route->run();
Example #19
0
<?php

require_once '../autoloader.php';
require_once '../app/config/config.php';
require_once '../vendor/autoload.php';
$uri = $_SERVER['REQUEST_URI'];
$dir = __DIR__;
$path = substr($dir, strlen($_SERVER['DOCUMENT_ROOT']) - 1);
$url = substr($uri, strlen($path));
$route = substr($url, strlen("index.php"));
$router = new Router();
$response = $router->run($route);
foreach (getallheaders() as $name => $value) {
    $file = __DIR__ . "/../app/logs/access.log";
    if (!file_exists($file)) {
        file_put_contents($file, "LOGS ACCESS: \n");
    }
    file_put_contents($file, date("\\[d/m/y H:i:s\\]") . " : " . "{$name}: {$value}" . " \n", FILE_APPEND);
}
Example #20
0
 public function run()
 {
     //Objects
     $session = $this->_session;
     $message = new Message($session->getKhex());
     $db = new Database();
     $auth = new Authentication($db, $this->_username, $this->_A, $this->_M1);
     //Http cleaned infos
     $URI = $this->_URI;
     // Inputs
     $rawInput = $this->_rawInput;
     $sig = $this->_sig;
     $method = $this->_method;
     //Start the router
     $router = new Router();
     // Check if logged function
     $authCheck = function () use($session) {
         if (!$session->isLogged()) {
             header('HTTP/1.1 403 Forbidden');
             print 'Not logged';
             exit;
         }
     };
     // Autoload routes
     if ($dir = opendir(__ROOT__ . 'php/routes')) {
         while (false !== ($route = readdir($dir))) {
             if ($route != "." && $route != "..") {
                 include_once __ROOT__ . 'php/routes/' . $route;
             }
         }
         closedir($dir);
     }
     //Run the router
     $router->run($this->_method, $this->_URI);
 }
Example #21
0
<?php

//front controller
ini_set('display_errors', 1);
error_reporting(E_ALL);
define("ROOT", dirname(__FILE__));
require_once ROOT . '/classes/Autoload.php';
require_once ROOT . '/DB/DBConnector.php';
require_once ROOT . '/classes/Router.php';
require_once ROOT . '/Session/Session.php';
Session::init();
$router = new Router();
$router->run();
<?php

session_start();
//FRONT CONTROLLER
//general settings
ini_set('display_errors', 0);
error_reporting(E_ALL);
//files connection
define("ROOT", dirname(__FILE__));
require_once ROOT . '/components/Router.php';
//database connection
require_once ROOT . '/components/dbConection.php';
//launch Rourer
$obj = new Router();
$obj->run();