本文整理汇总了PHP中Zend\Mvc\Router\Http\TreeRouteStack::addRoute方法的典型用法代码示例。如果您正苦于以下问题:PHP TreeRouteStack::addRoute方法的具体用法?PHP TreeRouteStack::addRoute怎么用?PHP TreeRouteStack::addRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\Router\Http\TreeRouteStack
的用法示例。
在下文中一共展示了TreeRouteStack::addRoute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addRoute
/**
* @param Route $route
*/
public function addRoute(Route $route)
{
$name = $route->getName();
$path = $route->getPath();
$options = $route->getOptions();
$options = array_replace_recursive($options, ['route' => $path, 'defaults' => ['middleware' => $route->getMiddleware()]]);
$allowedMethods = $route->getAllowedMethods();
if (Route::HTTP_METHOD_ANY === $allowedMethods) {
$this->zf2Router->addRoute($name, ['type' => 'segment', 'options' => $options]);
$this->routeNameMap[$name] = $name;
return;
}
// Remove the middleware from the segment route in favor of method route
unset($options['defaults']['middleware']);
if (empty($options['defaults'])) {
unset($options['defaults']);
}
$httpMethodRouteName = implode(':', $allowedMethods);
$httpMethodRoute = $this->createHttpMethodRoute($route);
$methodNotAllowedRoute = $this->createMethodNotAllowedRoute($path);
$spec = ['type' => 'segment', 'options' => $options, 'may_terminate' => false, 'child_routes' => [$httpMethodRouteName => $httpMethodRoute, self::METHOD_NOT_ALLOWED_ROUTE => $methodNotAllowedRoute]];
if (array_key_exists($path, $this->allowedMethodsByPath)) {
$allowedMethods = array_merge($this->allowedMethodsByPath[$path], $allowedMethods);
// Remove the method not allowed route as it is already present for the path
unset($spec['child_routes'][self::METHOD_NOT_ALLOWED_ROUTE]);
}
$this->zf2Router->addRoute($name, $spec);
$this->allowedMethodsByPath[$path] = $allowedMethods;
$this->routeNameMap[$name] = sprintf('%s/%s', $name, $httpMethodRouteName);
}
示例2: setUp
public function setUp()
{
$this->router = $router = new TreeRouteStack();
$route = new Segment('/resource[/[:id]]');
$router->addRoute('resource', $route);
$route2 = new Segment('/help');
$router->addRoute('docs', $route2);
$router->addRoute('hostname', ['type' => 'hostname', 'options' => ['route' => 'localhost.localdomain'], 'child_routes' => ['resource' => ['type' => 'segment', 'options' => ['route' => '/resource[/:id]'], 'may_terminate' => true, 'child_routes' => ['children' => ['type' => 'literal', 'options' => ['route' => '/children']]]], 'users' => ['type' => 'segment', 'options' => ['route' => '/users[/:id]']], 'contacts' => ['type' => 'segment', 'options' => ['route' => '/contacts[/:id]']], 'embedded' => ['type' => 'segment', 'options' => ['route' => '/embedded[/:id]']], 'embedded_custom' => ['type' => 'segment', 'options' => ['route' => '/embedded_custom[/:custom_id]']]]]);
$this->event = $event = new MvcEvent();
$event->setRouter($router);
$router->setRequestUri(new Http('http://localhost.localdomain/resource'));
$controller = $this->controller = $this->getMock('Zend\\Mvc\\Controller\\AbstractRestfulController');
$controller->expects($this->any())->method('getEvent')->will($this->returnValue($event));
$this->urlHelper = $urlHelper = new UrlHelper();
$urlHelper->setRouter($router);
$this->serverUrlHelper = $serverUrlHelper = new ServerUrlHelper();
$serverUrlHelper->setScheme('http');
$serverUrlHelper->setHost('localhost.localdomain');
$this->plugin = $plugin = new HalHelper();
$plugin->setController($controller);
$plugin->setUrlHelper($urlHelper);
$plugin->setServerUrlHelper($serverUrlHelper);
$linkExtractor = new LinkExtractor($serverUrlHelper, $urlHelper);
$linkCollectionExtractor = new LinkCollectionExtractor($linkExtractor);
$plugin->setLinkCollectionExtractor($linkCollectionExtractor);
}
示例3: addRoute
/**
* @param Route $route
*/
public function addRoute(Route $route)
{
$path = $route->getPath();
$options = $route->getOptions() ?: [];
$options = array_replace_recursive($options, ['route' => $route->getPath(), 'defaults' => ['middleware' => $route->getMiddleware()]]);
$spec = ['type' => 'segment', 'options' => $options];
$this->zf2Router->addRoute($path, $spec);
$this->routes[$path] = $route;
}
示例4: createRouter
protected function createRouter()
{
$route = new RegexRoute('/assets/(?<resourcePath>.*)', '/assets/%resourcePath%');
$router = new TreeRouteStack();
$router->addRoute('asset', $route);
return $router;
}
示例5: setUp
public function setUp()
{
$router = new TreeRouteStack();
$router->addRoute('home', LiteralRoute::factory(array('route' => '/', 'defaults' => array('controller' => 'ZendTest\\Mvc\\Controller\\TestAsset\\SampleController'))));
$router->addRoute('sub', SegmentRoute::factory(array('route' => '/foo/:param', 'defaults' => array('param' => 1))));
$router->addRoute('ctl', SegmentRoute::factory(array('route' => '/ctl/:controller', 'defaults' => array('__NAMESPACE__' => 'ZendTest\\Mvc\\Controller\\TestAsset', 'controller' => 'sample'))));
$this->controller = new SampleController();
$this->request = new Request();
$this->event = new MvcEvent();
$this->routeMatch = new RouteMatch(array('controller' => 'controller-sample', 'action' => 'postPage'));
$this->event->setRequest($this->request);
$this->event->setRouteMatch($this->routeMatch);
$this->event->setRouter($router);
$this->sessionManager = new SessionManager();
$this->sessionManager->destroy();
$this->controller->setEvent($this->event);
$plugins = $this->controller->getPluginManager();
$plugins->get('flashmessenger')->setSessionManager($this->sessionManager);
}
示例6: testIsActiveReturnsTrueWhenMatchingRoute
public function testIsActiveReturnsTrueWhenMatchingRoute()
{
$page = new Page\Mvc(array('label' => 'spiffyjrwashere', 'route' => 'lolfish'));
$route = new LiteralRoute('/lolfish');
$router = new TreeRouteStack();
$router->addRoute('lolfish', $route);
$routeMatch = new RouteMatch(array());
$routeMatch->setMatchedRouteName('lolfish');
$page->setRouter($router);
$page->setRouteMatch($routeMatch);
$this->assertEquals(true, $page->isActive());
}
示例7: matchUrl
private function matchUrl($url, $urlHelper)
{
$url = 'http://localhost.localdomain' . $url;
$request = new Request();
$request->setUri($url);
$router = new TreeRouteStack();
$router->addRoute('hostname', ['type' => 'hostname', 'options' => ['route' => 'localhost.localdomain'], 'child_routes' => ['resource' => ['type' => 'segment', 'options' => ['route' => '/resource[/:id]']]]]);
$match = $router->match($request);
if ($match instanceof RouteMatch) {
$urlHelper->setRouter($router);
$urlHelper->setRouteMatch($match);
}
return $match;
}
示例8: testHrefGeneratedIsRouteAware
public function testHrefGeneratedIsRouteAware()
{
$page = new Page\Mvc(array('label' => 'foo', 'action' => 'myaction', 'controller' => 'mycontroller', 'route' => 'myroute', 'params' => array('page' => 1337)));
$route = new RegexRoute('(lolcat/(?<action>[^/]+)/(?<page>\\d+))', '/lolcat/%action%/%page%', array('controller' => 'foobar', 'action' => 'bazbat', 'page' => 1));
$router = new TreeRouteStack();
$router->addRoute('myroute', $route);
$routeMatch = new RouteMatch(array('controller' => 'foobar', 'action' => 'bazbat', 'page' => 1));
$urlHelper = new UrlHelper();
$urlHelper->setRouter($router);
$urlHelper->setRouteMatch($routeMatch);
$page->setUrlHelper($urlHelper);
$page->setRouteMatch($routeMatch);
$this->assertEquals('/lolcat/myaction/1337', $page->getHref());
}
示例9: addRoute
private function addRoute($routeName, $route, $routeOptions, $options)
{
if (isset($options['routeName'])) {
$routeName = $options['routeName'];
unset($options['routeName']);
}
if (isset($options['route'])) {
$route = $options['route'];
unset($options['route']);
}
$routeOptions = array_merge($routeOptions, $options);
$routeSegment = Segment::factory(['route' => $route, 'defaults' => $routeOptions]);
$this->router->addRoute($routeName, $routeSegment);
}
示例10: testIsActiveReturnsTrueWhenMatchingRouteWhileUsingModuleRouteListener
public function testIsActiveReturnsTrueWhenMatchingRouteWhileUsingModuleRouteListener()
{
$page = new Page\Mvc(array('label' => 'mpinkstonwashere', 'route' => 'roflcopter', 'controller' => 'index'));
$route = new LiteralRoute('/roflcopter');
$router = new TreeRouteStack();
$router->addRoute('roflcopter', $route);
$routeMatch = new RouteMatch(array(ModuleRouteListener::MODULE_NAMESPACE => 'Application\\Controller', 'controller' => 'index'));
$routeMatch->setMatchedRouteName('roflcopter');
$event = new MvcEvent();
$event->setRouter($router)->setRouteMatch($routeMatch);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->onRoute($event);
$page->setRouter($event->getRouter());
$page->setRouteMatch($event->getRouteMatch());
$this->assertEquals(true, $page->isActive());
}
示例11: testDefaultParamDoesNotOverrideParamForAssembling
public function testDefaultParamDoesNotOverrideParamForAssembling()
{
$stack = new TreeRouteStack();
$stack->addRoute('foo', new TestAsset\DummyRouteWithParam());
$stack->setDefaultParam('foo', 'baz');
$this->assertEquals('bar', $stack->assemble(array('foo' => 'bar'), array('name' => 'foo')));
}
示例12: testCanAppendPreviousUri
public function testCanAppendPreviousUri()
{
$response = new HttpResponse();
$request = new HttpRequest();
$request->setUri('http://example.com');
$router = new TreeRouteStack();
$router->addRoute('login', ['type' => 'Zend\\Mvc\\Router\\Http\\Literal', 'options' => ['route' => '/login']]);
$mvcEvent = new MvcEvent();
$mvcEvent->setParam('exception', new UnauthorizedException());
$mvcEvent->setResponse($response);
$mvcEvent->setRequest($request);
$mvcEvent->setRouter($router);
$options = new RedirectStrategyOptions(['redirect_to_route_disconnected' => 'login', 'append_previous_uri' => true, 'previous_uri_query_key' => 'redirect-uri']);
$authenticationService = $this->getMock('Zend\\Authentication\\AuthenticationService');
$authenticationService->expects($this->once())->method('hasIdentity')->will($this->returnValue(false));
$redirectStrategy = new RedirectStrategy($options, $authenticationService);
$redirectStrategy->onError($mvcEvent);
$this->assertInstanceOf('Zend\\Stdlib\\ResponseInterface', $mvcEvent->getResult());
$this->assertEquals(302, $mvcEvent->getResponse()->getStatusCode());
$this->assertEquals('/login?redirect-uri=http://example.com/', $mvcEvent->getResponse()->getHeaders()->get('Location')->getFieldValue());
}
示例13: testInheritedRouteMatchParamsWorkWithModuleRouteListener
public function testInheritedRouteMatchParamsWorkWithModuleRouteListener()
{
$page = new Page\Mvc(array('label' => 'mpinkstonwashere', 'route' => 'lmaoplane'));
$route = new SegmentRoute('/lmaoplane[/:controller]');
$router = new TreeRouteStack();
$router->addRoute('lmaoplane', $route);
$routeMatch = new RouteMatch(array(ModuleRouteListener::MODULE_NAMESPACE => 'Application\\Controller', 'controller' => 'index'));
$routeMatch->setMatchedRouteName('lmaoplane');
$event = new MvcEvent();
$event->setRouter($router)->setRouteMatch($routeMatch);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->onRoute($event);
$page->setRouter($event->getRouter());
$page->setRouteMatch($event->getRouteMatch());
$this->assertEquals('/lmaoplane', $page->getHref());
$page->setUseRouteMatch(true);
$this->assertEquals('/lmaoplane/index', $page->getHref());
}
示例14: testChainRouteAssembling
public function testChainRouteAssembling()
{
$stack = new TreeRouteStack();
$stack->addPrototype('bar', array('type' => 'literal', 'options' => array('route' => '/bar')));
$stack->addRoute('foo', array('type' => 'literal', 'options' => array('route' => '/foo'), 'chain_routes' => array('bar')));
$this->assertEquals('/foo/bar', $stack->assemble(array(), array('name' => 'foo')));
}
示例15: testMistakeDetectIsActiveOnIndexController
public function testMistakeDetectIsActiveOnIndexController()
{
$page = new Page\Mvc(array('label' => 'some Label', 'route' => 'myRoute'));
$route = new LiteralRoute('/foo');
$router = new TreeRouteStack();
$router->addRoute('myRoute', $route);
$routeMatch = new RouteMatch(array(ModuleRouteListener::MODULE_NAMESPACE => 'Application\\Controller', 'controller' => 'index', 'action' => 'index'));
$routeMatch->setMatchedRouteName('index');
$event = new MvcEvent();
$event->setRouter($router)->setRouteMatch($routeMatch);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->onRoute($event);
$page->setRouter($event->getRouter());
$page->setRouteMatch($event->getRouteMatch());
$this->assertFalse($page->isActive());
}