mirror of
https://github.com/flarum/core.git
synced 2025-07-26 11:10:41 +02:00
Create URL generator interface.
Also bind a default implementation to the container.
This commit is contained in:
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);
|
||||
}
|
Reference in New Issue
Block a user