Skip to content

Load Variables from array instead of .env file #50

@jan-di

Description

@jan-di

I am wondering if it is possible to load a list of key value pairs from an array instead of a file. To explain why I want to do this, i'll explain my use case (basicly caching the config to enable opcache performance gains):

First Request:

  • Load/parse .env file normally
  • (IF environment = production): Extract config as array (with toArray()) and store it as php file with var_export
  • Populate $_ENV, $_SERVER, ...

Next Request:

  • The .env file isn't parsed because the php-cache file with the array is required instead.
  • A DotEnv Loader is created and filled with the variables from the cache file.
  • Populate $_ENV, $_SERVER, ...

-> In both cases i could proceeed the same way, no matter where the variables came from (checking Expections, put them to $_ENV etc.).

Currently I haven't found a way to load the variables from an array to work with them the same way as I do with the .env-loaded variables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions