{"id":42036385,"url":"https://github.com/naingaunglwin-dev/dotenv","last_synced_at":"2026-01-26T05:07:44.800Z","repository":{"id":220569115,"uuid":"751983990","full_name":"naingaunglwin-dev/dotenv","owner":"naingaunglwin-dev","description":"Flexible and lightweight PHP environment loader","archived":false,"fork":false,"pushed_at":"2025-09-18T10:43:04.000Z","size":57,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-18T12:36:29.049Z","etag":null,"topics":["dotenv","dotenv-loader","env","phpdotenv"],"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/naingaunglwin-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-02-02T18:56:16.000Z","updated_at":"2025-09-18T10:43:04.000Z","dependencies_parsed_at":"2024-02-02T20:28:59.553Z","dependency_job_id":"c4a918a6-7027-48d6-b3b8-deaa0462102e","html_url":"https://github.com/naingaunglwin-dev/dotenv","commit_stats":null,"previous_names":["naingaunglwin-dev/dotenv"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/naingaunglwin-dev/dotenv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naingaunglwin-dev%2Fdotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naingaunglwin-dev%2Fdotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naingaunglwin-dev%2Fdotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naingaunglwin-dev%2Fdotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naingaunglwin-dev","download_url":"https://codeload.github.com/naingaunglwin-dev/dotenv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naingaunglwin-dev%2Fdotenv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28767032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T03:54:34.369Z","status":"ssl_error","status_checked_at":"2026-01-26T03:54:33.031Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","dotenv-loader","env","phpdotenv"],"created_at":"2026-01-26T05:07:44.209Z","updated_at":"2026-01-26T05:07:44.795Z","avatar_url":"https://github.com/naingaunglwin-dev.png","language":"PHP","readme":"\u003cdiv align=\"center\"\u003e\n\n# Simple Dotenv Library\n\u003ca href=\"https://github.com/naingaunglwin-dev/dotenv/actions\"\u003e\u003cimg src=\"https://github.com/naingaunglwin-dev/dotenv/actions/workflows/tests.yml/badge.svg\" alt=\"GitHub CI Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/naingaunglwin-dev/dotenv/\"\u003e\u003cimg src=\"https://img.shields.io/badge/coverage-100%25-green\" alt=\"Code Coverage\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/naingaunglwin-dev/dotenv/blob/main/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\" alt=\"License\"\u003e\u003c/a\u003e\n\n\u003c/div\u003e\n\n## About\n`NAL\\Dotenv` is a flexible and lightweight PHP environment loader designed for modern applications.\nIt supports loading environment variables from `.env` and `.json` files by default, with the ability to register custom loaders (e.g., YAML, XML) effortlessly.\n\n**This package provides:**\n\n- Grouped access to related environment keys\n- Support for multiple environment files\n- Static or instance-based access\n- Optional caching for performance\n- Convention-based parser resolution\n- Seamless integration with custom loaders and parsers\n\nIt's ideal for both small-scale projects and larger applications where managing structured and multi-source environment data is essential.\n\n## Contributing\n- This is an open-source library, and contributions are welcome.\n- If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request on the project repository.\n\n## Requirement\n- **PHP** version 8.2 or newer is required\n\n## Installation \u0026 Setup\n\n### Using Composer\n\u003e If Composer is not installed, follow the [official guide](https://getcomposer.org/download/).\n\n1. Create a `composer.json` file at your project root directory (if you don't have one):\n```json\n{\n  \"require\": {\n    \"naingaunglwin-dev/dotenv\": \"^2.0\"\n  }\n}\n```\n\n- Run the following command in your terminal from the project's root directory:\n```bash\ncomposer install\n```\n\nIf you already have `composer.json` file in your project, just run this command in your terminal,\n```bash\ncomposer require naingaunglwin-dev/dotenv\n```\n\n## Features\n✅ **Load .env files easily**\n- Supports standard .env key-value files for environment configuration.\n\n✅ **Support for .json config files**\n- Load structured environment data from JSON files — great for frontend-backend monorepo setups.\n\n✅ **Nested key flattening**\n- Nested JSON keys are automatically flattened into uppercase ENV_STYLE_KEYS.\n\n✅ **Environment grouping support**\n- Automatically organizes keys into groups based on naming conventions like APP_ENV → APP group.\n\n✅ **Custom Loader Registry**\n- Register your own loaders to support formats like YAML, TOML, etc.\n\n✅ **Optional override behavior**\n- Configure whether later files can override previously loaded keys.\n\n✅ **Safe loading**\n- Use `safeLoad()` to prevent exceptions when loading optional or missing files.\n\n✅ **Supercharged access methods**\n- Access environment values using `Env::get('KEY')` or grouped access with `Env::group('APP')`.\n\n✅ **Supports multiple files**\n- Pass an array of files to load them in order — useful for layering config.\n\n## Usage\n\n```php\n\u003c?php\n\nuse NAL\\Dotenv\\Env;\n\n$env = Env::create()-\u003eload();\n\n// Access values\n$envs = $env-\u003eget('APP_ENV');           // \"production\"\n$group = $env-\u003egroup('DATABASE');      // ['DATABASE_HOST' =\u003e '127.0.0.1', ...]\n```\n\n#### Static Access\nYou can also use static calls without manually creating an instance:\n```php\n\u003c?php\n\nuse NAL\\Dotenv\\Env;\n\n$value = Env::get('APP_ENV');\n$group = Env::group('APP');\n```\n\u003e If no instance was created yet, Env::get() and Env::group() will auto-initialize using default behavior `(.env, no cache)`. If an instance was previously created via Env::create(), the static calls will reuse that instance instead.\n\n#### Safe Load (No Exceptions)\n```php\n\u003c?php\n\nuse NAL\\Dotenv\\Env;\n\n$env = Env::create()-\u003esafeLoad(); // Returns ['envs' =\u003e [], 'groups' =\u003e []] on failure\n```\n\n#### Load JSON Configuration\n```php\n\u003c?php\n\nuse NAL\\Dotenv\\Env;\n\n$env = Env::create(name: 'env.json')-\u003eload();\n```\n\n#### Load Multiple Files\n```php\n\u003c?php\n\nuse NAL\\Dotenv\\Env;\n\nEnv::create(name: ['.env', '.env.testing'])-\u003eload();\n```\n\n#### Enable Caching\n```php\n\u003c?php\n\nuse NAL\\Dotenv\\Env;\n\nEnv::create(name: '.env', cache: true)-\u003eload(); // Loads once, reuses from memory\n```\n\n#### Register Custom Loader (e.g., YAML)\n```php\n\u003c?php\n\nuse NAL\\Dotenv\\Loader\\LoaderRegistry;\n\n$registry = new LoaderRegistry();\n\n$registry-\u003eregister('yaml', fn ($file, $override, $resolver, $parser) =\u003e new YamlLoader(\n    $file, $override, $resolver, $parser\n), '\\\\Namespace\\\\For\\\\Parser');\n\nEnv::create(name: 'config.yaml', registry: $registry)-\u003eload();\n```\n\n**Notes for Custom Loader Development**\n- The registered callback must accept exactly 4 arguments in this order:\n```php\n($file, $override, $resolver, $parser)\n```\n- Your custom loader **must**:\n\n  - Implement `NAL\\Dotenv\\Loader\\LoaderInterface`\n\n    **or**\n\n  - Extend `NAL\\Dotenv\\Loader\\BaseLoader` for convenient utilities like `resolveFiles()` and `save()`.\n\n- Every custom loader must include a corresponding parser, whose class name:\n\n  - **Starts with the capitalized extension name**, followed by Parser\n    **e.g., for .yaml, the parser must be YamlParser**\n\n  - **Must implement** `NAL\\Dotenv\\Parser\\ParserInterface`\n\n\u003e Parsers are resolved by convention from the namespace `\\NAL\\Dotenv\\Parser\\`, or a custom namespace if provided.\n\n## Running Tests\n\n- To run the test suite, execute the following command\n```bash\nvendor/bin/phpunit tests/EnvTest.php\n```\n- This will run all test cases defined in the EnvTest.php file.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaingaunglwin-dev%2Fdotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaingaunglwin-dev%2Fdotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaingaunglwin-dev%2Fdotenv/lists"}