mirror of
https://github.com/flarum/core.git
synced 2025-07-28 20:20:34 +02:00
72 lines
1.3 KiB
PHP
72 lines
1.3 KiB
PHP
<?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;
|
|
}
|
|
}
|