Last active
November 6, 2018 17:14
-
-
Save GregoireHebert/3e6feeade4f1eb4035aa25c09285fb01 to your computer and use it in GitHub Desktop.
DotenvUpdater
This file contains 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
#!/usr/bin/env php | |
<?php | |
declare(strict_types=1); | |
foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) { | |
if (file_exists($file)) { | |
require $file; break; | |
} | |
} | |
$dotenv = new \Symfony\Component\Dotenv\Dotenv(); | |
$text = 'This will add new entries to your Dotenv file, but won\'t update existing ones...' . PHP_EOL; | |
echo sprintf("\033[%sm%s\033[%sm", implode(';', ['34']), $text, implode(';', ['39'])); | |
$environment = array_merge( | |
$dotenv->parse(file_get_contents(__DIR__ . '/../.env.dist'), __DIR__ . '/../.env.dist'), | |
$dotenv->parse(file_get_contents(__DIR__ . '/../.env'), __DIR__ . '/../.env') | |
); | |
file_put_contents(__DIR__ . '/../.env', implode(PHP_EOL, array_map(function ($v, $k) { | |
return sprintf("%s='%s'", $k, $v); | |
}, | |
$environment, | |
array_keys($environment) | |
))); | |
$text = 'Dotenv file successfully updated!' . PHP_EOL; | |
echo sprintf("\033[%sm%s\033[%sm", implode(';', ['32']), $text, implode(';', ['39'])); | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put this on you
bin
directory and set it executable.