Last active
April 18, 2020 16:16
-
-
Save andyexeter/8dc76743bc2b062d6635e70244cb2653 to your computer and use it in GitHub Desktop.
Take env vars from a Symfony parameters.yml.dist file and put them in a .env.dist file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
$yaml = \Symfony\Component\Yaml\Yaml\Yaml::parseFile(__DIR__ . '/app/config/parameters.yml.dist'); | |
$lines = []; | |
foreach ($yaml['parameters'] as $key => $value) { | |
if (strpos($key, 'env(') === 0 && substr($key, -1) === ')' && $key !== 'env()') { | |
$lines[] = substr($key, 4, -1) . '=' . "'$value'"; | |
} | |
} | |
file_put_contents('.env.dist', implode(PHP_EOL, $lines) . PHP_EOL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment