20

I wish to read and use information stored in my env.php. Is there an entity that I can use to achieve this?

Any tips are highly appreciated. Thanks.

1 Answer 1

37

Have a look at \Magento\Framework\App\DeploymentConfig:

Inject a deployment config object of \Magento\Framework\App\DeploymentConfig in your code

private DeploymentConfig $deploymentConfig;

public function __construct(DeploymentConfig $deploymentConfig) {
    $this->deploymentConfig = $deploymentConfig;
}

Then retrieve the value like this:

$this->deploymentConfig->get('db/connection/default/host'));

for example:

$this->deploymentConfig->get('your/custom/value'));

For default values, see Magento's deployment configuration.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.