Parcourir la source

Not using config helper inside config file

Guilherme Pressutto il y a 5 ans
Parent
commit
b3a93deda0
2 fichiers modifiés avec 10 ajouts et 4 suppressions
  1. 1 1
      config/apidoc.php
  2. 9 3
      src/Commands/GenerateDocumentation.php

+ 1 - 1
config/apidoc.php

@@ -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.

+ 9 - 3
src/Commands/GenerateDocumentation.php

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