当前位置: 首页>>代码示例>>PHP>>正文


PHP Router::match方法代码示例

本文整理汇总了PHP中Router::match方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::match方法的具体用法?PHP Router::match怎么用?PHP Router::match使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Router的用法示例。


在下文中一共展示了Router::match方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testMatchTraversesAllRegisteredRoutesIfFalseIsReturned

 public function testMatchTraversesAllRegisteredRoutesIfFalseIsReturned()
 {
     $Request = $this->createRequest('');
     $PersonRoute = $this->mock('AkRoute', array('parametrize' => new RouteDoesNotMatchRequestException()));
     $AuthorRoute = $this->mock('AkRoute', array('parametrize' => true));
     $this->Router->addRoute('person', $PersonRoute);
     $this->Router->addRoute('author', $AuthorRoute);
     $this->Router->match($Request);
     $this->assertEqual($AuthorRoute, $this->Router->currentRoute);
 }
开发者ID:bermi,项目名称:akelos,代码行数:10,代码来源:router.php

示例2: array

 function testMatchTraversesAllRegisteredRoutesIfFalseIsReturned()
 {
     $Request = $this->getMock('AkRequest', array(), array(), '', false);
     $PersonRoute = $this->getMock('AkRoute', array(), array('person/:name'));
     $PersonRoute->expects($this->once())->method('parametrize')->with($Request)->will($this->throwException(new RouteDoesNotMatchRequestException()));
     $AuthorRoute = $this->getMock('AkRoute', array(), array('author/:name'));
     $AuthorRoute->expects($this->once())->method('parametrize')->with($Request)->will($this->returnValue(true));
     $this->Router->addRoute('person', $PersonRoute);
     $this->Router->addRoute('author', $AuthorRoute);
     $this->Router->match($Request);
     $this->assertEquals($AuthorRoute, $this->Router->currentRoute);
 }
开发者ID:joeymetal,项目名称:v1,代码行数:12,代码来源:RouterTest.php

示例3: testMatchFail

 /**
  * @covers Zepto\Router::match()
  */
 public function testMatchFail()
 {
     $this->router->get('/notget', function () {
         return 'This is not a get route';
     });
     $this->assertNull($this->router->match('/get/', Router::METHOD_GET));
 }
开发者ID:hassankhan,项目名称:sonic,代码行数:10,代码来源:RouterTest.php

示例4: run

 public function run()
 {
     $route = $this->router->match($this->request);
     if ($route === false) {
         $actionName = self::ACTION_NOT_FOUND;
     } else {
         $actionName = $route->getName();
     }
     if (!$this->actions->has($actionName)) {
         throw new \Exception(sprintf('Action %s not found', $actionName));
     }
     $this->store->setFileName($actionName);
     if ($this->request->isAjax()) {
         $this->view->setRenderType(View::RENDER_JSON);
     } else {
         $this->view->setContentView('error');
     }
     $action = $this->actions->get($actionName);
     call_user_func_array($action, array($this));
     if (is_callable($this->postAction)) {
         call_user_func_array($this->postAction, array($this));
     }
     $this->response->setContent($this->view->render());
     $this->response->send();
 }
开发者ID:Acidburn0zzz,项目名称:devtools-1,代码行数:25,代码来源:Application.php

示例5: match

 public function match(Request $request, $route = false)
 {
     if ($request->getHostname() == $this->_hostname) {
         return parent::match($request, new Route());
     }
     return false;
 }
开发者ID:elvis2,项目名称:simple-mvc,代码行数:7,代码来源:HostnameRouter.php

示例6: testMatchMethod

 public function testMatchMethod()
 {
     $this->object->add(new \PHPixie\Route('get', '/url', array('controller' => 'home', 'action' => 'get'), 'GeT'));
     $this->object->add(new \PHPixie\Route('post', '/url', array('controller' => 'home', 'action' => 'get'), array('PosT')));
     $route = $this->object->match('/url', 'GEt');
     $this->assertEquals('get', $route['route']->name);
     $route = $this->object->match('/url', 'POST');
     $this->assertEquals('post', $route['route']->name);
 }
开发者ID:PermeAgility,项目名称:FrameworkBenchmarks,代码行数:9,代码来源:routerTest.php

示例7: match_route

 /**
  * Returns the matched route
  * @return mixed The matched route or false if none matched
  */
 private function match_route()
 {
     $match = $this->router->match();
     if ($match) {
         $route = $this->routes[$match['name']];
         $route['parameters'] = $match['params'];
         $this->current_route = $route;
         return $route;
     }
 }
开发者ID:Anunatak,项目名称:framework,代码行数:14,代码来源:FrontEnd.php

示例8: run

 /**
  * Dispatches a HTTP request to a front controller.
  * Sends response to output.
  *
  * @return void
  */
 public function run()
 {
     $request = $this->createRequest();
     $applicationRequestInformation = $this->router->match($request);
     $controllerName = $this->formatControllerName($applicationRequestInformation['controller']);
     $methodName = $this->formatMethodName($applicationRequestInformation['method']);
     $templateFileName = $this->formatTemplateFileName($applicationRequestInformation['controller'], $applicationRequestInformation['method']);
     require_once $this->controllersDir . $controllerName . '.php';
     $response = new Response();
     $template = new Template($this->templatesDir . $templateFileName);
     /** @var Controller $controller */
     $controller = new $controllerName($template, $response);
     if (method_exists($controller, $methodName)) {
         call_user_func_array(array($controller, $methodName), $applicationRequestInformation['parameters']);
     }
     $response = $controller->getResponse();
     $response->setOutput($controller->getTemplate()->render());
     $response->send();
 }
开发者ID:JanPetr,项目名称:AlgoliaTestAppStore,代码行数:25,代码来源:Application.php

示例9: match

 public function match(Request $request, $route = false)
 {
     if ($request->getUri() == $this->_path) {
         $static = new Route();
         $static->setControllerName($this->_controller);
         $static->setActionName($this->_action);
         $static->merge($route);
         return parent::match($request, $static);
     }
 }
开发者ID:elvis2,项目名称:simple-mvc,代码行数:10,代码来源:StaticRouter.php

示例10: testAlias

 public function testAlias()
 {
     Router::alias('/', 'home.html');
     $result = Router::match('/');
     $this->assertTrue($result instanceof Route);
     $this->assertEquals('home.html', $result->url);
     $this->assertEquals([], $result->parameters);
     $this->assertTrue(is_callable($result->callback));
     $result = ($result->callback)(new Request());
     $this->assertTrue($result instanceof Page);
 }
开发者ID:alkemann,项目名称:h2l,代码行数:11,代码来源:RouterTest.php

示例11: testChain

 public function testChain()
 {
     $request = new Request();
     $request->setHostname("t.test.local");
     $request->setUri("/");
     $router = new Router();
     $hostnameRouter = new HostnameRouter("t.test.local");
     $hostnameRouter->addChild("hello", new StaticRouter("/", "Hello", "world"));
     $router->addChild("hostname", $hostnameRouter);
     $route = $router->match($request);
     $this->assertEquals("Hello", $route->getControllerName());
 }
开发者ID:elvis2,项目名称:simple-mvc,代码行数:12,代码来源:RouterTest.php

示例12: handleHttpRequest

 /**
  * Get and handle HTTP request
  *
  * @param void
  * @return null
  */
 function handleHttpRequest()
 {
     $request = $this->router->match(ANGIE_PATH_INFO, ANGIE_QUERY_STRING);
     if (is_error($request)) {
         handle_fatal_error($request);
     } else {
         $execute =& execute_action($request);
         if (is_error($execute)) {
             handle_fatal_error($execute);
         }
         // if
     }
     // if
 }
开发者ID:NaszvadiG,项目名称:activecollab_loc,代码行数:20,代码来源:AngieApplication.class.php

示例13: __construct

 /**
  * Analyze request, provided $_REQUESt, $_SERVER [, $_GET, $_POST] and identifu Route
  *
  * Response type can be set from HTTP_ACCEPT header. the Route object will be set by a call
  * to Router::match
  *
  * @param array $request $_REQUEST
  * @param array $server $_SERVER
  * @param array $get $_GET
  * @param array $post $_POST
  */
 public function __construct(array $request = [], array $server = [], array $get = [], array $post = [])
 {
     $this->_request = $request;
     $this->_server = $server;
     $this->_post = $post;
     $this->_get = $get;
     unset($this->_get['url']);
     $this->_parameters = [];
     // override html type with json
     $httaccept = $this->_server['HTTP_ACCEPT'] ?? '*/*';
     if ($httaccept !== '*/*' && strpos($this->_server['HTTP_ACCEPT'], 'application/json') !== false) {
         $this->_type = 'json';
     }
     $this->_url = $this->_request['url'] ?? '/';
     $this->_method = $this->_server['REQUEST_METHOD'] ?? Request::GET;
     $this->_route = Router::match($this->_url, $this->_method);
 }
开发者ID:alkemann,项目名称:h2l,代码行数:28,代码来源:Request.php

示例14: Router

<?php

require_once 'init.php';
$router = new Router();
$router->map('GET', '', function () {
    loadSmarty();
    show_page('index', 'Home');
});
$router->map('GET', '/news/:id', function ($id) {
    return Adapter::invokeAdapter('News', 'obtaionNews', array('id' => $id));
});
$router->map('GET', '/news/', function () {
    return Adapter::invokeAdapter('News', 'obtaionNews');
});
$router->map('POST', '/news/:id', function ($id) {
    return Adapter::invokeAdapter('News', 'editNews', array('id' => $id));
});
$router->map('POST', '/news/', function () {
    return Adapter::invokeAdapter('News', 'addNews');
});
$router->map('DELETE', '/news/:id', function ($id) {
    return Adapter::invokeAdapter('News', 'deleteNews', array('id' => $id));
});
$router->map('GET', '/users/:userId/', function ($userId) {
    return Adapter::invokeAdapter('Users', 'getUser', array('userId' => $userId));
});
$router->map('GET', '/users/:userId/comments/[:commentId]', function ($userId, $commentId = 0) {
    return Adapter::invokeAdapter('Users', 'getUserComments', array('userId' => $userId, 'commentId' => $commentId));
});
echo $router->match();
开发者ID:veselinDoynov,项目名称:RestApi,代码行数:30,代码来源:app.php

示例15: array

    $router->map('/groups/i:objectGroupID/:scopeObject/:scopeObjectKey/items/top', array('controller' => 'Items', 'extra' => array('subset' => 'top')));
    // Items within something else
    $router->map('/users/i:objectUserID/:scopeObject/:scopeObjectKey/items/:objectKey/:subset', array('controller' => 'Items'));
    $router->map('/groups/i:objectGroupID/:scopeObject/:scopeObjectKey/items/:objectKey/:subset', array('controller' => 'Items'));
    // User API keys
    $router->map('/keys/:objectName', array('controller' => 'Keys'));
    $router->map('/users/i:objectUserID/keys/:objectName', array('controller' => 'Keys'));
    // User/library settings
    $router->map('/users/i:objectUserID/publications/settings/:objectKey', ['controller' => 'settings', 'extra' => ['publications' => true]]);
    $router->map('/users/i:objectUserID/settings/:objectKey', array('controller' => 'settings'));
    $router->map('/groups/i:objectGroupID/settings/:objectKey', array('controller' => 'settings'));
    // Clear (for testing)
    $router->map('/users/i:objectUserID/clear', array('controller' => 'Api', 'action' => 'clear'));
    $router->map('/users/i:objectUserID/publications/clear', ['controller' => 'Api', 'action' => 'clear', 'extra' => ['publications' => true]]);
    $router->map('/groups/i:objectGroupID/clear', array('controller' => 'Api', 'action' => 'clear'));
    // Other top-level URLs, with an optional key and subset
    $router->map('/users/i:objectUserID/publications/items/:objectKey/:subset', ['controller' => 'Items', 'extra' => ['publications' => true]]);
    // Just items for now
    $router->map('/users/i:objectUserID/publications/deleted', ['controller' => 'Deleted', 'extra' => ['publications' => true]]);
    $router->map('/users/i:objectUserID/:controller/:objectKey/:subset');
    $router->map('/groups/i:objectGroupID/:controller/:objectKey/:subset');
    $router->map('/itemTypes', array('controller' => 'Mappings', 'extra' => array('subset' => 'itemTypes')));
    $router->map('/itemTypeFields', array('controller' => 'Mappings', 'extra' => array('subset' => 'itemTypeFields')));
    $router->map('/itemFields', array('controller' => 'Mappings', 'extra' => array('subset' => 'itemFields')));
    $router->map('/itemTypeCreatorTypes', array('controller' => 'Mappings', 'extra' => array('subset' => 'itemTypeCreatorTypes')));
    $router->map('/creatorFields', array('controller' => 'Mappings', 'extra' => array('subset' => 'creatorFields')));
    $router->map('/items/new', array('controller' => 'Mappings', 'action' => 'newItem'));
    $router->map('/test/setup', array('controller' => 'Api', 'action' => 'testSetup'));
}
return $router->match($_SERVER['REQUEST_URI']);
开发者ID:selenus,项目名称:dataserver,代码行数:30,代码来源:routes.inc.php


注:本文中的Router::match方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。