Skip to content

Commit 55e2249

Browse files
committed
[FEATURE] Add support for dumped .env files
This only adds an adapter to load the result. It does not integrate the dump command. Relates: helhum#27
1 parent be11835 commit 55e2249

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,19 @@ This may be the case if you use hashed values of credentials you pass via `.env`
5656
You can specify a class that implements `\Helhum\DotEnvConnector\DotEnvVars` interface,
5757
if you need a different way to expose env vars.
5858

59-
*The default value* is "Helhum\DotEnvConnector\Adapter\SymfonyDotEnv",
59+
*The default value* is `"Helhum\DotEnvConnector\Adapter\SymfonyDotEnv"`,
6060
which uses symfony/dotenv default parsing of the one .env file.
6161

6262
This could be useful though e.g. if you prefer to use another dotenv parsing library to expose the variables defined in .env
6363
or you want to switch to another parsing strategy of the Symfony dotenv parsing. In the latter case use
64-
"Helhum\DotEnvConnector\Adapter\SymfonyLoadEnv" as value for this option.
64+
`"Helhum\DotEnvConnector\Adapter\SymfonyLoadEnv"` as value for this option.
65+
66+
To additional support dumped .env settings, use the adapter `"\Helhum\DotEnvConnector\Adapter\SymfonyBootEnv"`.
67+
This allows to load a PHP file instead, compiled from all .env* files in the environment.
68+
*Important*: The command `dump-env` needed for compiling the PHP file, is not registered by default.
69+
See the section [Configuring Environment Variables in Production](https://symfony.com/doc/current/configuration.html#configuring-environment-variables-in-production)
70+
of the symfony documentation for details.
71+
6572
Have a look at the existing implementations for examples.
6673

6774
## Feedback

src/Adapter/SymfonyBootEnv.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Helhum\DotEnvConnector\Adapter;
5+
6+
use Helhum\DotEnvConnector\DotEnvVars;
7+
use Symfony\Component\Dotenv\Dotenv;
8+
9+
class SymfonyBootEnv implements DotEnvVars
10+
{
11+
public function exposeToEnvironment(string $dotEnvFile): void
12+
{
13+
if (is_file($dotEnvFile) || is_file("$dotEnvFile.dist")) {
14+
$dotEnv = new Dotenv();
15+
$dotEnv->usePutenv();
16+
$dotEnv->bootEnv($dotEnvFile);
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)