[FEATURE] Support env vars in YAML file names on import 55/61955/7
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 11 Oct 2019 12:02:32 +0000 (14:02 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 27 Nov 2019 09:49:36 +0000 (10:49 +0100)
To have a variable import chain per environment (dev, stage etc) for
example, YAML files now may contain environment variables.

Resolves: #89398
Releases: master
Change-Id: I274c8e78f1a072ba490f4844d545b3015f658409
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61955
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/Configuration/Loader/YamlFileLoader.php
typo3/sysext/core/Documentation/Changelog/master/Feature-89398-SupportForEnvironmentVariablesInImportsInSiteConfigurations.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Berta.yml [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Env_barbaz.yml [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Secondfile.yml [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Configuration/Loader/YamlFileLoaderTest.php

index 41f9637..cd8770f 100644 (file)
@@ -167,6 +167,7 @@ class YamlFileLoader
     {
         if (isset($content['imports']) && is_array($content['imports'])) {
             foreach ($content['imports'] as $import) {
+                $import = $this->processPlaceholders($import, $import);
                 $importedContent = $this->loadAndParse($import['resource'], $fileName);
                 // override the imported content with the one from the current file
                 $content = ArrayUtility::replaceAndAppendScalarValuesRecursive($importedContent, $content);
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-89398-SupportForEnvironmentVariablesInImportsInSiteConfigurations.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-89398-SupportForEnvironmentVariablesInImportsInSiteConfigurations.rst
new file mode 100644 (file)
index 0000000..c6c6839
--- /dev/null
@@ -0,0 +1,28 @@
+.. include:: ../../Includes.txt
+
+=====================================================================================
+Feature: #89398 - Support for environment variables in imports in site configurations
+=====================================================================================
+
+See :issue:`89398`
+
+Description
+===========
+
+Environment variables are now resolved in imports of site configuration YAML files.
+
+Example:
+
+.. code-block:: yaml
+
+   imports:
+     -
+       resource: 'Env_%env("foo")%.yaml'
+
+
+Impact
+======
+
+It is now possible to use environment variables in imports of site configuration yaml files.
+
+.. index:: Backend, ext:backend
diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Berta.yml b/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Berta.yml
new file mode 100644 (file)
index 0000000..5f8748c
--- /dev/null
@@ -0,0 +1,6 @@
+imports:
+    - { resource: Secondfile.yml }
+
+options:
+    - option1
+    - option2
diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Env_barbaz.yml b/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Env_barbaz.yml
new file mode 100644 (file)
index 0000000..3832d25
--- /dev/null
@@ -0,0 +1 @@
+loadedWithEnvVars: 1
diff --git a/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Secondfile.yml b/typo3/sysext/core/Tests/Unit/Configuration/Loader/Fixtures/Env/Secondfile.yml
new file mode 100644 (file)
index 0000000..8f9b401
--- /dev/null
@@ -0,0 +1,5 @@
+imports:
+    - { resource: Env_%env("foo")%.yml }
+
+options:
+    - optionBefore
index db53413..45439fb 100644 (file)
@@ -150,6 +150,30 @@ betterthanbefore: \'%firstset.myinitialversion%\'
         self::assertSame($expected, $output);
     }
 
+    /**
+     * Method checking for imports with env vars that they have been processed properly
+     * @test
+     */
+    public function loadWithImportAndEnvVars(): void
+    {
+        $loader = new YamlFileLoader();
+
+        putenv('foo=barbaz');
+        $output = $loader->load(__DIR__ . '/Fixtures/Env/Berta.yml');
+        putenv('foo=');
+
+        $expected = [
+            'loadedWithEnvVars' => 1,
+            'options' => [
+                'optionBefore',
+                'option1',
+                'option2',
+            ],
+        ];
+
+        self::assertSame($expected, $output);
+    }
+
     public function loadWithEnvVarDataProvider(): array
     {
         return [