{"id":15355076,"url":"https://github.com/adhocore/php-env","last_synced_at":"2025-04-15T06:20:43.612Z","repository":{"id":52442150,"uuid":"107715208","full_name":"adhocore/php-env","owner":"adhocore","description":"A small and fast .env loader for PHP","archived":false,"fork":false,"pushed_at":"2023-03-25T14:33:21.000Z","size":46,"stargazers_count":23,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-28T17:01:45.351Z","etag":null,"topics":["adhocore","dotenv","dotenv-parser","env","env-loader","environment-variables","hacktoberfest","php-dotenv","php-env"],"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/adhocore.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"custom":["https://paypal.me/ji10"]}},"created_at":"2017-10-20T18:55:09.000Z","updated_at":"2023-06-19T06:09:52.000Z","dependencies_parsed_at":"2022-08-19T11:20:14.673Z","dependency_job_id":"f019a44b-ea93-4cf2-8e3b-025d98de33ca","html_url":"https://github.com/adhocore/php-env","commit_stats":{"total_commits":53,"total_committers":1,"mean_commits":53.0,"dds":0.0,"last_synced_commit":"be6eea4dd576dd3c272c1595982167e8d6bf82f5"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhocore%2Fphp-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhocore%2Fphp-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhocore%2Fphp-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhocore%2Fphp-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adhocore","download_url":"https://codeload.github.com/adhocore/php-env/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249017243,"owners_count":21198932,"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":["adhocore","dotenv","dotenv-parser","env","env-loader","environment-variables","hacktoberfest","php-dotenv","php-env"],"created_at":"2024-10-01T12:22:24.140Z","updated_at":"2025-04-15T06:20:43.586Z","avatar_url":"https://github.com/adhocore.png","language":"PHP","readme":"## adhocore/env\n\n[![Latest Version](https://img.shields.io/github/release/adhocore/php-env.svg?style=flat-square)](https://github.com/adhocore/php-env/releases)\n[![Travis Build](https://travis-ci.org/adhocore/php-env.svg?branch=master)](https://travis-ci.org/adhocore/php-env?branch=master)\n[![Scrutinizer CI](https://img.shields.io/scrutinizer/g/adhocore/php-env.svg?style=flat-square)](https://scrutinizer-ci.com/g/adhocore/php-env/?branch=master)\n[![Codecov branch](https://img.shields.io/codecov/c/github/adhocore/php-env/master.svg?style=flat-square)](https://codecov.io/gh/adhocore/php-env)\n[![StyleCI](https://styleci.io/repos/107715208/shield)](https://styleci.io/repos/107715208)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n\n- Environment variable loader and retriever for PHP.\n- Sanitization/Filters can be applied on retrieval if `filter` extension is loaded.\n- Using env to configure application is one of the [12 postulates](https://12factor.net/config).\n\n## Installation\n```\ncomposer require adhocore/env\n```\n\n## Usage\n\n### Loading\n\n```php\nuse Ahc\\Env\\Loader;\n\n// Load env variables from .env file to `putenv` by default:\n(new Loader)-\u003eload('/project/root/.env');\n\n// Pass in boolean second param to control if the env should be reloaded:\n(new Loader)-\u003eload('/project/root/.env', true);\n\n// Load to $_SERVER global:\n(new Loader)-\u003eload('/project/root/.env', true, Loader::SERVER);\n\n// Load to $_ENV global and putenv():\n(new Loader)-\u003eload('/project/root/.env', true, Loader::ENV | Loader::PUTENV);\n\n// Load to all targets:\n(new Loader)-\u003eload('/project/root/.env', true, Loader::ALL);\n```\n\n\u003e Always wrap complex values within double quotes in `.env` file. Eg: `APP_KEY=\"K\u0026^¢*\u0026D(?\u003cµ}^(P\\]X\"`\n\n### ENV Format\n\nSupports `#` or `;` comments. Literal double quote should be escaped like `\"\"`. See more examples below:\n\n```\n# comment line\na=1\nb=\"2\"\nc=$3#\n; also comment line\nd=\"lol\"\n# empty\ne=\n# f is `\"6\"`\nf=\"\"6\"\"\n1_2=one_two\n# empty too\nE=\"\"\nA_B=Apple Ball\nx=Y\n```\n\nReference is possible like so:\n\n```\nMAIN=1\nREF=${MAIN}/2\nREF2=${REF}/3\n# below will not be parsed as INV is not resolved\nREF3=${INV}\n```\n\n### Retrieving\n\n```php\nuse Ahc\\Env\\Retriever;\n\n// Retrieve:\necho Retriever::getEnv($key);\n\n// Default value:\necho Retriever::getEnv('PAYMENT_GATEWAY', 'stripe');\n\n// Sanitization (pass third and optionally fourth parameters):\necho Retriever::getEnv('MYSQL_PORT', 3306, FILTER_VALIDATE_INT);\n\n// Or you can use `env()` which is alias of `Retriever::getEnv()`:\necho env('THE_KEY');\n```\n\nSee [filter_var](http://php.net/filter_var) for more on sanitizing/filtering values!\n\n## Benchmark\n\nIf you are interested [here](https://github.com/adhocore/env-bench) is a simple benchmark.\n\n---\n### Consideration\n\nBy default this library only loads env to `putenv()`.\nBe cautious exposing confidential credentials into `$_ENV` and `$_SERVER` which bug/error catchers may log.\n\nAlthough this libray is already fast enough, in production you might want to boost performance a little by loading if only required:\n\n```php\nif (!getenv('\u003cLAST_ENV_APP_SHOULD_BE_AWARE_OF\u003e')) {\n    // Override false :)\n    (new Loader)-\u003eload('/project/root/.env', false);\n}\n```\n\nFor example if your app last introduced `FB_APP_ID` env, but this value is not already hard set in the machine,\nit would be loaded via `.env` file else you are already covered.\n\n### Credits\n\nThis project is [release](https://github.com/adhocore/php-env/releases)\nmanaged by [please](https://github.com/adhocore/please).\n","funding_links":["https://paypal.me/ji10"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadhocore%2Fphp-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadhocore%2Fphp-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadhocore%2Fphp-env/lists"}