{"id":20812438,"url":"https://github.com/markwalet/dotenv-manager","last_synced_at":"2025-10-11T22:18:42.422Z","repository":{"id":32780698,"uuid":"142404454","full_name":"markwalet/dotenv-manager","owner":"markwalet","description":"A PHP package that helps you edit the .env file programmatically.","archived":false,"fork":false,"pushed_at":"2023-07-06T18:11:20.000Z","size":72,"stargazers_count":9,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-14T21:14:29.532Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markwalet.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"markwalet","custom":["https://www.paypal.me/markwalet"]}},"created_at":"2018-07-26T07:23:31.000Z","updated_at":"2023-01-24T09:28:48.000Z","dependencies_parsed_at":"2023-10-12T06:15:06.656Z","dependency_job_id":null,"html_url":"https://github.com/markwalet/dotenv-manager","commit_stats":{"total_commits":91,"total_committers":2,"mean_commits":45.5,"dds":"0.19780219780219777","last_synced_commit":"4d4480823aa6380b9ba15518f6003131f2aaee5e"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/markwalet/dotenv-manager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markwalet%2Fdotenv-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markwalet%2Fdotenv-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markwalet%2Fdotenv-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markwalet%2Fdotenv-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markwalet","download_url":"https://codeload.github.com/markwalet/dotenv-manager/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markwalet%2Fdotenv-manager/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279009047,"owners_count":26084547,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T20:54:28.802Z","updated_at":"2025-10-11T22:18:42.409Z","avatar_url":"https://github.com/markwalet.png","language":"PHP","funding_links":["https://github.com/sponsors/markwalet","https://www.paypal.me/markwalet"],"categories":[],"sub_categories":[],"readme":"[![PHP Dotenv manager](https://banners.beyondco.de/PHP%20Dotenv%20manager.png?theme=light\u0026packageManager=composer+require\u0026packageName=markwalet%2Fdotenv-manager\u0026pattern=circuitBoard\u0026style=style_1\u0026description=A+PHP+package+that+helps+you+edit+the+.env+file+programmatically.\u0026md=1\u0026showWatermark=0\u0026fontSize=100px\u0026images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg\u0026widths=200)](https://github.com/markwalet/dotenv-manager)\n\n[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Latest Stable Version](https://poser.pugx.org/markwalet/dotenv-manager/v/stable)](https://packagist.org/packages/markwalet/dotenv-manager)\n[![Build status](https://img.shields.io/github/actions/workflow/status/markwalet/dotenv-manager/tests.yml?branch=master\u0026style=flat-square\u0026label=tests)](https://github.com/markwalet/dotenv-manager/actions)\n[![Coverage](https://codecov.io/gh/markwalet/dotenv-manager/branch/master/graph/badge.svg)](https://codecov.io/gh/markwalet/dotenv-manager)\n[![StyleCI](https://github.styleci.io/repos/142404454/shield?branch=master)](https://github.styleci.io/repos/142404454)\n[![Total Downloads](https://poser.pugx.org/markwalet/dotenv-manager/downloads)](https://packagist.org/packages/markwalet/dotenv-manager)\n\nA PHP package that helps you edit the .env file programmatically. It works great for building tools like an installation CLI.\n\n## Installation\nYou can install this package with composer.\n\n```shell\ncomposer require markwalet/dotenv-manager\n```\n\nThis package can be used in every PHP project.\n\n### Laravel\nThe optional `DotenvManagerServiceProvider` makes this package package suitable for Laravel projects.\n\nFrom Laravel 5.5 and up you don't have to register your service provider anymore because of the package auto-discovery feature.\n\nIf you want to register the service provider manually (required for older versions), add the following line to your `config/app.php` file:\n\n```php\nMarkWalet\\DotenvManager\\DotenvManagerServiceProvider::class\n```\n\nThe service provider is also compatible with Laravel Lumen. Just add the following line to your `bootstrap/app.php` file:\n```php\n$app-\u003eregister(\\MarkWalet\\DotenvManager\\DotenvManagerServiceProvider::class);\n```\n\n## Usage\nYou can get the dotenv manager by resolving it with the app Laravel service container. \nThis will give you a singleton `MarkWalet\\DotenvManager\\DotenvManager` instance with the right dependencies.\n```php\n$dotenv = app(DotenvManager::class);\n```\n\nYou can also manually set up an `DotenvManager` class when you are not using Laravel.\n\nOnce you have a dotenv instance you can add a new value to the dotenv file:\n\n```php\n$dotenv-\u003eadd('FOO', 'Bar')-\u003eafter('EXISTING_KEY');\n```\n\nIf you don't specify a location for the new value, the value will be added at the end of the file.\n\nYou can also edit dotenv variables:\n\n```php\n$dotenv-\u003eupdate('EXISTING_KEY', 'updatedValue');\n```\n\nThis will replace the original value of `EXISTING_KEY` with `updatedValue`.\n\nAll values will be automatically formatted to a valid dotenv value.\n\n### Mutating multiple lines\nYou can use the `mutate()` method when you want to apply multiple changes to the file. The syntax looks a lot like the syntax in Laravel migrations:\n\n```php\n/**\n * Original content: \n *\n * TEST1=value1\n * TEST2=value2\n * TEST3=value3\n */\n \n$dotenv-\u003emutate(function(DotenvBuilder $builder){\n    $builder-\u003eadd('TEST4', 'escaped value');\n    $builder-\u003eupdate('TEST2', 'updated')-\u003eafter('TEST3');\n    $builder-\u003edelete('TEST1');\n});\n\n/**\n * New content: \n *\n * TEST3=value3\n * TEST2=updated\n * TEST4=\"escaped value\"\n */\n```\n\n### Available methods\nBelow you will find every available method and its underlying class. These methods can be called on the `DotenvManager` class itself and also on the `DotenvBuilder` you get when mutating the dotenv file.\n\nMethod  |  Returns\n------------- | -------------\n`add(string $key, $value = null)` | [Addition](src/Changes/Addition.php)\n`create(string $key, $value = null)` | [Addition](src/Changes/Addition.php)\n`set(string $key, $value = null)` | [Update](src/Changes/Update.php)\n`update(string $key, $value = null)` | [Update](src/Changes/Update.php)\n`move(string $key)` | [Move](src/Changes/Move.php)\n`delete(string $key)` | [Delete](src/Changes/Delete.php)\n`unset(string $key)` | [Delete](src/Changes/Delete.php)\n\n## Extending the builder\nYou can also extend the builder with your own implementation of the `Change` class. In the example below we are making a class that can increment a value quickly:\n\n```php\nuse MarkWalet\\DotenvManager\\Changes\\Change;\n\nclass Increment extends Change\n{\n    use HasKey;\n\n    function __construct(string $key)\n    {\n        $this-\u003ekey = $key;\n    }\n\n    public function apply(string $content): string\n    {\n        $search = '/'.$this-\u003egetKey().'=(.*)/';\n        preg_match($search, $content, $matches);\n        $value = $matches[1];\n\n        $replacement = $this-\u003egetKey().'='.($value + 1);\n\n        return preg_replace($search, $replacement, $content);\n    }\n}\n\n$dotenv-\u003eextend('increment', Increment::class);\n```\n\nAfter we extended the builder we can call it through the `DotenvManager` instance:\n\n```php\n/**\n * Original content: \n *\n * TEST1=value1\n * INCREMENT=56\n */\n$dotenv-\u003eincrement('INCREMENT');\n\n/**\n * New content: \n *\n * TEST1=value1\n * INCREMENT=57\n */\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkwalet%2Fdotenv-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkwalet%2Fdotenv-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkwalet%2Fdotenv-manager/lists"}