{"id":22627536,"url":"https://github.com/rammewerk/environment","last_synced_at":"2025-04-11T18:51:52.564Z","repository":{"id":64779126,"uuid":"578162690","full_name":"rammewerk/environment","owner":"rammewerk","description":"A fast, type-safe, and dependency-free .env handler for PHP, built for performance and simplicity.","archived":false,"fork":false,"pushed_at":"2025-01-15T15:12:07.000Z","size":39,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T14:44:45.725Z","etag":null,"topics":["dotenv","environment","php","rammewerk-component"],"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/rammewerk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2022-12-14T12:05:52.000Z","updated_at":"2025-01-15T15:12:08.000Z","dependencies_parsed_at":"2025-01-15T16:30:53.748Z","dependency_job_id":"132f77f2-3c72-46ef-8702-375b89cd9347","html_url":"https://github.com/rammewerk/environment","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rammewerk%2Fenvironment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rammewerk%2Fenvironment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rammewerk%2Fenvironment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rammewerk%2Fenvironment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rammewerk","download_url":"https://codeload.github.com/rammewerk/environment/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248464314,"owners_count":21108238,"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":["dotenv","environment","php","rammewerk-component"],"created_at":"2024-12-09T01:12:19.061Z","updated_at":"2025-04-11T18:51:52.555Z","avatar_url":"https://github.com/rammewerk.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Rammewerk Environment\n======================\n\nA **fast**, **typed**, and **opinionated** environment variable handler designed for simplicity.\n\nThis package provides a streamlined, dependency-free approach to handling `.env` files in your project, offering both\nspeed and type safety. Unlike other solutions, Rammewerk Environment focuses on performance and ensures minimal exposure\nrisks by not injecting variables into $_ENV.\n\n#### Why choose Rammewerk Environment?\n\n- **Blazing fast parsing** of .env files, suitable for high-performance applications.\n- **Type-safe outputs**: Automatically converts values to proper types like bool, int, null, or even array.\n- **No hidden magic**: Variables are not automatically added to global environment arrays.\n- **Dependency-free**: Minimal footprint for lightweight projects.\n- **Extensible validation**: Easily validate required variables using closures.\n- **Multiple file support**: Load and manage multiple .env files with ease.\n\n***Note**: This package supports a simplified .env format, with specific rules for variable names, comments, and values.\nSee\n[Limitations](#Limitations) for details.*\n\nGetting Started\n---------------\n\n```\n$ composer require rammewerk/environment\n```\n\n```php\nuse Rammewerk\\component\\environment\\src\\Environment;\n\n$env = new Environment();\n\n// Load from environment variable file\n$env-\u003eload( ROOT_DIR . '.env');\n\n// Get value from environment\n$debug_mode = $env-\u003eget( 'DEBUG_MODE' );\n\n// Or use the built-in typed getters which returns true or false, defaults to false\n$debug_mode = $env-\u003egetBool('DEBUG_MODE');\n\n```\n\nSupport for multiple .env files\n---------------\nYou can add multiple environment files or create new variables on the fly.\n\nA file does not necessarily need to be .env. For instance, a file.txt will also work as long as it is correctly\nformatted.\n\n```php\n$env-\u003eload( ROOT_DIR . '.env');\n\n# Warning: will overwrite value for keys that exist in both files.\n$env-\u003eload( ROOT_DIR . '.env-app');\n\n# You can also define new variables or overwrite values on the fly.\n$env-\u003eset('NEW_KEY', 'new value');\n```\n\nValidating environment variables\n---------------\n\n```php\n$env-\u003evalidate( static function(Validator $env) {\n    $env-\u003erequire('DEBUG_MODE')-\u003eisBoolean();\n    $env-\u003eifPresent('APP_URL')-\u003eendWith('/');\n})\n```\n\nLimitations\n---------------\nThis is a simple env parser. You will need to format your env-files accordingly:\n\n#### Variable names\n\nEnvironment variable names must consist solely of letters, digits, and the\nunderscore ( _ ) and must not begin with a digit.\n\n#### Comments\n\nComments are **only** allowed on new lines, never on the same line as variables.\n\n```dotenv\n# This is a valid comment\nUSER=John # Comment like this is not allowed!\n```\n\n#### Variable values\n\nValues can be quoted.\n\n```dotenv\n# Values can be quoted. These are all the same values:\nKEY1=value\nKEY2='value'\nKEY3=\"value\"\n```\n\n### Values will be trimmed and converted to types\n\n```dotenv\n# Values will be automatically trimmed. This is the same as KEY2='HELLO'\nKEY4=' HELLO '\n\n# TRUE or FALSE will be converted to valid boolean type in PHP. If you use quotes, it will be converted to string.\nKEY5=TRUE\n\n# An interger value will be converted to a valid PHP interger. If you use quotes, it will be converted to string.\nKEY6=120\n\n# Empty string '' or NULL will be converted to PHP NULL value.\nKEY7=NULL\n\n# Add commaseparated string inside brackets to convert to array of strings\nKEY9='[value1,value2,value3]'\n```\n\nTips\n---------------\nA `new Environment()` will return a new instance of the class. So, if you use a dependency injection container or\nsimilar, consider making the Environment class a shared instance. Or make your own singleton wrapper.\n\n## Typed getters\n\nYou can use typed getters to get the value of a key as a specific type. For example:\n\n```php\n$env-\u003egetString('KEY1'); // Returns string or null\n$env-\u003egetInt('KEY2'); // Returns int or null\n$env-\u003egetFloat('KEY3'); // Returns float or null\n$env-\u003egetBool('KEY4'); // Returns bool, true or false, defaults to false\n$env-\u003egetArray('KEY5'); // Returns array or null\n```\n\nContribution\n---------------\nIf you have any issues or would like to contribute to the development of this library, feel free to open an issue or\npull request.\n\nLicense\n---------------\nThe Rammewerk Container is open-sourced software licensed under\nthe [MIT license](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frammewerk%2Fenvironment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frammewerk%2Fenvironment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frammewerk%2Fenvironment/lists"}