本文整理汇总了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);
}
示例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: 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);
}
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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');
}
}
示例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());
}
示例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);
}
示例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));
}
示例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');
}
示例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);
}
示例15: __invoke
/**
* Get the current action's name
*
* @return string|bool
*/
public function __invoke()
{
if ($this->routeMatch) {
return $this->routeMatch->getMatchedRouteName();
}
return false;
}