1
0
mirror of https://github.com/flarum/core.git synced 2025-05-05 23:15:22 +02:00

#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 class UrlGenerator extends AbstractUrlGenerator
{ {
/**
* {@inheritdoc}
*/
protected $prefix = 'api'; protected $prefix = 'api';
} }

View File

@ -30,6 +30,11 @@ class AbstractUrlGenerator
*/ */
protected $path; protected $path;
/**
* @var string
*/
protected $prefix = '';
/** /**
* @param Application $app * @param Application $app
* @param RouteCollection $routes * @param RouteCollection $routes
@ -67,12 +72,18 @@ class AbstractUrlGenerator
} }
/** /**
* Get the base URL. * Generate a URL to base with UrlGenerator's prefix.
* *
* @return string * @return string
*/ */
public function toBase() 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;
}
} }
} }