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:
71
src/Http/RouteCollectionUrlGenerator.php
Normal file
71
src/Http/RouteCollectionUrlGenerator.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user