https://github.com/codezero-be/dotenv-updater
⭐️ Update key/value pairs in a .env file in PHP.
https://github.com/codezero-be/dotenv-updater
dotenv editor env php updater
Last synced: 9 months ago
JSON representation
⭐️ Update key/value pairs in a .env file in PHP.
- Host: GitHub
- URL: https://github.com/codezero-be/dotenv-updater
- Owner: codezero-be
- License: mit
- Created: 2019-12-31T18:37:21.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-03-28T18:26:06.000Z (almost 2 years ago)
- Last Synced: 2025-03-25T21:47:14.344Z (10 months ago)
- Topics: dotenv, editor, env, php, updater
- Language: PHP
- Homepage:
- Size: 33.2 KB
- Stars: 5
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# PHP `.env` Updater
[](https://github.com/codezero-be/dotenv-updater/releases)
[](LICENSE.md)
[](https://github.com/codezero-be/dotenv-updater/actions)
[](https://app.codacy.com/gh/codezero-be/dotenv-updater)
[](https://packagist.org/packages/codezero/dotenv-updater)
[](https://ko-fi.com/R6R3UQ8V)
#### Update key/value pairs in a `.env` file.
## ✅ Requirements
- PHP >= 7.3
## 📦 Install
```bash
composer require codezero/dotenv-updater
```
## 🛠 Usage
Create an instance of the `DotEnvUpdater` and pass it the path to the `.env` file:
```php
$updater = new \CodeZero\DotEnvUpdater\DotEnvUpdater('/path/to/.env');
```
Add any new, or overwrite any existing key/value pairs:
```php
$updater->set('MY_ENV_KEY', 'Some Value'); // Strings
$updater->set('MY_ENV_KEY', 25); // Integers
$updater->set('MY_ENV_KEY', true); // Booleans
$updater->set('MY_ENV_KEY', null); // NULL values
$updater->set('MY_ENV_KEY', ''); // Empty values
```
Retrieve the value of a key:
```php
$value = $updater->get('MY_ENV_KEY');
```
## 🚧 Testing
```bash
composer test
```
## ☕️ Credits
- [Ivan Vermeyen](https://byterider.io)
- [All contributors](../../contributors)
## 🔓 Security
If you discover any security related issues, please [e-mail me](mailto:ivan@codezero.be) instead of using the issue tracker.
## 📑 Changelog
A complete list of all notable changes to this package can be found on the
[releases page](https://github.com/codezero-be/dotenv-updater/releases).
## 📜 License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.