mirror of
https://github.com/flarum/framework.git
synced 2024-11-24 17:12:13 +08:00
#696 Added support for prefixes in AbstractUrlGenerator.
This commit is contained in:
parent
5bbcba6332
commit
096aae7919
|
@ -14,5 +14,8 @@ use Flarum\Http\AbstractUrlGenerator;
|
|||
|
||||
class UrlGenerator extends AbstractUrlGenerator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $prefix = 'api';
|
||||
}
|
||||
|
|
|
@ -30,6 +30,11 @@ class AbstractUrlGenerator
|
|||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix = '';
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
* @param RouteCollection $routes
|
||||
|
@ -67,12 +72,18 @@ class AbstractUrlGenerator
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the base URL.
|
||||
* Generate a URL to base with UrlGenerator's prefix.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toBase()
|
||||
{
|
||||
return $this->app->url($this->path);
|
||||
$base = $this->app->url($this->path);
|
||||
|
||||
if (empty($this->prefix)) {
|
||||
return $base;
|
||||
} else {
|
||||
return $base . '/' . $this->prefix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user