{"id":15561179,"url":"https://github.com/lionix-team/envclient","last_synced_at":"2025-10-15T10:46:58.416Z","repository":{"id":54916589,"uuid":"235995426","full_name":"lionix-team/envclient","owner":"lionix-team","description":"Manage and validate environmental variables with artisan console commands and facades","archived":false,"fork":false,"pushed_at":"2021-01-21T07:39:51.000Z","size":111,"stargazers_count":16,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-04T02:54:47.874Z","etag":null,"topics":["dotenv","env","environment","environment-variables","laravel","laravel-framework","lionix"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lionix-team.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-24T12:03:40.000Z","updated_at":"2023-09-26T10:08:20.000Z","dependencies_parsed_at":"2022-08-14T06:31:15.731Z","dependency_job_id":null,"html_url":"https://github.com/lionix-team/envclient","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/lionix-team/envclient","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lionix-team%2Fenvclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lionix-team%2Fenvclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lionix-team%2Fenvclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lionix-team%2Fenvclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lionix-team","download_url":"https://codeload.github.com/lionix-team/envclient/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lionix-team%2Fenvclient/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279074524,"owners_count":26097647,"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-15T02:00:07.814Z","response_time":56,"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":["dotenv","env","environment","environment-variables","laravel","laravel-framework","lionix"],"created_at":"2024-10-02T16:05:58.098Z","updated_at":"2025-10-15T10:46:58.383Z","avatar_url":"https://github.com/lionix-team.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EnvClient for Laravel\n\nManage and validate environmental variables with artisan console commands, environmental rules and facades\n\n## Installation\n\n```\ncomposer require lionix/envclient\n```\n\n## Breaking changes\n\n### From 1.0.0 to 1.1.0\n\n- To construct the `\\Lionix\\Envclient` use Laravel Service Container instead of plain construct.\n\n## Artisan commands\n\n| Signature               | Description                                       |\n| ----------------------- | ------------------------------------------------- |\n| `env:get {key}`         | Prints .env variable value                        |\n| `env:set {key} {value}` | Sets .env variable if validation rules are passed |\n| `env:check`             | Check all env variables for validness             |\n| `env:empty`             | Print empty .env variables                        |\n| `make:envrule {name}`   | Create a new .env validation rules                |\n\n## Basic usage\n\nSet an environment variable using `env:set` artisan command.\n\n```\nphp artisan env:set EXAMPLE_ENV_VARIABLE 'example value'\n```\n\nThe command will modify your environment file by replacing or adding the given key to it.\n\n### Validate environment variables\n\nIf you want to apply validation rules to environmental variables before `env:set` command will modify the file you will have to publish command package configuration files.\n\n```\nphp artisan vendor:publish --provider='Lionix\\EnvClient\\Providers\\EnvClientServiceProvider' --tag='config'\n```\n\nThe command will create `config/env.php`\n\n```php\n\u003c?php\n\nreturn [\n\n    /**\n     * Validation classes which contain environment rules\n     * applied by env artisan commands.\n     *\n     * Add your validation classes created by\n     * `php artisan make:envrule` command to apply their rules\n     *\n     * @var array\n     */\n    'rules' =\u003e [\n        \\App\\Env\\BaseEnvValidationRules::class\n    ]\n];\n```\n\nand `app/Env/BaseEnvValidationRules.php`\n\n```php\n\u003c?php\n\nnamespace App\\Env;\n\nuse Lionix\\EnvValidator;\n\nclass BaseEnvValidationRules extends EnvValidator\n{\n    /**\n     * Validation rules that apply to the .env variables.\n     *\n     * @return array\n     */\n    public function rules() : array\n    {\n        return [\n            //\n        ];\n    }\n}\n```\n\nBy adding validation rules into `rules` method return value you will apply them to `env:set` command.\n\n```php\n...\npublic function rules() : array\n{\n    return [\n        'DB_CONNECTION' =\u003e 'required|in:mysql,sqlite'\n    ];\n}\n...\n```\n\nThis way if you try to set an invalid value to the `DB_CONNECTION` variable with `env:set` command, the console will print out an error\n\n```\n$ php artisan env:set DB_CONNECTION SomeInvalidValue\nThe selected DB_CONNECTION is invalid.\n```\n\nIf your environment file was modified you can run `env:check` command which will check all variables for validness and print out the results.\n\n```\n$ php artisan env:check\nThe selected DB_CONNECTION is invalid.\n```\n\n## Create a new environmental validation rules\n\n### Run the `make:envrule` command\n\nBy default, the script will generate a class in `App/Env` namespace.\n\n#### Example:\n\n```\nphp artisan make:envrule DatabaseEnvRules\n```\n\n`app/Env/DatabaseEnvRules.php`\n\n```php\n\u003c?php\n\nnamespace App\\Env;\n\nuse Lionix\\EnvValidator;\n\nclass DatabaseEnvRules extends EnvValidator\n{\n    /**\n     * Validation rules that apply to the .env variables.\n     *\n     * @return array\n     */\n    public function rules() : array\n    {\n        return [\n            //\n        ];\n    }\n}\n```\n\n### Specify validation rules:\n\n```php\n...\npublic function rules() : array\n{\n    return [\n        'DB_CONNECTION' =\u003e 'requried|in:mysql,sqlite,pgsql,sqlsrv'\n        'DB_HOST' =\u003e 'requried',\n        'DB_PORT' =\u003e 'requried|numeric',\n        'DB_DATABASE' =\u003e 'requried',\n        'DB_USERNAME' =\u003e 'requried',\n        'DB_PASSWORD' =\u003e 'requried'\n    ];\n}\n...\n```\n\n### Apply the rules:\n\nYou can add the `DatabaseEnvRules` class to `env.php` configuration file at the `rules` key. That way all the rules specified in the class will affect package artisan commands.\n\n`config/env.php`\n\n```php\n\n\u003c?php\n\nreturn [\n\n    /**\n     * Validation classes which contain environment rules\n     * applied by env artisan commands.\n     *\n     * Add your validation classes created by\n     * `php artisan make:envrule` command to apply their rules\n     *\n     * @var array\n     */\n    'rules' =\u003e [\n        \\App\\Env\\BaseEnvValidationRules::class\n        \\App\\Env\\DatabaseEnvRules::class // \u003c- our database rules\n    ]\n];\n```\n\nOr you can use `Lionix\\EnvClient` Facade to validate the input with given validation rules:\n\n```php\n...\n$client = app()-\u003emake(\\Lionix\\Envclient::class);\n\n$client-\u003euseValidator(new \\App\\Env\\DatabaseEnvRules())-\u003eupdate($databaseCredentials);\n\nif ($client-\u003eerrors()-\u003eisNotEmpty()) {\n    // handle errors\n} else {\n    // success, the variables are updated\n}\n...\n```\n\n## Facades\n\n### Lionix\\EnvClient\n\n#### Properties:\n\n- protected **\\$getter** : _Lionix\\EnvClient\\Interfaces\\EnvGetterInterface_\n\n- protected **\\$setter** : _Lionix\\EnvClient\\Interfaces\\EnvSetterInterface_\n\n- protected **\\$validator** : _Lionix\\EnvClient\\Interfaces\\EnvValidatorInterface_\n\n#### Methods:\n\n- `void` : **\\_\\_construct()**  \n  Create a new instance of EnvClient using default dependencies\n\n- `self` : **useGetter(_Lionix\\EnvClient\\Interfaces\\EnvGetterInterface_ \\$getter)**  \n  Set client getter dependency\n\n- `self` : **useSetter(_Lionix\\EnvClient\\Interfaces\\EnvSetterInterface_ \\$setter)**  \n  Set setter dependency\n\n- `self` : **useValidator(_Lionix\\EnvClient\\Interfaces\\EnvValidatorInterface_ \\$validator)**  \n  Set validator dependency merging current errors with the validator errors\n\n- `array` : **all()**  \n  Get all env variables from the environmental file\n\n- `bool` : **has(_string \\$key_)**  \n  Check if the environmental file contains the key\n\n- `mixed` : **get(_string \\$key_)**  \n  Get the env variable using the key (returns the output of `Illuminate\\Support\\Env` get method)\n\n- `self` : **set(_array \\$values_)**  \n  Set the environmental variables at runtime if validation rules passed\n\n- `self` : **save()**  \n  Save previously set variables to the environmental file\n\n- `self` : **update()**  \n  If validation rules passed then set and save variables to the environmental file\n\n- `bool` : **validate(_array_ \\$values)**  \n  Check values validness and retrieve passed status\n\n- `Illuminate\\Support\\MessageBag` : **errors()**  \n  Get all validation errors occurred during the class lifetime\n\n### Lionix\\EnvGetter\n\n#### Methods:\n\n- `void` : **\\_\\_construct()**  \n  Create a new instance of EnvGetter\n\n- `mixed` : **get(_string_ \\$key)**  \n  Get the env variable using the key (returns the output of `Illuminate\\Support\\Env` get method)\n\n- `array` : **all()**  \n  Get all env variables from the environmental file\n\n- `bool` : **has(_string_ \\$key)**  \n  Check if the environmental file contains the key\n\n### Lionix\\EnvSetter\n\n#### Properties:\n\n- protected **\\$variablesToSet** : _array_\n\n#### Methods:\n\n- `void` : **\\_\\_construct()**  \n  Create a new instance of EnvSetter\n\n- `void` : **set(_array_ \\$values)**  \n  Merge given values with variablesToSet property\n\n- `void` : **save()**  \n  Save all variables previously set by the set method to the environmental file\n\n- protected `string` : **sanitize(_string_ \\$value)**  \n  Sanitize input values\n\n### Lionix\\EnvValidator\n\n#### Properties:\n\n- protected **\\$errors** : _Illuminate\\Support\\MessageBag_\n\n#### Methods:\n\n- `void` : **\\_\\_construct()**  \n  Create a new instance of EnvValidator\n\n- `array` : **rules()**  \n  Returns class validation rules\n\n- `bool` : **validate(_array_ \\$values)**  \n  Validate given values\n\n- `Illuminate\\Support\\MessageBag` : **errors()**  \n  Get validator errors\n\n- `void` : **mergeErrors(_Illuminate\\Support\\MessageBag_ \\$errors)**  \n  Merge given MessageBag with current errors\n\n## Credits:\n\n- [Stas Vartanyan](https://github.com/vaawebdev)\n- [Lionix Team](https://github.com/lionix-team)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flionix-team%2Fenvclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flionix-team%2Fenvclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flionix-team%2Fenvclient/lists"}