1
0
mirror of https://github.com/flarum/core.git synced 2025-10-12 23:44:27 +02:00
Files
php-flarum/src/Http/AbstractUrlGenerator.php
2016-02-25 22:09:39 -05:00

79 lines
1.4 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;
use Flarum\Foundation\Application;
class AbstractUrlGenerator
{
/**
* @var Application
*/
protected $app;
/**
* @var RouteCollection
*/
protected $routes;
/**
* @var string|null
*/
protected $path;
/**
* @param Application $app
* @param RouteCollection $routes
*/
public function __construct(Application $app, RouteCollection $routes)
{
$this->app = $app;
$this->routes = $routes;
}
/**
* Generate a URL to a named route.
*
* @param string $name
* @param array $parameters
* @return string
*/
public function toRoute($name, $parameters = [])
{
$path = $this->routes->getPath($name, $parameters);
$path = ltrim($path, '/');
return $this->toBase().'/'.$path;
}
/**
* Generate a URL to a path.
*
* @param string $path
* @return string
*/
public function toPath($path)
{
return $this->toBase().'/'.$path;
}
/**
* Generate a URL to base with UrlGenerator's prefix.
*
* @return string
*/
public function toBase()
{
return $this->app->url($this->path);
}
}