Create URL generator interface.

Also bind a default implementation to the container.
This commit is contained in:
Franz Liedke 2015-05-27 23:58:43 +02:00
parent bbd2625752
commit c4012ed718
3 changed files with 43 additions and 0 deletions

View File

@ -72,6 +72,11 @@ class CoreServiceProvider extends ServiceProvider
$this->app->singleton('flarum.formatter', 'Flarum\Core\Formatter\FormatterManager');
$this->app->bind(
'Flarum\Http\UrlGeneratorInterface',
'Flarum\Http\UrlGenerator'
);
$this->app->bind(
'Flarum\Core\Repositories\DiscussionRepositoryInterface',
'Flarum\Core\Repositories\EloquentDiscussionRepository'

View File

@ -0,0 +1,28 @@
<?php
namespace Flarum\Http;
class UrlGenerator implements UrlGeneratorInterface
{
protected $router;
public function __construct(Router $router)
{
$this->router = $router;
}
public function toRoute($name, $parameters = [])
{
$path = $this->router->getPath($name, $parameters);
$path = ltrim($path, '/');
// TODO: Prepend real base URL
return "/$path";
}
public function toAsset($path)
{
return "/$path";
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace Flarum\Http;
interface UrlGeneratorInterface
{
public function toRoute($name, $parameters = []);
public function toAsset($path);
}