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'); } /** @psalm-suppress RedundantCastGivenDocblockType */ $name = (string) $this->routeMatch->getMatchedRouteName(); if ($name === '') { 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 (string) $this->router->assemble($params, $options); } /** * Set the router to use for assembling. * * @param RouteStackInterface $router * @return Url * @throws Exception\InvalidArgumentException For invalid router types. * @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */ public function setRouter($router) { if (! $router instanceof RouteStackInterface) { throw new Exception\InvalidArgumentException(sprintf( '%s expects a %s instance; received %s', __METHOD__, RouteStackInterface::class, is_object($router) ? get_class($router) : gettype($router) )); } $this->router = $router; return $this; } /** * Set route match returned by the router. * * @param RouteMatch $routeMatch * @return Url * @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */ public function setRouteMatch($routeMatch) { if (! $routeMatch instanceof RouteMatch) { throw new Exception\InvalidArgumentException(sprintf( '%s expects a %s instance; received %s', __METHOD__, RouteMatch::class, is_object($routeMatch) ? get_class($routeMatch) : gettype($routeMatch) )); } $this->routeMatch = $routeMatch; return $this; } }