本文整理汇总了PHP中Zend\Mvc\Router\RouteMatch::getMatchedRouteName方法的典型用法代码示例。如果您正苦于以下问题:PHP RouteMatch::getMatchedRouteName方法的具体用法?PHP RouteMatch::getMatchedRouteName怎么用?PHP RouteMatch::getMatchedRouteName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\Router\RouteMatch
的用法示例。
在下文中一共展示了RouteMatch::getMatchedRouteName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* Get the current action's name
*
* @return string|bool
*/
public function __invoke()
{
if ($this->routeMatch) {
return $this->routeMatch->getMatchedRouteName();
}
return false;
}
示例2: 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);
}
示例3: switchInstance
/**
* {@inheritDoc}
*/
public function switchInstance(InstanceInterface $instance)
{
if (!array_key_exists('HTTP_HOST', (array) $_SERVER)) {
throw new Exception\RuntimeException(sprintf('Host not set.'));
}
$url = $this->router->assemble($this->routeMatch->getParams(), ['name' => $this->routeMatch->getMatchedRouteName()]);
$hostNames = explode('.', $_SERVER['HTTP_HOST']);
$tld = $hostNames[count($hostNames) - 2] . "." . $hostNames[count($hostNames) - 1];
$url = 'http://' . $instance->getSubdomain() . '.' . $tld . $url;
$this->redirect($url);
}
示例4: isActive
/**
* Returns whether page should be considered active or not
*
* This method will compare the page properties against the route matches
* composed in the object.
*
* @param bool $recursive [optional] whether page should be considered
* active if any child pages are active. Default is
* false.
* @return bool whether page should be considered active or not
*/
public function isActive($recursive = false)
{
if (!$this->active) {
$reqParams = array();
if ($this->routeMatch instanceof RouteMatch) {
$reqParams = $this->routeMatch->getParams();
if ($this->routeMatch->getMatchedRouteName() === $this->getRoute()) {
$this->active = true;
return true;
}
}
$myParams = $this->params;
if (null !== $this->controller) {
$myParams['controller'] = $this->controller;
} else {
/**
* @todo In ZF1, this was configurable and pulled from the front controller
*/
$myParams['controller'] = 'index';
}
if (null !== $this->action) {
$myParams['action'] = $this->action;
} else {
/**
* @todo In ZF1, this was configurable and pulled from the front controller
*/
$myParams['action'] = 'action';
}
if (count(array_intersect_assoc($reqParams, $myParams)) == count($myParams)) {
$this->active = true;
return true;
}
}
return parent::isActive($recursive);
}
示例5: isExcluded
/**
* {@inheritDoc}
*/
public function isExcluded()
{
$matchedRouteName = $this->routeMatch->getMatchedRouteName();
$matchedRouteParams = $this->routeMatch->getParams();
$matchedRoutePath = $this->getRoutePath($matchedRouteParams);
foreach ($this->routes as $route) {
if (is_string($route) && $route == $matchedRouteName) {
return true;
} elseif (is_array($route)) {
if (isset($route['action']) && $this->getRoutePath($route) == $matchedRoutePath) {
return true;
} elseif (!isset($route['action']) && $route['controller'] == $matchedRouteParams['controller']) {
return true;
}
}
}
return false;
}
示例6: 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;
}
示例7: 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');
}
}
示例8: __invoke
/**
* Generates a url given the name of a route.
*
* @see Zend\Mvc\Router\RouteInterface::assemble()
* @see Zend\Router\RouteInterface::assemble()
* @param string $name Name of the route
* @param array $params Parameters for the link
* @param array|Traversable $options Options for the route
* @param bool $reuseMatchedParams Whether to reuse matched parameters
* @return string Url For the link href attribute
* @throws Exception\RuntimeException If no RouteStackInterface was
* provided
* @throws Exception\RuntimeException If no RouteMatch was provided
* @throws Exception\RuntimeException If RouteMatch didn't contain a
* matched route name
* @throws Exception\InvalidArgumentException If the params object was not
* an array or Traversable object.
*/
public function __invoke($name = null, $params = [], $options = [], $reuseMatchedParams = false)
{
if (null === $this->router) {
throw new Exception\RuntimeException('No RouteStackInterface instance provided');
}
if (3 == func_num_args() && is_bool($options)) {
$reuseMatchedParams = $options;
$options = [];
}
if ($name === null) {
if ($this->routeMatch === null) {
throw new Exception\RuntimeException('No RouteMatch instance provided');
}
$name = $this->routeMatch->getMatchedRouteName();
if ($name === null) {
throw new Exception\RuntimeException('RouteMatch does not contain a matched route name');
}
}
if (!is_array($params)) {
if (!$params instanceof Traversable) {
throw new Exception\InvalidArgumentException('Params is expected to be an array or a Traversable object');
}
$params = iterator_to_array($params);
}
if ($reuseMatchedParams && $this->routeMatch !== null) {
$routeMatchParams = $this->routeMatch->getParams();
if (isset($routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER])) {
$routeMatchParams['controller'] = $routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER];
unset($routeMatchParams[ModuleRouteListener::ORIGINAL_CONTROLLER]);
}
if (isset($routeMatchParams[ModuleRouteListener::MODULE_NAMESPACE])) {
unset($routeMatchParams[ModuleRouteListener::MODULE_NAMESPACE]);
}
$params = array_merge($routeMatchParams, $params);
}
$options['name'] = $name;
return $this->router->assemble($params, $options);
}
示例9: isActive
/**
* Returns whether page should be considered active or not
*
* This method will compare the page properties against the route matches
* composed in the object.
*
* @param bool $recursive [optional] whether page should be considered
* active if any child pages are active. Default is
* false.
* @return bool whether page should be considered active or not
*/
public function isActive($recursive = false)
{
if (!$this->active) {
$reqParams = array();
if ($this->routeMatch instanceof RouteMatch) {
$reqParams = $this->routeMatch->getParams();
if (isset($reqParams[ModuleRouteListener::ORIGINAL_CONTROLLER])) {
$reqParams['controller'] = $reqParams[ModuleRouteListener::ORIGINAL_CONTROLLER];
}
$pageParams = $this->params;
if (null !== $this->controller) {
$pageParams['controller'] = $this->controller;
}
if (null !== $this->action) {
$pageParams['action'] = $this->action;
}
if (null !== $this->getRoute()) {
if ($this->routeMatch->getMatchedRouteName() === $this->getRoute() && count(array_intersect_assoc($reqParams, $pageParams)) == count($pageParams)) {
$this->active = true;
return $this->active;
} else {
return parent::isActive($recursive);
}
}
}
$pageParams = $this->params;
if (null !== $this->controller) {
$pageParams['controller'] = $this->controller;
} else {
/**
* @todo In ZF1, this was configurable and pulled from the front controller
*/
$pageParams['controller'] = 'index';
}
if (null !== $this->action) {
$pageParams['action'] = $this->action;
} else {
/**
* @todo In ZF1, this was configurable and pulled from the front controller
*/
$pageParams['action'] = 'index';
}
if (count(array_intersect_assoc($reqParams, $pageParams)) == count($pageParams)) {
$this->active = true;
return true;
}
}
return parent::isActive($recursive);
}
示例10: getMatchedRoute
/**
* @param RouteMatch $matcher
* @return string
*/
public function getMatchedRoute(RouteMatch $matcher)
{
$routesToRedirect = $this->moduleOptions->getRedirectRoute();
if (is_string($routesToRedirect)) {
return $routesToRedirect;
}
$defaultRoute = '';
$matchedRoute = $matcher->getMatchedRouteName();
foreach ($routesToRedirect as $dependsOn => $route) {
if ($dependsOn === 0 || $dependsOn == 'default') {
$defaultRoute = $route;
continue;
}
if (preg_match('/^' . preg_quote($dependsOn) . '/', $matchedRoute)) {
return $route;
}
}
return $defaultRoute;
}
示例11: setRouteVariables
protected function setRouteVariables(RouteMatch $routeMatch)
{
$controller = $routeMatch->getParam('controller');
$controller = strtolower(substr($controller, strrpos($controller, '\\') + 1));
$action = $routeMatch->getParam('action');
$route = $routeMatch->getMatchedRouteName();
$setArray = ['route' => $route, 'controller' => $controller, 'action' => $action];
$alias = $routeMatch->getParam('alias');
if ($alias) {
$setArray['alias'] = $alias;
}
$id = $routeMatch->getParam('id');
if ($id) {
$setArray['id'] = $id;
}
$page = $routeMatch->getParam('page');
if ($page) {
$setArray['page'] = $page;
}
return $setArray;
}
示例12: translateRouteMatch
/**
* Translate a routematch
* Will be used by the Module bootstrap
*
* @param RouteMatch $routeMatch
* @return void
*/
public function translateRouteMatch(RouteMatch $routeMatch)
{
$params = $routeMatch->getParams();
$routeName = $routeMatch->getMatchedRouteName();
$result = $this->translate($routeName, self::NAMESPACE_ROUTE_MATCH);
if ($result === $routeName) {
return;
}
foreach ($params as $key => $value) {
$translateKey = "{$routeName}.{$key}.{$value}";
$result = $this->translate($translateKey, self::NAMESPACE_ROUTE_MATCH);
if ($result !== $translateKey) {
$routeMatch->setParam($key, $result);
}
}
}
示例13: testMatchedRouteNameIsSet
public function testMatchedRouteNameIsSet()
{
$match = new RouteMatch(array());
$match->setMatchedRouteName('foo');
$this->assertEquals('foo', $match->getMatchedRouteName());
}
示例14: formatRouteName
/**
* @param RouteMatch $routeMatch
* @return mixed
*/
protected function formatRouteName(RouteMatch $routeMatch)
{
$routeName = $routeMatch->getMatchedRouteName();
return $routeName;
}
示例15: marshalSuccessResultFromRouteMatch
/**
* Create a successful RouteResult from the given RouteMatch.
*
* @param RouteMatch $match
* @return RouteResult
*/
private function marshalSuccessResultFromRouteMatch(RouteMatch $match)
{
$params = $match->getParams();
if (array_key_exists(self::METHOD_NOT_ALLOWED_ROUTE, $params)) {
return RouteResult::fromRouteFailure($this->allowedMethodsByPath[$params[self::METHOD_NOT_ALLOWED_ROUTE]]);
}
return RouteResult::fromRouteMatch($this->getMatchedRouteName($match->getMatchedRouteName()), $params['middleware'], $params);
}