diff --git a/framework/core/src/Api/UrlGenerator.php b/framework/core/src/Api/UrlGenerator.php index 748e218de..003d2d607 100644 --- a/framework/core/src/Api/UrlGenerator.php +++ b/framework/core/src/Api/UrlGenerator.php @@ -14,5 +14,8 @@ use Flarum\Http\AbstractUrlGenerator; class UrlGenerator extends AbstractUrlGenerator { + /** + * {@inheritdoc} + */ protected $prefix = 'api'; } diff --git a/framework/core/src/Http/AbstractUrlGenerator.php b/framework/core/src/Http/AbstractUrlGenerator.php index e905fdbf9..1d0426984 100644 --- a/framework/core/src/Http/AbstractUrlGenerator.php +++ b/framework/core/src/Http/AbstractUrlGenerator.php @@ -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; + } } }