Jelajahi Sumber

Replace `env` section with `config`

This is because Laravel loads values from the .env file before the generator has a chance to run, so env variables set there can't be changed. Also, the `env` helper caches variables. So the `env` section wasn't really changing any env variables.
shalvah 6 tahun lalu
induk
melakukan
68cd100065
2 mengubah file dengan 27 tambahan dan 8 penghapusan
  1. 8 7
      config/apidoc.php
  2. 19 1
      src/Tools/ResponseStrategies/ResponseCallStrategy.php

+ 8 - 7
config/apidoc.php

@@ -103,7 +103,7 @@ return [
                 /*
                  * If no @response or @transformer declarations are found for the route,
                  * we'll try to get a sample response by attempting an API call.
-                 * Configure the settings for the API call here,
+                 * Configure the settings for the API call here.
                  */
                 'response_calls' => [
                     /*
@@ -122,14 +122,15 @@ return [
                     ],
 
                     /*
-                     * Environment variables which should be set for the API call.
+                     * Laravel config variables which should be set for the API call.
                      * This is a good place to ensure that notifications, emails
-                     * and other external services are not triggered during the documentation API calls
+                     * and other external services are not triggered
+                     * during the documentation API calls
                      */
-                    'env' => [
-                        'APP_ENV' => 'documentation',
-                        'APP_DEBUG' => false,
-                        // 'env_var' => 'value',
+                    'config' => [
+                        'app.env' => 'documentation',
+                        'app.debug' => false,
+                        // 'service.key' => 'value',
                     ],
 
                     /*

+ 19 - 1
src/Tools/ResponseStrategies/ResponseCallStrategy.php

@@ -52,6 +52,7 @@ class ResponseCallStrategy
     {
         $this->startDbTransaction();
         $this->setEnvironmentVariables($rulesToApply['env'] ?? []);
+        $this->setLaravelConfigs($rulesToApply['config'] ?? []);
     }
 
     /**
@@ -103,9 +104,10 @@ class ResponseCallStrategy
     }
 
     /**
-     * @param array $env
+     * @param array $config
      *
      * @return void
+     * @deprecated in favour of Laravel config variables
      */
     private function setEnvironmentVariables(array $env)
     {
@@ -117,6 +119,22 @@ class ResponseCallStrategy
         }
     }
 
+    /**
+     * @param array $config
+     *
+     * @return void
+     */
+    private function setLaravelConfigs(array $config)
+    {
+        if (empty($config)) {
+            return;
+        }
+
+        foreach ($config as $name => $value) {
+            config([$name => $value]);
+        }
+    }
+
     /**
      * @return void
      */