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


PHP RouteMatch::setMatchedRouteName方法代码示例

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

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

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

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

示例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);
 }
开发者ID:cross-solution,项目名称:yawik,代码行数:13,代码来源:DefaultNavigationFactoryTest.php

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

示例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));
 }
开发者ID:stefanorg,项目名称:zf2-fullpage-cache,代码行数:22,代码来源:RouteTest.php

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

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

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

示例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;
 }
开发者ID:slawojstanislawski,项目名称:doctrine-entity-creator,代码行数:20,代码来源:AbstractDecControllerTest.php

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

示例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;
 }
开发者ID:totolouis,项目名称:ZF2-Auth,代码行数:50,代码来源:Forward.php

示例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;
 }
开发者ID:leonardovn86,项目名称:zf2_basic2013,代码行数:35,代码来源:Forward.php

示例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());
 }
开发者ID:erik-maas,项目名称:zf-apigility-admin,代码行数:20,代码来源:InputFilterControllerTest.php


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