本文整理汇总了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);
}
示例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);
}
示例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));
}
示例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();
}
示例5: match
public function match(Request $request, $route = false)
{
if ($request->getHostname() == $this->_hostname) {
return parent::match($request, new Route());
}
return false;
}
示例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);
}
示例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;
}
}
示例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();
}
示例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);
}
}
示例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);
}
示例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());
}
示例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
}
示例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);
}
示例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();
示例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']);