Download the PHP package thegr8dev/dotenv-editor without Composer
On this page you can find all versions of the php package thegr8dev/dotenv-editor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download thegr8dev/dotenv-editor
More information about thegr8dev/dotenv-editor
Files in thegr8dev/dotenv-editor
Package dotenv-editor
Short Description The .env file editor tool for Laravel 5.8+
License MIT
Informations about the package dotenv-editor
Laravel Dotenv Editor
Laravel Dotenv Editor is the .env file editor (or files with same structure and syntax) for Laravel 5.8+. Now you can easily edit .env files with the following features:
- Read raw content of file.
- Read lines of file content.
- Read setters (key-value-pair) of file content.
- Determine one key name of existing setter.
- Append empty lines to file.
- Append comment lines to file.
- Append new or update exists setter lines to file.
- Delete existing setter line in file.
- Backup and restore file.
- Manage backup files.
Versions and compatibility
Laravel Dotenv Editor is compatible with Laravel 5+ and above. Since the release of 1.2.0
onwards, this package only supports Laravel 5.8 and later. Previous versions of Laravel will no longer be supported.
Note for the release 1.2.0
and later
Starting with the release 1.2.0
, the .gitignore file in the folder containing the backup file will no longer be created automatically. Developers will have to create this file manually if deemed necessary.
Documentation
Look at one of the following topics to learn more about Laravel Dotenv Editor:
- Installation
- Configuration
- Auto backup mode
- Backup location
- Always create backup folder
- Usage
- Working with facade
- Using dependency injection
- Loading file for working
- Reading file content
- Writing content into file
- Backing up and restoring file
- Method chaining
- Working with Artisan CLI
- Exceptions
Installation
You can install this package through Composer with the following steps:
Step 1 - Require package
At the root of your application directory, run the following command (in any terminal client):
Note: Since Laravel 5.5, service providers and aliases are automatically registered, so you can safely skip the following two steps:
Step 2 - Register service provider
Open config/app.php
, and add a new line to the providers section:
Step 3 - Register facade
Add the following line to the aliases section in file config/app.php
:
Configuration
To start using the package, you should publish the configuration file so that you can configure the package as needed. To do that, run the following command (in any terminal client) at the root of your application:
This will create a config/dotenv-editor.php
file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases. Currently there are the following settings:
Auto backup mode
The autoBackup
setting allows your original file to be backed up automatically before saving. Set it to true
to agree.
Backup location
The backupPath
setting is used to specify where your file is backed up. This value is a sub path (sub-folder) from the root folder of the project application.
Always create backup folder
The alwaysCreateBackupFolder
setting is used to request that the backup folder always be created, whether or not the backup is performed.
Usage
Working with facade
Laravel Dotenv Editor has a facade with the name Jackiedo\DotenvEditor\Facades\DotenvEditor
. You can perform all operations through this facade.
Example:
Using dependency injection
This package also supports dependency injection. You can easily inject an instance of the Jackiedo\DotenvEditor\DotenvEditor
class into your controller or other classes.
Example:
Loading file for working
By default, Laravel Dotenv Editor will load the .env
file in the root of your project. Example:
However, if you want to explicitly specify the files you are going to work with, you should use the load()
method.
Method syntax:
Example:
Note: The load()
method has three parameters:
$filePath
: The path to the file you want to work with. Setnull
to work with the file.env
in the root folder.$restoreIfNotFound
: Allows to restore your file if it is not found.$restorePath
: The path to the file used to restoring. Setnull
to restore from an older backup file.
Reading file content
Reading raw content.
Method syntax:
Example:
Reading content by lines.
Method syntax:
Example:
Note: This will return an array. Each element in the array consists of the following items:
- Number of the line.
- Raw content of the line.
- Parsed content of the line, including: type of line (empty, comment, setter...), key name of setter, value of setter, comment of setter...
Reading content by keys
Method syntax:
Example:
Note: This will return an array. Each element in the array consists of the following items:
- Number of the line.
- Key name of the setter.
- Value of the setter.
- Comment of the setter.
- If this key is used for the "export" command or not.
Determine if a key exists
Method syntax:
Example:
Get value of a key
Method syntax:
Example:
Writing content into a file
To edit file content, you have two jobs:
- First is writing content into the buffer
- Second is saving the buffer into the file
Add an empty line into buffer
Method syntax:
Example:
Add a comment line into buffer
Method syntax:
Example:
Add or update a setter into buffer
Method syntax:
Example:
Add or update multi setter into buffer
Method syntax:
Example:
Alternatively, you can also provide an associative array of keys and values:
Delete a setter line in buffer
Method syntax:
Example:
Delete multi setter lines in buffer
Method syntax:
Example:
Save buffer into file
Method syntax:
Example:
Backing up and restoring file
Backup your file
Method syntax:
Example:
Get all backup versions
Method syntax:
Example:
Get latest backup version
Method syntax:
Example:
Restore your file from latest backup or other file
Method syntax:
Example:
Delete one backup file
Method syntax:
Example:
Delete multi backup files
Method syntax:
Example:
Change auto backup mode
Method syntax:
Example:
Method chaining
Some functions of loading, writing, backing up, restoring support method chaining. So these functions can be called chained together in a single statement. Example:
Working with Artisan CLI
Now, Laravel Dotenv Editor has 6 commands which can be used easily with the Artisan CLI. These are:
php artisan dotenv:backup
php artisan dotenv:get-backups
php artisan dotenv:restore
php artisan dotenv:get-keys
php artisan dotenv:set-key
php artisan dotenv:delete-key
Please use each of the commands with the --help
option to leanr more about there usage.
Example:
Exceptions
This package will throw exceptions if something goes wrong. This way it's easier to debug your code using this package or to handle the error based on the type of exceptions.
Exception | Reason |
---|---|
FileNotFoundException | When the file was not found. |
InvalidValueException | When the value of setter is invalid. |
KeyNotFoundException | When the requested key does not exist in file. |
NoBackupAvailableException | When no backup file exists. |
UnableReadFileException | When unable to read the file. |
UnableWriteToFileException | When unable to write to the file. |
Contributors
This project exists thanks to all its contributors.
License
MIT © Jackie Do
All versions of dotenv-editor with dependencies
illuminate/contracts Version ^5.8|^6.0|^7.0|^8.0|^9.0
illuminate/support Version ^5.8|^6.0|^7.0|^8.0|^9.0