src/Router/UriGenerator.php
public function generate($name, array $params = [], $style = self::ABSOLUTE_URI)
	{
		if('/' !== substr($name, 0, 1))
		{
			$match = $this->context->getRouteMatch();
			
			if($match !== NULL)
			{
				$name = rtrim('/' . implode('/', explode('/', $match->getRouteName())), '/') . '/' . $name;
			}
		}
		
		$name = Filesystem::normalizePath('/' . trim($name, '/'));
		
		if($name === '/')
		{		
			switch($style)
			{
				case self::ABSOLUTE_PATH:
					return new UriInfo(rtrim('/' . $this->context->getRequest()->getPathBase(), '/') . '/');
				case self::ABSOLUTE_URI:
					return new UriInfo(rtrim($this->context->getRequest()->getBaseUri(), '/') . '/');
				case self::NETWORK_PATH:
					return new UriInfo(rtrim($this->context->getRequest()->getBaseUri()->setScheme(NULL), '/') . '/');
			}
			
			throw new \InvalidArgumentException(sprintf('Invalid URI generation style: "%s"', $style));
		}
		
		// Iterative route lookup:
		$router = $this->router;
		$info = NULL;
		
		foreach(explode('/', trim($name, '/')) as $step)
		{
			if($info === NULL)
			{
				$info = $router->getRoute($step);
			}
			else
			{
				$info = $info->append($router->getRoute($step));
			}
			
			$handler = $info->getHandler();
			
			if($handler instanceof DispatchableMountHandler)
			{
				break;
			}
			elseif($handler instanceof MountHandler)
			{
				if(NULL !== ($router = $handler->getRouter()))
				{
					continue;
				}
				
				$router = $this->dispatcher->publishUntil(new LoadMountedRouterEvent($handler), function($result) {
					return $result instanceof Router;
				});
				
				if($router === NULL)
				{
					throw new \RuntimeException(sprintf('No router could be loaded for mount %s', get_class($handler)));
				}
				
				$handler->setRouter($router);
			}
		}
		
		$info = $this->resolveParams($info, $params);
		
		if($style == self::ABSOLUTE_PATH)
		{
			return $info->prepend(rtrim('/' . $this->context->getRequest()->getPathBase(), '/'));
		}
		
		if($style == self::ABSOLUTE_URI)
		{
			return $info->prepend(rtrim($this->context->getRequest()->getBaseUri(), '/'));
		}
		
		if($style == self::NETWORK_PATH)
		{
			return $info->prepend(rtrim($this->context->getRequest()->getBaseUri()->setScheme(NULL), '/'));
		}
		
		throw new \InvalidArgumentException(sprintf('Invalid URI generation style: "%s"', $style));
	}
public function generate($name, array $params = [], $style = self::ABSOLUTE_URI)
	{
		if('/' !== substr($name, 0, 1))
		{
			$match = $this->context->getRouteMatch();
			
			if($match !== NULL)
			{
				$name = rtrim('/' . implode('/', explode('/', $match->getRouteName())), '/') . '/' . $name;
			}
		}
		
		$name = Filesystem::normalizePath('/' . trim($name, '/'));
		
		if($name === '/')
		{		
			switch($style)
			{
				case self::ABSOLUTE_PATH:
					return new UriInfo(rtrim('/' . $this->context->getRequest()->getPathBase(), '/') . '/');
				case self::ABSOLUTE_URI:
					return new UriInfo(rtrim($this->context->getRequest()->getBaseUri(), '/') . '/');
				case self::NETWORK_PATH:
					return new UriInfo(rtrim($this->context->getRequest()->getBaseUri()->setScheme(NULL), '/') . '/');
			}
			
			throw new \InvalidArgumentException(sprintf('Invalid URI generation style: "%s"', $style));
		}
		
		// Iterative route lookup:
		$router = $this->router;
		$info = NULL;
		
		foreach(explode('/', trim($name, '/')) as $step)
		{
			if($info === NULL)
			{
				$info = $router->getRoute($step);
			}
			else
			{
				$info = $info->append($router->getRoute($step));
			}
			
			$handler = $info->getHandler();
			
			if($handler instanceof DispatchableMountHandler)
			{
				break;
			}
			elseif($handler instanceof MountHandler)
			{
				if(NULL !== ($router = $handler->getRouter()))
				{
					continue;
				}
				
				$router = $this->dispatcher->publishUntil(new LoadMountedRouterEvent($handler), function($result) {
					return $result instanceof Router;
				});
				
				if($router === NULL)
				{
					throw new \RuntimeException(sprintf('No router could be loaded for mount %s', get_class($handler)));
				}
				
				$handler->setRouter($router);
			}
		}
		
		$info = $this->resolveParams($info, $params);
		
		if($style == self::ABSOLUTE_PATH)
		{
			return $info->prepend(rtrim('/' . $this->context->getRequest()->getPathBase(), '/'));
		}
		
		if($style == self::ABSOLUTE_URI)
		{
			return $info->prepend(rtrim($this->context->getRequest()->getBaseUri(), '/'));
		}
		
		if($style == self::NETWORK_PATH)
		{
			return $info->prepend(rtrim($this->context->getRequest()->getBaseUri()->setScheme(NULL), '/'));
		}
		
		throw new \InvalidArgumentException(sprintf('Invalid URI generation style: "%s"', $style));
	}
{@inheritdoc}