#696 Added support for prefixes in AbstractUrlGenerator.

This commit is contained in:
Albert221 2016-01-04 15:11:28 +01:00
parent 5bbcba6332
commit 096aae7919
2 changed files with 16 additions and 2 deletions

View File

@ -14,5 +14,8 @@ use Flarum\Http\AbstractUrlGenerator;
class UrlGenerator extends AbstractUrlGenerator
{
/**
* {@inheritdoc}
*/
protected $prefix = 'api';
}

View File

@ -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;
}
}
}