Skip to content

Commit

Permalink
[FEATURE] Support env vars in YAML file names on import
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: TYPO3com <[email protected]>
Tested-by: Andreas Fernandez <[email protected]>
Reviewed-by: Mathias Brodala <[email protected]>
Reviewed-by: Andreas Fernandez <[email protected]>
  • Loading branch information
andreaskienast committed Nov 27, 2019
1 parent 58c1510 commit ba50c94
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ protected function processImports(array $content, ?string $fileName): array
{
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
imports:
- { resource: Secondfile.yml }

options:
- option1
- option2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loadedWithEnvVars: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
imports:
- { resource: Env_%env("foo")%.yml }

options:
- optionBefore
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,30 @@ public function loadWithPlaceholders(): void
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 [
Expand Down

0 comments on commit ba50c94

Please sign in to comment.