{"id":20345947,"url":"https://github.com/silinternational/php-env","last_synced_at":"2025-07-10T12:11:18.567Z","repository":{"id":1882699,"uuid":"45204195","full_name":"silinternational/php-env","owner":"silinternational","description":"Utility class for working with environment variables in PHP that handles 'true', 'false', and 'null' more intelligently.","archived":false,"fork":false,"pushed_at":"2025-01-06T21:00:24.000Z","size":71,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-12T00:42:14.348Z","etag":null,"topics":["getenv","php"],"latest_commit_sha":null,"homepage":null,"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/silinternational.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2015-10-29T18:58:35.000Z","updated_at":"2025-02-28T22:55:05.000Z","dependencies_parsed_at":"2024-06-21T04:40:24.586Z","dependency_job_id":null,"html_url":"https://github.com/silinternational/php-env","commit_stats":{"total_commits":67,"total_committers":8,"mean_commits":8.375,"dds":0.4776119402985075,"last_synced_commit":"d69cf17b7fc02cf6450d7d947634d07b7c2168af"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silinternational%2Fphp-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silinternational%2Fphp-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silinternational%2Fphp-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silinternational%2Fphp-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/silinternational","download_url":"https://codeload.github.com/silinternational/php-env/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501958,"owners_count":21114681,"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":["getenv","php"],"created_at":"2024-11-14T22:10:28.828Z","updated_at":"2025-04-12T00:42:19.182Z","avatar_url":"https://github.com/silinternational.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sil/PhpEnv/\n\nSimple PHP library for getting (or requiring) environment variables, designed \nto handle `true`, `false`, and `null` more intelligently. If desired, an \nenvironment variable's value can be split into an array automatically.\n\n## Build Status\n\n![Unit Tests](https://github.com/silinternational/php-env/actions/workflows/test.yml/badge.svg?branch=master)\n\n## Setup\n\n1. Clone this repo.\n1. Copy `local.env.dist` to `local.env` and update GitHub.com token as \n   appropriate.\n1. Run `make test` to install dependencies and run PHPUnit tests.\n   \n### Makefile script\n\nThere is a Makefile in place to simplify common tasks.\n- `make test` - does `composer install` and runs phpunit tests\n\n___\n\n## Classes in Sil/PhpEnv namespace\n\n1. __Env__: `use Sil\\PhpEnv\\Env;`\n2. __EnvVarNotFoundException__: `use Sil\\PhpEnv\\EnvVarNotFoundException;`\n\n### Class `Env` summary of functions\n\n1. __get__ - `public static function get($varname, $default = null)`\n\n    * searches the local environment for `$varname` and returns the corresponding value string\n    * if `$varname` is not set or the value is empty (only whitespace), `get` returns `$default` parameter\n    * if the value string corresponding to `$varname` is 'true', 'false' or 'null', `get` returns \nphp values of `true`, `false`, or `null` respectively\n    * NOTE: Any value string containing 'true' with any combination of case and/or leading/trailing whitespace still returns php `true`.  \n`false` and `null` are handled similarly.  Other value strings will have leading/trailing whitespace trimmed.\n\n1. __getString__ - `public static function getString($varname, $default = null): ?string`\n\n    * searches the local environment for `$varname` and returns the corresponding trimmed value string\n    * if `$varname` is not set or the value is empty (only whitespace), `getString` returns `$default` parameter\n\n1. __getBoolean__ - `public static function getBoolean($varname, $default = null): ?bool`\n\n    * searches the local environment for `$varname` and returns the corresponding boolean value string\n    * if `$varname` is not set or the value is empty (only whitespace), `getBoolean` returns `$default` parameter\n    * if the value string corresponding to `$varname` is 'true', 'false' or 'null', `getBoolean` returns\n      php values of `true`, `false`, or `null` respectively\n    * if the value is not boolean, `getBoolean` returns `$default` parameter\n    * NOTE: Any value string containing 'true' with any combination of case and/or leading/trailing whitespace still returns php `true`.\n      `false` and `null` are handled similarly.\n\n1. __getArray__ - `public static function getArray($varname, array $default = [])`\n\n    * searches the local environment for `$varname` and returns the corresponding value string with comma separated elements as a php array\n    * if `$varname` is not set or the value is empty (only whitespace), `getArray` returns `$default` parameter which must be an array\n    * if $default is not an array, it throws a `TypeError` exception\n\n1. __requireEnv__ - `public static function requireEnv($varname)`\n\n    * searches the local environment for `$varname` and returns the corresponding value string\n    * if `$varname` is not set or the value is empty (only whitespace), it throws `EnvVarNotFoundException`\n    * 'true', 'false', and 'null' are handled the same as `get()`\n\n1. __requireArray__ - `public static function requireArray($varname)`\n\n    * searches the local environment for `$varname` and returns the corresponding value string with comma separated elements as a php array\n    * if `$varname` is not set or the value is empty (only whitespace), it throws `EnvVarNotFoundException`\n\n\n### Class `EnvVarNotFoundException`\n\n`class EnvVarNotFoundException extends \\Exception`\n\n`EnvVarNotFoundException` is thrown by `requireEnv()` and `requireArray()` when `$varname` is not found in the local\nenvironment or the corresponding value string is empty (only whitespace)\n\n\n___\n\n## `Env` example function calls\n\n### Assume this `local.env` file\n\n    EMPTY=\n    SPACES=      \n    WHITESPACE= Some whitespace    \n    FALSE=False\n    TRUE=TRUE\n    NULL=null\n    LOWERCASE=abc123\n    UPPERCASE=ABC123\n    ARRAY0=\n    ARRAY1=one\n    ARRAY=one,two,,three\n\n### Example function calls and results\n\n* **get** - `public static function get($varname, $default = null)`\n\n    1. `Env::get('NOTFOUND')` - returns `null`\n    1. `Env::get('NOTFOUND', 'bad data')` - returns `'bad data'`\n    1. `Env::get('EMPTY')` - returns `''`\n    1. `Env::get('SPACES')` - returns `''`\n    1. `Env::get('WHITESPACE')` - returns `'Some whitespace'`\n    1. `Env::get('FALSE')` - returns `false`\n    1. `Env::get('TRUE')` - returns `true`\n    1. `Env::get('NULL')` - returns `null`\n    1. `Env::get('LOWERCASE')` - returns `'abc123'`\n    1. `Env::get('UPPERCASE')` - returns `'ABC123'`\n\n* **requireEnv** - `public static function requireEnv($varname)`\n\n    1. `Env::requireEnv('NOTFOUND')` - throws `EnvVarNotFoundException`\n    1. `Env::requireEnv('EMPTY')` - throws `EnvVarNotFoundException`\n    1. `Env::requireEnv('WHITESPACE')` - returns `'Some whitespace'`\n    1. `Env::requireEnv('FALSE')` - returns `false`\n    1. `Env::requireEnv('LOWERCASE')` - returns `'abc123'`\n\n* **getArray** - `public static function getArray($varname, array $default = [])`\n\n    1. `Env::getArray('NOTFOUND')` - returns `[]`\n    1. `Env::getArray('NOTFOUND', ['one', 'two'])` - returns `['one', 'two']`\n    1. `Env::getArray('NOTFOUND', 'one,two,three')` - throws `TypeError` exception\n    1. `Env::getArray('ARRAY0')` - returns `['']`\n    1. `Env::getArray('ARRAY1')` - returns `['one']`\n    1. `Env::getArray('ARRAY')` - returns `['one', 'two', '', 'three']`\n\n* **requireArray** - `public static function requireArray($varname)`\n\n    1. `Env::requireArray('NOTFOUND')` - throws `EnvVarNotFoundException`\n    1. `Env::requireArray('EMPTY')` - throws `EnvVarNotFoundException`\n    1. `Env::requireArray('ARRAY1')` - returns `['one']`\n    1. `Env::requireArray('ARRAY')` - returns `['one', 'two', '', 'three']`\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilinternational%2Fphp-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsilinternational%2Fphp-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilinternational%2Fphp-env/lists"}