{"id":15029774,"url":"https://github.com/rancoud/environment","last_synced_at":"2025-04-09T20:40:29.489Z","repository":{"id":37579851,"uuid":"135355463","full_name":"rancoud/Environment","owner":"rancoud","description":"Environment Package","archived":false,"fork":false,"pushed_at":"2025-04-01T12:21:02.000Z","size":608,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T00:34:34.507Z","etag":null,"topics":["composer","coverage","env","environment","packagist","php","php74","php8","php80","php81","phpdotenv","phpunit","phpunit9"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/rancoud/environment","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/rancoud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-29T21:36:30.000Z","updated_at":"2025-04-01T12:21:04.000Z","dependencies_parsed_at":"2024-02-03T17:35:42.489Z","dependency_job_id":"fd65fa90-8259-4f34-a253-812cf1dba41f","html_url":"https://github.com/rancoud/Environment","commit_stats":{"total_commits":114,"total_committers":3,"mean_commits":38.0,"dds":"0.29824561403508776","last_synced_commit":"cfc00937c64b0e57c4f8649d277f0dd6b6242dc9"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FEnvironment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FEnvironment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FEnvironment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancoud%2FEnvironment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rancoud","download_url":"https://codeload.github.com/rancoud/Environment/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248109612,"owners_count":21049343,"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","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":["composer","coverage","env","environment","packagist","php","php74","php8","php80","php81","phpdotenv","phpunit","phpunit9"],"created_at":"2024-09-24T20:11:36.369Z","updated_at":"2025-04-09T20:40:29.470Z","avatar_url":"https://github.com/rancoud.png","language":"PHP","readme":"# Environment Package\n\n![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/rancoud/environment)\n[![Packagist Version](https://img.shields.io/packagist/v/rancoud/environment)](https://packagist.org/packages/rancoud/environment)\n[![Packagist Downloads](https://img.shields.io/packagist/dt/rancoud/environment)](https://packagist.org/packages/rancoud/environment)\n[![Composer dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](https://github.com/rancoud/Environment/blob/master/composer.json)\n[![Test workflow](https://img.shields.io/github/actions/workflow/status/rancoud/environment/test.yml?branch=master)](https://github.com/rancoud/environment/actions/workflows/test.yml)\n[![Codecov](https://img.shields.io/codecov/c/github/rancoud/environment?logo=codecov)](https://codecov.io/gh/rancoud/environment)\n\nRead Environment file (.env).  \nCan complete or override data from `getenv()` / `$_ENV` / `$_SERVER`  \n\n## Installation\n```php\ncomposer require rancoud/environment\n```\n\n## .env File example\n```\n# type of variables used\nSTRING=STRING\nSTRING_QUOTES=\" STRING QUOTES \"\nINTEGER=9\nFLOAT=9.0\n\nBOOL_TRUE=TRUE\nBOOL_FALSE=FALSE\nNULL_VALUE=NULL\n\n# variable in value\nHOME=/user/www\nCORE=$HOME/core\n; $HOME won't be interpreted\nUSE_DOLLAR_IN_STRING=\"$HOME\"\n\n#comment line 1\n;comment line 2\n\n# import another env file use @ and the filename\n@database.env\n\n# multilines\nRGPD=\"\ni understand\n\n    enough of email for \\\"me\\\"    \n\nthanks\n\"\n```\n\n## How to use it?\nWarning, call constructor will not load values, you can:  \n* use `load()` function\n* use [any functions](#when-load-is-called)  that automatically call `load()` inside  \n\n### Simple example\n```php\n// search .env file\n$env = new Environment(__DIR__);\n$values = $env-\u003egetAll();\n$value = $env-\u003eget('a', 'defaultvalue');\n```\n\n### Check keys and values\n```php\n// check if a key exists\n$env = new Environment(__DIR__);\n$isExists = $env-\u003eexists('key1');\n$isExists = $env-\u003eexists(['key1', 'key2']);\n\n// check if value is set with allowed values\n$isAllowed = $env-\u003eallowedValues('key1', ['value1', NULL, 'value2']);\n```\n\n### Complete and Override values\nOnly type conversion will be done on those variables (no replacement with `$`).\n\nYou have 3 differents flags:\n* Environment::GETENV\n* Environment::ENV\n* Environment::SERVER\n\nComplete is for filling values belong to keys having empty string or no values.  \nOverride is for erasing values belong to keys.  \nThe treatment given by the flags is always in the same order:\n1. `getenv()`\n2. `$_ENV`\n3. `$_SERVER`\n\nYou can also use 3 others flags.  \nThose will inject all keys and values found, your env file is not used for checkings keys.\n* Environment::GETENV_ALL\n* Environment::ENV_ALL\n* Environment::SERVER_ALL\n\n```php\n$env = new Environment(__DIR__);\n\n// complete with only getenv()\n$env-\u003ecomplete(Environment::GETENV);\n\n// complete with $_ENV then $_SERVER\n$env-\u003ecomplete(Environment::SERVER | Environment::ENV);\n\n// override with getenv() will erase values\n$env-\u003eoverride(Environment::GETENV);\n```\n\n### Enable cache\nThe file cached will not contains informations from `getenv()` / `$_ENV` / `$_SERVER`  \n```php\n// force using cache (if not exist it will be created)\n$env = new Environment(__DIR__);\n$env-\u003eenableCache();\n$values = $env-\u003egetAll();\n```\n\n### When load() is called?\nFor simplicity `load()` is automatically called when using thoses functions:  \n* get\n* getAll\n* exists\n* complete\n\n### Multiline\nYou can check what kind of endline it using, by default it's `PHP_EOL`  \nYou can change it with for using `\u003cbr\u003e`  \n```php\n// force using cache (if not exist it will be created)\n$env = new Environment(__DIR__);\n$env-\u003esetEndline('\u003cbr /\u003e');\n```\n\n### Include another .env\nInside .env file you can include another .env file with the `@` operator at the begining of the line\n\n### Constructor variations\n```php\n// search .env file\n$env = new Environment(__DIR__);\n\n// search dev.env file\n$env = new Environment(__DIR__, 'dev.env');\n\n// search .env file in folders __DIR__ then '/usr'\n$env = new Environment([__DIR__, '/usr']);\n\n// search dev.env file in folders __DIR__ then '/usr'\n$env = new Environment([__DIR__, '/usr'], 'dev.env');\n```\n\n## Environment Constructor\n### Settings\n#### Mandatory\n| Parameter | Type            | Description              |\n|-----------|-----------------|--------------------------|\n| folder    | string OR array | folder to seek .env file |\n\n#### Optionnals\n| Parameter | Type   | Default value | Description                                                   |\n|-----------|--------|---------------|---------------------------------------------------------------|\n| filename  | string | .env          | custom name of .env file (don't forget to add file extension) |\n\n## Environment Methods\n### General Commands  \n* load():void  \n* get(name: string, [default: mixed = null]): mixed|null  \n* getAll(): arrray  \n* exists(name: string|array): bool  \n* allowedValues(name: string, values: array): bool  \n\n### Cache File  \n* enableCache(): void  \n* disableCache(): void  \n* flushCache(): void  \n\n### Env variables\n* complete(flags: Environment::GETENV | Environment::ENV | Environment::SERVER): void\n* override(flags: Environment::GETENV | Environment::ENV | Environment::SERVER): void\n\n### Multilines endline interpretation\n* setEndline(endline: string): void  \n* getEndline(): string  \n\n## How to Dev\n`composer ci` for php-cs-fixer and phpunit and coverage  \n`composer lint` for php-cs-fixer  \n`composer test` for phpunit and coverage  \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Francoud%2Fenvironment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Francoud%2Fenvironment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Francoud%2Fenvironment/lists"}