本文整理汇总了PHP中Zend\Mvc\ModuleRouteListener::onRoute方法的典型用法代码示例。如果您正苦于以下问题:PHP ModuleRouteListener::onRoute方法的具体用法?PHP ModuleRouteListener::onRoute怎么用?PHP ModuleRouteListener::onRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\ModuleRouteListener
的用法示例。
在下文中一共展示了ModuleRouteListener::onRoute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRemovesModuleRouteListenerParamsWhenReusingMatchedParameters
public function testRemovesModuleRouteListenerParamsWhenReusingMatchedParameters()
{
$router = new \Zend\Mvc\Router\Http\TreeRouteStack();
$router->addRoute('default', array('type' => 'Zend\\Mvc\\Router\\Http\\Segment', 'options' => array('route' => '/:controller/:action', 'defaults' => array(ModuleRouteListener::MODULE_NAMESPACE => 'ZendTest\\Mvc\\Controller\\TestAsset', 'controller' => 'SampleController', 'action' => 'Dash')), 'child_routes' => array('wildcard' => array('type' => 'Zend\\Mvc\\Router\\Http\\Wildcard', 'options' => array('param_delimiter' => '=', 'key_value_delimiter' => '%')))));
$routeMatch = new RouteMatch(array(ModuleRouteListener::MODULE_NAMESPACE => 'ZendTest\\Mvc\\Controller\\TestAsset', 'controller' => 'Rainbow'));
$routeMatch->setMatchedRouteName('default/wildcard');
$event = new MvcEvent();
$event->setRouter($router)->setRouteMatch($routeMatch);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->onRoute($event);
$controller = new SampleController();
$controller->setEvent($event);
$url = $controller->plugin('url')->fromRoute('default/wildcard', array('Twenty' => 'Cooler'), true);
$this->assertEquals('/Rainbow/Dash=Twenty%Cooler', $url);
}
示例2: testUsingNamespaceRouteParameterGivesSameResultAsFullControllerParameter
public function testUsingNamespaceRouteParameterGivesSameResultAsFullControllerParameter()
{
$controller1 = 'MappedNs\\Foo\\Controller\\Bar\\Baz\\Sample';
$this->routeMatch->setParam('controller', $controller1);
$this->listener->injectActionHandles($this->event);
$handles1 = $this->updater->getHandles();
$controller2 = 'MappedNs\\Foo\\Controller\\Bar';
$this->routeMatch->setParam(ModuleRouteListener::MODULE_NAMESPACE, $controller2);
$this->routeMatch->setParam('controller', 'Baz\\Sample');
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->onRoute($this->event);
$this->listener->injectActionHandles($this->event);
$handles2 = $this->updater->getHandles();
$this->assertEquals($handles1, $handles2);
}
示例3: 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());
}
示例4: testKeepUrlQueryParameters
public function testKeepUrlQueryParameters()
{
$expects = '/ctl/sample';
$this->request->setMethod('POST');
$this->request->setUri($expects);
$this->request->setQuery(new Parameters(['id' => '123']));
$routeMatch = $this->event->getRouter()->match($this->request);
$this->event->setRouteMatch($routeMatch);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->onRoute($this->event);
$this->controller->dispatch($this->request, $this->response);
$plugin = $this->plugin;
$prgResultRoute = $plugin();
$this->assertInstanceOf('Zend\\Http\\Response', $prgResultRoute);
$this->assertTrue($prgResultRoute->getHeaders()->has('Location'));
$this->assertEquals($expects . '?id=123', $prgResultRoute->getHeaders()->get('Location')->getUri(), 'expects to redirect for the same url');
$this->assertEquals(303, $prgResultRoute->getStatusCode());
}
示例5: testReuseMatchedParametersWithSegmentController
public function testReuseMatchedParametersWithSegmentController()
{
$expects = '/ctl/sample';
$this->request->setMethod('POST');
$this->request->setUri($expects);
$this->request->setPost(new Parameters(['postval1' => 'value1']));
$routeMatch = $this->event->getRouter()->match($this->request);
$this->event->setRouteMatch($routeMatch);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->onRoute($this->event);
$this->controller->dispatch($this->request, $this->response);
$plugin = $this->plugin;
$prgResultRoute = $plugin($this->form);
$this->assertInstanceOf(Response::class, $prgResultRoute);
$this->assertTrue($prgResultRoute->getHeaders()->has('Location'));
$this->assertEquals($expects, $prgResultRoute->getHeaders()->get('Location')->getUri(), 'redirect to the same url');
$this->assertEquals(303, $prgResultRoute->getStatusCode());
}
示例6: 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());
}
示例7: 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));
}
示例8: testUsingNamespaceRouteParameterGivesSameResultAsFullControllerParameter
public function testUsingNamespaceRouteParameterGivesSameResultAsFullControllerParameter()
{
$this->routeMatch->setParam('controller', 'MappedNs\\Foo\\Controller\\Bar\\Baz\\Sample');
$myViewModel = new ViewModel();
$this->event->setResult($myViewModel);
$this->listener->injectTemplate($this->event);
$template1 = $myViewModel->getTemplate();
$this->routeMatch->setParam(ModuleRouteListener::MODULE_NAMESPACE, 'MappedNs\\Foo\\Controller\\Bar');
$this->routeMatch->setParam('controller', 'Baz\\Sample');
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->onRoute($this->event);
$myViewModel = new ViewModel();
$this->event->setResult($myViewModel);
$this->listener->injectTemplate($this->event);
$this->assertEquals($template1, $myViewModel->getTemplate());
}