From 096aae79191df4d03a72ae7e4ebc6a1e7d09546a Mon Sep 17 00:00:00 2001 From: Albert221 Date: Mon, 4 Jan 2016 15:11:28 +0100 Subject: [PATCH] #696 Added support for prefixes in AbstractUrlGenerator. --- src/Api/UrlGenerator.php | 3 +++ src/Http/AbstractUrlGenerator.php | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Api/UrlGenerator.php b/src/Api/UrlGenerator.php index 748e218de..003d2d607 100644 --- a/src/Api/UrlGenerator.php +++ b/src/Api/UrlGenerator.php @@ -14,5 +14,8 @@ use Flarum\Http\AbstractUrlGenerator; class UrlGenerator extends AbstractUrlGenerator { + /** + * {@inheritdoc} + */ protected $prefix = 'api'; } diff --git a/src/Http/AbstractUrlGenerator.php b/src/Http/AbstractUrlGenerator.php index e905fdbf9..1d0426984 100644 --- a/src/Http/AbstractUrlGenerator.php +++ b/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; + } } }