Download the PHP package oohology/dotenvwriter without Composer
On this page you can find all versions of the php package oohology/dotenvwriter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package dotenvwriter
DotEnvWriter
Interface for editing .env files in PHP
Note: This is probably not advisable for use in production, but could be handy for automating installation tasks, etc.
Basic Usage
In general, you will open a .env file, use the set
method to append or replace some
values, and then call the save
method to write the result.
Open an environment file and replace a value:
Also supports fluent interface:
Output File
There are multiple ways to read from a source file, make some changes, and write the result to a different output file. The end result is the same, so choose whichever method best fits your use case:
Or alternately:
Or using the load()
method:
Comments
The set()
method takes a $comments
parameter. If omitted (or set to null
), any existing comment from the source file with be kept intact. If a $comment
is provided it will overwrite the existing comment. Providing a zero-length $comment
will cause the comment to be deleted.
Examples: Set a comment
Delete a comment
Keep existing comment
Export
The parser supports a bash-style export
prefix on any line. The set()
method
takes an $export
variable as its 4th argument.
Example:
By default, keep the existing state
Or change it by passing a boolean
Casting booleans
By default boolean values will not be stored as true
or false
.
To enable casting booleans you should call the castBooleans()
method.
Example:
Default behaviour
After calling castBooleans()
method
Read the Value of a Variable
The get
method allows you to find the value of an existing given environment
variable. It returns false if the variable doesn't exist, or an array containing
the details of the line from the source file.
Source:
export ENV="dev" # dev or live?
Get command:
$writer->get('ENV');
Result:
Writing Blank/Comment Lines
The line
method appends a single unprocessed line of output to the file. It could be used
to insert blank lines or comments. If you wish to append a new variable, the
set
method should be used instead to prevent duplicates.