Not using config helper inside config file

This commit is contained in:
Guilherme Pressutto
2019-08-02 09:38:32 -03:00
parent c4422ce679
commit b3a93deda0
2 changed files with 10 additions and 4 deletions

View File

@@ -17,7 +17,7 @@ return [
* The base URL to be used in examples and the Postman collection.
* By default, this will be the value of config('app.url').
*/
'base_url' => config('app.url'),
'base_url' => null,
/*
* Generate a Postman collection in addition to HTML docs.

View File

@@ -42,6 +42,11 @@ class GenerateDocumentation extends Command
*/
private $docConfig;
/**
* @var string
*/
private $baseUrl;
public function __construct(RouteMatcher $routeMatcher)
{
parent::__construct();
@@ -60,9 +65,10 @@ class GenerateDocumentation extends Command
Flags::$shouldBeVerbose = $this->option('verbose');
$this->docConfig = new DocumentationConfig(config('apidoc'));
$this->baseUrl = $this->docConfig->get('base_url') ?? config('app.url');
try {
URL::forceRootUrl($this->docConfig->get('base_url'));
URL::forceRootUrl($this->baseUrl);
} catch (\Error $e) {
echo "Warning: Couldn't force base url as your version of Lumen doesn't have the forceRootUrl method.\n";
echo "You should probably double check URLs in your generated documentation.\n";
@@ -111,7 +117,7 @@ class GenerateDocumentation extends Command
$route['output'] = (string) view('apidoc::partials.route')
->with('route', $route)
->with('settings', $settings)
->with('baseUrl', $this->docConfig->get('base_url'))
->with('baseUrl', $this->baseUrl)
->render();
return $route;
@@ -288,7 +294,7 @@ class GenerateDocumentation extends Command
*/
private function generatePostmanCollection(Collection $routes)
{
$writer = new CollectionWriter($routes, $this->docConfig->get('base_url'));
$writer = new CollectionWriter($routes, $this->baseUrl);
return $writer->getCollection();
}