本文整理汇总了PHP中Zend\Mvc\Router\RouteMatch::setMatchedRouteName方法的典型用法代码示例。如果您正苦于以下问题:PHP RouteMatch::setMatchedRouteName方法的具体用法?PHP RouteMatch::setMatchedRouteName怎么用?PHP RouteMatch::setMatchedRouteName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\Router\RouteMatch
的用法示例。
在下文中一共展示了RouteMatch::setMatchedRouteName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onDispatch
public function onDispatch(Event $event)
{
$controller = $event->getTarget();
if (!$controller instanceof AbstractController) {
return;
}
$entity = $controller->getEntity();
if (!$entity) {
return;
}
$terms = $entity->getTaxonomyTerms();
if ($terms->isEmpty()) {
foreach ($entity->getParents('link') as $parent) {
$terms = $parent->getTaxonomyTerms();
if (!$terms->isEmpty()) {
break;
}
}
}
$term = $this->strategy->findBranch($terms);
if ($term) {
/* @var $navigationFactory DefaultNavigationFactory */
$navigationFactory = $controller->getServiceLocator()->get('Navigation\\Factory\\DefaultNavigationFactory');
$params = ['term' => $term->getId(), 'controller' => 'Taxonomy\\Controller\\GetController', 'action' => 'index'];
$routeMatch = new RouteMatch($params);
$routeMatch->setMatchedRouteName('taxonomy/term/get');
$navigationFactory->setRouteMatch($routeMatch);
}
}
示例2: setUp
public function setUp()
{
StaticEventManager::resetInstance();
$mockSharedEventManager = $this->getMock('Zend\EventManager\SharedEventManagerInterface');
$mockSharedEventManager->expects($this->any())->method('getListeners')->will($this->returnValue(array()));
$mockEventManager = $this->getMock('Zend\EventManager\EventManagerInterface');
$mockEventManager->expects($this->any())->method('getSharedManager')->will($this->returnValue($mockSharedEventManager));
$mockApplication = $this->getMock('Zend\Mvc\ApplicationInterface');
$mockApplication->expects($this->any())->method('getEventManager')->will($this->returnValue($mockEventManager));
$event = new MvcEvent();
$event->setApplication($mockApplication);
$event->setRequest(new Request());
$event->setResponse(new Response());
$routeMatch = new RouteMatch(array('action' => 'test'));
$routeMatch->setMatchedRouteName('some-route');
$event->setRouteMatch($routeMatch);
$locator = new Locator;
$locator->add('forward', function () {
return new ForwardController();
});
$this->controller = new SampleController();
$this->controller->setEvent($event);
$this->controller->setServiceLocator($locator);
$this->plugin = $this->controller->plugin('forward');
}
示例3: testIsActiveReturnsFalseWhenMatchingRouteButNonMatchingParams
public function testIsActiveReturnsFalseWhenMatchingRouteButNonMatchingParams()
{
$page = new Page\Mvc(array('label' => 'foo', 'route' => 'bar', 'action' => 'baz'));
$routeMatch = new RouteMatch(array());
$routeMatch->setMatchedRouteName('bar');
$routeMatch->setParam('action', 'qux');
$page->setRouteMatch($routeMatch);
$this->assertFalse($page->isActive());
}
示例4: 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());
}
示例5: testSetsActiveFlagOnPagesProvidingTheActiveOnOption
public function testSetsActiveFlagOnPagesProvidingTheActiveOnOption()
{
$pages = ['page1' => ['active_on' => 'matchedRouteName'], 'page2' => ['active_on' => 'notMatchedRoute'], 'page3' => ['active_on' => ['matchedRouteName', 'anotherRoute']], 'page4' => []];
$routeMatch = new RouteMatch([]);
$routeMatch->setMatchedRouteName('matchedRouteName');
$expect = $pages;
$expect['page1']['active'] = true;
$expect['page3']['active'] = true;
$m = new \ReflectionMethod($this->target, 'injectComponents');
$m->setAccessible(true);
$actual = $m->invoke($this->target, $pages, $routeMatch);
$this->assertEquals($expect, $actual);
}
示例6: setUp
public function setUp()
{
StaticEventManager::resetInstance();
$mockSharedEventManager = $this->getMock('Zend\\EventManager\\SharedEventManagerInterface');
$mockSharedEventManager->expects($this->any())->method('getListeners')->will($this->returnValue(array()));
$mockEventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface');
$mockEventManager->expects($this->any())->method('getSharedManager')->will($this->returnValue($mockSharedEventManager));
$mockApplication = $this->getMock('Zend\\Mvc\\ApplicationInterface');
$mockApplication->expects($this->any())->method('getEventManager')->will($this->returnValue($mockEventManager));
$event = new MvcEvent();
$event->setApplication($mockApplication);
$event->setRequest(new Request());
$event->setResponse(new Response());
$routeMatch = new RouteMatch(array('action' => 'test'));
$routeMatch->setMatchedRouteName('some-route');
$event->setRouteMatch($routeMatch);
$services = new Locator();
$plugins = $this->plugins = new PluginManager();
$plugins->setServiceLocator($services);
$controllers = $this->controllers = new ControllerManager();
$controllers->setFactory('forward', function () use($plugins) {
$controller = new ForwardController();
$controller->setPluginManager($plugins);
return $controller;
});
$controllers->setInvokableClass('ZendTest\\Mvc\\Controller\\TestAsset\\ForwardFq', 'ZendTest\\Mvc\\Controller\\TestAsset\\ForwardFqController');
$controllers->setServiceLocator($services);
$controllerLoader = function () use($controllers) {
return $controllers;
};
$services->add('ControllerLoader', $controllerLoader);
$services->add('ControllerManager', $controllerLoader);
$services->add('ControllerPluginManager', function () use($plugins) {
return $plugins;
});
$services->add('Zend\\ServiceManager\\ServiceLocatorInterface', function () use($services) {
return $services;
});
$services->add('EventManager', function () use($mockEventManager) {
return $mockEventManager;
});
$services->add('SharedEventManager', function () use($mockSharedEventManager) {
return $mockSharedEventManager;
});
$this->controller = new SampleController();
$this->controller->setEvent($event);
$this->controller->setServiceLocator($services);
$this->controller->setPluginManager($plugins);
$this->plugin = $this->controller->plugin('forward');
}
示例7: testShouldCache
/**
* @param array $routes
* @param string $route
* @param boolean $expectedResult
* @param array $params
* @param string $httpMethod
* @dataProvider shouldCacheProvider
*/
public function testShouldCache($routes, $route, $expectedResult, $params = array(), $httpMethod = null)
{
$this->strategy->setRoutes($routes);
$routeMatch = new RouteMatch($params);
$routeMatch->setMatchedRouteName($route);
$request = new Request();
if ($httpMethod !== null) {
$request->setMethod($httpMethod);
}
$mvcEvent = new MvcEvent();
$mvcEvent->setRouteMatch($routeMatch);
$mvcEvent->setRequest($request);
$this->assertEquals($expectedResult, $this->strategy->shouldCache($mvcEvent));
}
示例8: testCheckDeactivatedUser
/**
* @dataProvider dataForheckDeactivatedUser
*/
public function testCheckDeactivatedUser($routeName, $hasIdentity, $isActive, $expectedTriggerCalled)
{
$this->routeMatch->setMatchedRouteName($routeName);
$this->auth->expects($this->any())->method('hasIdentity')->willReturn($hasIdentity);
$this->user->expects($this->any())->method('isActive')->willReturn($isActive);
$this->event->expects($expectedTriggerCalled ? $this->once() : $this->never())->method('setError');
if ($expectedTriggerCalled) {
$eventManager = $this->getMockBuilder(EventManager::class)->getMock();
$eventManager->expects($this->once())->method('trigger')->willReturn(new \Zend\EventManager\ResponseCollection())->with($this->equalTo(MvcEvent::EVENT_DISPATCH_ERROR));
$target = $this->getMockBuilder(\stdClass::class)->setMethods(['getEventManager'])->getMock();
$target->expects($this->any())->method('getEventManager')->willReturn($eventManager);
$this->event->expects($this->once())->method('getTarget')->willReturn($target);
}
$this->listener->checkDeactivatedUser($this->event);
}
示例9: createService
/**
* {@inheritDoc}
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
/* @var $serviceLocator AbstractPluginManager */
$serviceManager = $serviceLocator->getServiceLocator();
$response = $serviceManager->get('Response');
$request = $serviceManager->get('Request');
$router = $serviceManager->get('Router');
$routeMatch = $router->match($request);
$class = $this->getClass();
if (null === $routeMatch) {
$routeMatch = new RouteMatch([]);
$routeMatch->setMatchedRouteName('home');
}
return new $class($response, $router, $routeMatch);
}
示例10: testCanAllowAccess
public function testCanAllowAccess()
{
$eventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface');
$eventManager->expects($this->never())->method('trigger');
$application = $this->getMock('Zend\\Mvc\\Application', array(), array(), '', false);
$application->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
$routeMatch = new RouteMatch(array());
$routeMatch->setMatchedRouteName('secure');
$event = new MvcEvent();
$event->setRouteMatch($routeMatch);
$event->setApplication($application);
$routeGuardMock = $this->getMockBuilder('UghAuthorization\\Guards\\Guard', array('isGranted'))->disableOriginalConstructor()->getMock();
$routeGuardMock->expects($this->any())->method('isGranted')->will($this->returnValue(true));
$routeGuardListener = new RouteGuardListener($routeGuardMock);
$routeGuardListener->onGuard($event);
$this->assertFalse($event->propagationIsStopped());
$this->assertEmpty($event->getError());
}
示例11: configureControllerForAGivenRoute
public function configureControllerForAGivenRoute($controller, $routeName)
{
//CONFIGURE ROUTING
$event = new MvcEvent();
//build the router and set it as event's router.
$routeStack = new SimpleRouteStack();
$route = new Literal('/' . $routeName);
$routeStack->addRoute($routeName, $route);
//so that "route >home< not found" error did not show up - add home route.
$routeHome = new Literal('/');
$routeStack->addRoute('home', $routeHome);
$event->setRouter($routeStack);
//set route match for the event
$routeMatch = new RouteMatch(['controller' => 'Index', 'action' => $routeName]);
$routeMatch->setMatchedRouteName($routeName);
$event->setRouteMatch($routeMatch);
//finish configuring controller
$controller->setEvent($event);
return $controller;
}
示例12: testProperlySetUnauthorizedAndTriggerEventOnUnauthorization
public function testProperlySetUnauthorizedAndTriggerEventOnUnauthorization()
{
$whip = $this->createMock(Whip::class);
$whip->expects($this->once())->method('getValidIpAddress')->will($this->returnValue(false));
$event = new MvcEvent();
$request = new HttpRequest();
$response = new HttpResponse();
$routeMatch = new RouteMatch([]);
$application = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock();
$eventManager = $this->createMock(EventManagerInterface::class);
$application->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
$routeMatch->setMatchedRouteName(Module::RECURLY_NOTIFICATION_ROUTE);
$event->setRequest($request)->setResponse($response)->setRouteMatch($routeMatch)->setApplication($application);
$listener = new IpListener($whip);
$logger = $this->createMock(LoggerInterface::class);
$logger->expects($this->once())->method('info');
$listener->setLogger($logger);
$listener->onResult($event);
$this->assertNotEmpty($event->getError());
$this->assertNotNull($event->getParam('exception'));
$this->assertEquals(HttpResponse::STATUS_CODE_403, $response->getStatusCode());
}
示例13: dispatch
/**
* Dispatch another controller
*
* @param string $name Controller name; either a class name or an alias used in the DI container or service locator
* @param null|array $params Parameters with which to seed a custom RouteMatch object for the new controller
* @return mixed
* @throws Exception\DomainException if composed controller does not define InjectApplicationEventInterface
* or Locator aware; or if the discovered controller is not dispatchable
*/
public function dispatch($name, array $params = null)
{
$event = clone $this->getEvent();
$locator = $this->getLocator();
$scoped = false;
// Use the controller loader when possible
if ($locator->has('ControllerLoader')) {
$locator = $locator->get('ControllerLoader');
$scoped = true;
}
$controller = $locator->get($name);
if (!$controller instanceof Dispatchable) {
throw new Exception\DomainException('Can only forward to DispatchableInterface classes; class of type ' . get_class($controller) . ' received');
}
if ($controller instanceof InjectApplicationEventInterface) {
$controller->setEvent($event);
}
if (!$scoped) {
if ($controller instanceof ServiceLocatorAwareInterface) {
$controller->setServiceLocator($locator);
}
}
// Allow passing parameters to seed the RouteMatch with & copy matched route name
if ($params !== null) {
$routeMatch = new RouteMatch($params);
$routeMatch->setMatchedRouteName($event->getRouteMatch()->getMatchedRouteName());
$event->setRouteMatch($routeMatch);
}
if ($this->numNestedForwards > $this->maxNestedForwards) {
throw new Exception\DomainException("Circular forwarding detected: greater than {$this->maxNestedForwards} nested forwards");
}
$this->numNestedForwards++;
// Detach listeners that may cause problems during dispatch:
$sharedEvents = $event->getApplication()->getEventManager()->getSharedManager();
$listeners = $this->detachProblemListeners($sharedEvents);
$return = $controller->dispatch($event->getRequest(), $event->getResponse());
// If we detached any listeners, reattach them now:
$this->reattachProblemListeners($sharedEvents, $listeners);
$this->numNestedForwards--;
return $return;
}
示例14: dispatch
/**
* Dispatch another controller
*
* @param string $name Controller name; either a class name or an alias used in the controller manager
* @param null|array $params Parameters with which to seed a custom RouteMatch object for the new controller
* @return mixed
* @throws Exception\DomainException if composed controller does not define InjectApplicationEventInterface
* or Locator aware; or if the discovered controller is not dispatchable
*/
public function dispatch($name, array $params = null)
{
$event = clone $this->getEvent();
$controller = $this->controllers->get($name);
if ($controller instanceof InjectApplicationEventInterface) {
$controller->setEvent($event);
}
// Allow passing parameters to seed the RouteMatch with & copy matched route name
if ($params !== null) {
$routeMatch = new RouteMatch($params);
$routeMatch->setMatchedRouteName($event->getRouteMatch()->getMatchedRouteName());
$event->setRouteMatch($routeMatch);
}
if ($this->numNestedForwards > $this->maxNestedForwards) {
throw new Exception\DomainException("Circular forwarding detected: greater than {$this->maxNestedForwards} nested forwards");
}
$this->numNestedForwards++;
// Detach listeners that may cause problems during dispatch:
$sharedEvents = $event->getApplication()->getEventManager()->getSharedManager();
$listeners = $this->detachProblemListeners($sharedEvents);
$return = $controller->dispatch($event->getRequest(), $event->getResponse());
// If we detached any listeners, reattach them now:
$this->reattachProblemListeners($sharedEvents, $listeners);
$this->numNestedForwards--;
return $return;
}
示例15: testRemoveInputFilter
public function testRemoveInputFilter()
{
$request = new Request();
$request->setMethod('delete');
$request->getHeaders()->addHeaderLine('Accept', 'application/json');
$request->getHeaders()->addHeaderLine('Content-Type', 'application/json');
$module = 'InputFilter';
$controller = 'InputFilter\\V1\\Rest\\Foo\\Controller';
$validator = 'InputFilter\\V1\\Rest\\Foo\\Validator';
$params = ['name' => $module, 'controller_service_name' => $controller, 'input_filter_name' => $validator];
$routeMatch = new RouteMatch($params);
$routeMatch->setMatchedRouteName('zf-apigility-admin/api/module/rest-service/rest_input_filter');
$event = new MvcEvent();
$event->setRouteMatch($routeMatch);
$this->controller->setRequest($request);
$this->controller->setEvent($event);
$result = $this->controller->indexAction();
$this->assertInstanceOf('Zend\\Http\\Response', $result);
$this->assertEquals(204, $result->getStatusCode());
}