本文整理汇总了PHP中Zend\Mvc\Router\Http\TreeRouteStack::addRoutes方法的典型用法代码示例。如果您正苦于以下问题:PHP TreeRouteStack::addRoutes方法的具体用法?PHP TreeRouteStack::addRoutes怎么用?PHP TreeRouteStack::addRoutes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\Router\Http\TreeRouteStack
的用法示例。
在下文中一共展示了TreeRouteStack::addRoutes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createService
/**
* Create and return the router
*
* Retrieves the "router" key of the Config service, and uses it
* to instantiate the router. Uses the TreeRouteStack implementation by
* default.
*
* @param ServiceLocatorInterface $serviceLocator
* @param string|null $cName
* @param string|null $rName
* @return \Zend\Mvc\Router\RouteStackInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator, $cName = null, $rName = null)
{
$config = $serviceLocator->get('Config');
$routePluginManager = $serviceLocator->get('RoutePluginManager');
if ($rName === 'ConsoleRouter' || $cName === 'router' && Console::isConsole()) {
// We are in a console, use console router.
if (isset($config['console']) && isset($config['console']['router'])) {
$routerConfig = $config['console']['router'];
} else {
$routerConfig = array();
}
$router = new ConsoleRouter($routePluginManager);
} else {
// This is an HTTP request, so use HTTP router
$router = new HttpRouter($routePluginManager);
$routerConfig = isset($config['router']) ? $config['router'] : array();
}
if (isset($routerConfig['route_plugins'])) {
$router->setRoutePluginManager($routerConfig['route_plugins']);
}
if (isset($routerConfig['routes'])) {
$router->addRoutes($routerConfig['routes']);
}
if (isset($routerConfig['default_params'])) {
$router->setDefaultParams($routerConfig['default_params']);
}
return $router;
}
示例2: setUpRouter
public function setUpRouter()
{
if (isset($this->router)) {
return;
}
$this->setUpRequest();
$routes = ['resource' => ['type' => 'Segment', 'options' => ['route' => '/api/resource[/:id]', 'defaults' => ['controller' => 'Api\\RestController']]]];
$this->router = $router = new TreeRouteStack();
$router->addRoutes($routes);
$matches = $router->match($this->request);
if (!$matches instanceof RouteMatch) {
$this->fail('Failed to route!');
}
$this->matches = $matches;
}
示例3: testPriorityIsPassedToPartRoute
public function testPriorityIsPassedToPartRoute()
{
$stack = new TreeRouteStack();
$stack->addRoutes(array('foo' => array('type' => 'Literal', 'priority' => 1000, 'options' => array('route' => '/foo', 'defaults' => array('controller' => 'foo')), 'may_terminate' => true, 'child_routes' => array('bar' => array('type' => 'Literal', 'options' => array('route' => '/bar', 'defaults' => array('controller' => 'foo', 'action' => 'bar')))))));
$reflectedClass = new \ReflectionClass($stack);
$reflectedProperty = $reflectedClass->getProperty('routes');
$reflectedProperty->setAccessible(true);
$routes = $reflectedProperty->getValue($stack);
$this->assertEquals(1000, $routes->get('foo')->priority);
}
示例4: setUpAlternateRouter
public function setUpAlternateRouter()
{
$routes = array('parent' => array('type' => 'Segment', 'options' => array('route' => '/api/parent[/:id]', 'defaults' => array('controller' => 'Api\\ParentController')), 'may_terminate' => true, 'child_routes' => array('child' => array('type' => 'Segment', 'options' => array('route' => '/child[/:child_id]', 'defaults' => array('controller' => 'Api\\ChildController'))))));
$this->router = $router = new TreeRouteStack();
$router->addRoutes($routes);
$this->helpers->get('url')->setRouter($router);
}
示例5: setupRouter
/**
* Sets up the router based on the configuration provided
*
* @param Application $application
* @return void
*/
protected function setupRouter(AppContext $application)
{
$router = new Router();
$router->addRoutes($this->config->routes);
$application->setRouter($router);
}
示例6: testRecursiveDetectIsActiveWhenRouteNameIsKnown
public function testRecursiveDetectIsActiveWhenRouteNameIsKnown()
{
$parentPage = new Page\Mvc(array('label' => 'some Label', 'route' => 'parentPageRoute'));
$childPage = new Page\Mvc(array('label' => 'child', 'route' => 'childPageRoute'));
$parentPage->addPage($childPage);
$router = new TreeRouteStack();
$router->addRoutes(array('parentPageRoute' => array('type' => 'literal', 'options' => array('route' => '/foo', 'defaults' => array('controller' => 'fooController', 'action' => 'fooAction'))), 'childPageRoute' => array('type' => 'literal', 'options' => array('route' => '/bar', 'defaults' => array('controller' => 'barController', 'action' => 'barAction')))));
$routeMatch = new RouteMatch(array(ModuleRouteListener::MODULE_NAMESPACE => 'Application\\Controller', 'controller' => 'barController', 'action' => 'barAction'));
$routeMatch->setMatchedRouteName('childPageRoute');
$event = new MvcEvent();
$event->setRouter($router)->setRouteMatch($routeMatch);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->onRoute($event);
$parentPage->setRouter($event->getRouter());
$parentPage->setRouteMatch($event->getRouteMatch());
$childPage->setRouter($event->getRouter());
$childPage->setRouteMatch($event->getRouteMatch());
$this->assertTrue($childPage->isActive(true));
$this->assertTrue($parentPage->isActive(true));
}