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


PHP Router\RouteMatch类代码示例

本文整理汇总了PHP中Zend\Mvc\Router\RouteMatch的典型用法代码示例。如果您正苦于以下问题:PHP RouteMatch类的具体用法?PHP RouteMatch怎么用?PHP RouteMatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RouteMatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $callback = function (MvcEvent $event) {
         $view = $event->getApplication()->getServiceManager()->get('ViewRenderer');
         $config = $event->getApplication()->getConfig();
         $controller = $event->getTarget();
         $rm = $event->getRouteMatch();
         if (!$rm instanceof RouteMatch) {
             $rm = new RouteMatch(array('module' => 'Application', '__NAMESPACE__' => 'Application\\Controller', '__CONTROLLER__' => 'index', 'controller' => 'Application\\Controller\\Index', 'action' => 'index'));
         }
         $params = $rm->getParams();
         $modulo = "";
         if (isset($params['__NAMESPACE__'])) {
             $paramsArray = explode("\\", $params['__NAMESPACE__']);
             $modulo = $paramsArray[0];
         }
         $controller = isset($params['__CONTROLLER__']) ? $params['__CONTROLLER__'] : "";
         $action = isset($params['action']) ? $params['action'] : null;
         $app = $event->getParam('application');
         $sm = $app->getServiceManager();
         $paramsConfig = ['modulo' => strtolower($modulo), 'controller' => strtolower($controller), 'action' => strtolower($action), 'baseHost' => $view->base_path("/"), 'cssStaticHost' => "", 'jsStaticHost' => "", 'statHost' => "", 'eHost' => "", 'statVers' => '?', 'min' => '', 'AppCore' => [], 'AppSandbox' => [], 'AppSchema' => ['modules' => [], 'requires' => []]];
         $view->inlineScript()->appendScript("var yOSON=" . json_encode($paramsConfig, JSON_FORCE_OBJECT));
     };
     $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', MvcEvent::EVENT_DISPATCH, $callback, 100);
     $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Application', MvcEvent::EVENT_DISPATCH_ERROR, $callback, 100);
 }
开发者ID:jrodev,项目名称:Yoson,代码行数:26,代码来源:Module.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: 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

示例4: getVersionFromRouteMatch

 /**
  * Retrieve the version from the route match.
  *
  * The route prototype sets "version", while the Content-Type listener sets
  * "zf_ver_version"; check both to obtain the version, giving priority to the
  * route prototype result.
  *
  * @param  RouteMatch $routeMatches
  * @return int|false
  */
 protected function getVersionFromRouteMatch(RouteMatch $routeMatches)
 {
     $version = $routeMatches->getParam('zf_ver_version', false);
     if ($version) {
         return $version;
     }
     return $routeMatches->getParam('version', false);
 }
开发者ID:gstearmit,项目名称:EshopVegeTable,代码行数:18,代码来源:VersionListener.php

示例5: 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

示例6: getAllowedRoles

 protected function getAllowedRoles(RouteMatch $routeMatch)
 {
     $controller = strtolower($routeMatch->getParam('controller'));
     $action = strtolower($routeMatch->getParam('action'));
     $restAction = strtolower($routeMatch->getParam('restAction'));
     $rolesByAction = @$this->rules[$controller] ?: [];
     $roles = @$rolesByAction[$action] ?: @$rolesByAction[$restAction];
     $roles = $roles ?: @$rolesByAction['*'];
     return $roles;
 }
开发者ID:aerisweather,项目名称:ZfAuth,代码行数:10,代码来源:ControllerGuard.php

示例7: fromRoute

 public static function fromRoute(\Zend\Mvc\Router\RouteMatch $route)
 {
     $internalRoute = new self();
     $internalRoute->setRoute($route->getMatchedRouteName());
     $internalRoute->setParams($route->getParams());
     if ($_GET) {
         $internalRoute->setOptions(array('query' => $_GET));
     }
     return $internalRoute;
 }
开发者ID:stavarengo,项目名称:sta-commons,代码行数:10,代码来源:InternalRoute.php

示例8: onDispatchError

 public function onDispatchError(MvcEvent $e)
 {
     if ($e->getError() !== Zf2Application::ERROR_ROUTER_NO_MATCH) {
         return;
     }
     $routeMatch = new RouteMatch(array());
     $routeMatch->setParam('controller', 'Zf1Module\\DispatchController');
     $e->setError(null);
     $e->setRouteMatch($routeMatch);
     return $routeMatch;
 }
开发者ID:xemlock,项目名称:Zf1Module,代码行数:11,代码来源:DispatchListener.php

示例9: resolveController

 public static function resolveController(RouteMatch $routeMatch)
 {
     if ($routeMatch->getMatchedRouteName() != 'rest') {
         return;
     }
     if ($endpoint = $routeMatch->getParam('endpoint')) {
         $routeMatch->setParam('controller', 'shard.rest.' . $endpoint);
     } else {
         $routeMatch->setParam('controller', 'shard.rest');
     }
 }
开发者ID:zoopcommerce,项目名称:shard-module,代码行数:11,代码来源:RouteListener.php

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: switchInstance

 /**
  * {@inheritDoc}
  */
 public function switchInstance(InstanceInterface $instance)
 {
     $container = $this->getContainer();
     $container->offsetSet('instance', $instance->getId());
     $url = $this->router->assemble($this->routeMatch->getParams(), ['name' => $this->routeMatch->getMatchedRouteName()]);
     $this->redirect($url);
 }
开发者ID:andreas-serlo,项目名称:athene2,代码行数:10,代码来源:CookieStrategy.php

示例15: __invoke

 /**
  * Get the current action's name
  *
  * @return string|bool
  */
 public function __invoke()
 {
     if ($this->routeMatch) {
         return $this->routeMatch->getMatchedRouteName();
     }
     return false;
 }
开发者ID:JoshBour,项目名称:karolina,代码行数:12,代码来源:ActionName.php


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