1
0
mirror of https://github.com/flarum/core.git synced 2025-08-02 14:37:49 +02:00

Combine URL generator classes into one

This commit is contained in:
Franz Liedke
2017-06-25 23:33:02 +02:00
parent f824dcfb53
commit b72407440d
19 changed files with 104 additions and 111 deletions

View File

@@ -0,0 +1,71 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Http;
class RouteCollectionUrlGenerator
{
/**
* @var string|null
*/
protected $baseUrl;
/**
* @var RouteCollection
*/
protected $routes;
/**
* @param string $baseUrl
* @param RouteCollection $routes
*/
public function __construct($baseUrl, RouteCollection $routes)
{
$this->baseUrl = $baseUrl;
$this->routes = $routes;
}
/**
* Generate a URL to a named route.
*
* @param string $name
* @param array $parameters
* @return string
*/
public function route($name, $parameters = [])
{
$path = $this->routes->getPath($name, $parameters);
$path = ltrim($path, '/');
return $this->baseUrl.'/'.$path;
}
/**
* Generate a URL to a path.
*
* @param string $path
* @return string
*/
public function path($path)
{
return $this->baseUrl.'/'.$path;
}
/**
* Generate a URL to base with UrlGenerator's prefix.
*
* @return string
*/
public function base()
{
return $this->baseUrl;
}
}