Skip to content

Instantly share code, notes, and snippets.

@andyexeter
Last active April 18, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyexeter/8dc76743bc2b062d6635e70244cb2653 to your computer and use it in GitHub Desktop.
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
<?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