Download the PHP package benfiratkaya/laravel-setenv without Composer
On this page you can find all versions of the php package benfiratkaya/laravel-setenv. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download benfiratkaya/laravel-setenv
More information about benfiratkaya/laravel-setenv
Files in benfiratkaya/laravel-setenv
Package laravel-setenv
Short Description A .env editor for Laravel
License MIT
Homepage https://dacoto.github.io/laravel-setenv/
Informations about the package laravel-setenv
Laravel .env editor
Inspired by JackieDo/Laravel-Dotenv-Editor, it is a simplified version without a visual editor.
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:
Usage
Working with facade
Laravel Set Env has a facade with the name dacoto\SetEnv\Facades\SetEnv
. 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 dacoto\SetEnv
class into your controller or other classes.
Example:
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:
Note: To apply the changes to the file, you have to save it with the save method.
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:
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. |
UnableReadFileException | When unable to read the file. |
UnableWriteToFileException | When unable to write to the file. |
License
MIT © 2022 dacoto