Closed nostadt closed 3 years ago
Thanks for reaching out.
However it is hard to help without knowing what exactly you need, what you tried and what exact alternatives you are now considering.
Please post a composer.json config with a verbose description what you expect and what actually happens
I've a TYPO3 instance with version 10 and helhum/dotenv-connector (v3.0.0)
required. In my project root .env
file exists.
This file contains currently a MySQL config and the TYPO3_CONTEXT.
The dot env config In the composer.json
file looks like this:
"helhum/dotenv-connector": {
"adapter": "Helhum\\DotEnvConnector\\Adapter\\SymfonyDotEnv",
"env-file": ".env"
},
What I want to achieve is:
.env.local
(works with your package).env
file..env.local
fileWhat I have tried is to use the symfony package directly and load the files accordingly via AdditionalConfiguration.php
.
(function() {
$root = __DIR__ . '/../../';
$dotenv = new \Symfony\Component\Dotenv\Dotenv();
$dotenv->usePutenv(true);
$dotenv->load($root . '.env');
if (file_exists($root . '.env.local')) {
$dotenv->overload($root . '.env.local');
}
})();
While it reaches my goal with a local env file, it does not apply the TYPO3_CONTEXT.
What I have found is a method exposeToEnvironment
which will be used in a composer plugin and I am pretty sure this is the reason why the TYPO3_CONTEXT will be applied with your package.
public function exposeToEnvironment(string $dotEnvFile): void
{
if (!getenv('APP_ENV') && file_exists($dotEnvFile)) {
$dotEnv = new Dotenv();
$dotEnv->usePutenv();
$dotEnv->load($dotEnvFile);
$dotEnv->overload($dotEnvFile.'.local');
}
}
After adding $dotEnv->overload($dotEnvFile.'.local');
all my goals are achieved.
Yet, before implementing the wheel again I would like to know whether there is a config option by your package I have missed.
Okay, I figured out one can include own files using composer. I have created ./env-loader.php
and include this in the autoloader section of my composer file, which does the magic for me and it's early enough apparently.
Did you read and understand the section about adapters in the readme?
From what I read from your description, I'm not completely sure.
From what I grasp, the following configuration should do exactly what you want, without writing a single line of code anywhere.
"helhum/dotenv-connector": {
"adapter": "Helhum\\DotEnvConnector\\Adapter\\SymfonyLoadEnv"
},
Please also refer to the Symfony docs on how you can use multiple env files and how they override each other with this configuration.
I am currently trying to implement a hierarchy where first
.env
and then.env.local
should be loaded. I don't get it to work though and from what I see it's not supported by this package. Is this true? Should I write my own Adapter or what is the best practice go to?Best regards and thanks for your effort you put into the public packages!
Alex