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


PHP TreeRouteStack::addRoute方法代码示例

本文整理汇总了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);
 }
开发者ID:flipecristian,项目名称:apiZend,代码行数:33,代码来源:Zf2.php

示例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);
 }
开发者ID:antarus,项目名称:mystra-pve,代码行数:26,代码来源:HalTest.php

示例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;
 }
开发者ID:ezimuel,项目名称:zend-expressive,代码行数:12,代码来源:Zf2.php

示例4: createRouter

 protected function createRouter()
 {
     $route = new RegexRoute('/assets/(?<resourcePath>.*)', '/assets/%resourcePath%');
     $router = new TreeRouteStack();
     $router->addRoute('asset', $route);
     return $router;
 }
开发者ID:rhysr,项目名称:zf2assetic,代码行数:7,代码来源:AssetPathTest.php

示例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);
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:19,代码来源:PostRedirectGetTest.php

示例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());
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:12,代码来源:MvcTest.php

示例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;
 }
开发者ID:gstearmit,项目名称:EshopVegeTable,代码行数:14,代码来源:LinkExtractorTest.php

示例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());
 }
开发者ID:nevvermind,项目名称:zf2,代码行数:14,代码来源:MvcTest.php

示例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);
 }
开发者ID:t4web,项目名称:crud,代码行数:14,代码来源:RouteGenerator.php

示例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());
 }
开发者ID:nieldm,项目名称:zf2,代码行数:16,代码来源:MvcTest.php

示例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')));
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:7,代码来源:TreeRouteStackTest.php

示例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());
 }
开发者ID:adamh114,项目名称:zfc-rbac,代码行数:21,代码来源:RedirectStrategyTest.php

示例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());
 }
开发者ID:rajanlamic,项目名称:IntTest,代码行数:18,代码来源:MvcTest.php

示例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')));
 }
开发者ID:rajanlamic,项目名称:IntTest,代码行数:7,代码来源:TreeRouteStackTest.php

示例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());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:16,代码来源:MvcTest.php


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