mirror of
https://github.com/flarum/framework.git
synced 2024-12-11 21:43:38 +08:00
Create URL generator interface.
Also bind a default implementation to the container.
This commit is contained in:
parent
bbd2625752
commit
c4012ed718
|
@ -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'
|
||||
|
|
28
framework/core/src/Http/UrlGenerator.php
Normal file
28
framework/core/src/Http/UrlGenerator.php
Normal 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";
|
||||
}
|
||||
}
|
10
framework/core/src/Http/UrlGeneratorInterface.php
Normal file
10
framework/core/src/Http/UrlGeneratorInterface.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Flarum\Http;
|
||||
|
||||
interface UrlGeneratorInterface
|
||||
{
|
||||
public function toRoute($name, $parameters = []);
|
||||
|
||||
public function toAsset($path);
|
||||
}
|
Loading…
Reference in New Issue
Block a user