{"id":23881771,"url":"https://github.com/fkrzski/dotenv","last_synced_at":"2025-02-23T01:12:46.211Z","repository":{"id":44684010,"uuid":"448257977","full_name":"fkrzski/Dotenv","owner":"fkrzski","description":"Library that adds the ability to access variables from '.env', $_ENV, and $_SERVER using the getenv() function","archived":false,"fork":false,"pushed_at":"2022-01-31T13:14:43.000Z","size":43,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-04T01:58:46.699Z","etag":null,"topics":["configuration","dotenv","env","environment","environment-variables","php"],"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/fkrzski.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}},"created_at":"2022-01-15T11:27:15.000Z","updated_at":"2022-01-27T20:07:51.000Z","dependencies_parsed_at":"2022-09-04T04:41:48.299Z","dependency_job_id":null,"html_url":"https://github.com/fkrzski/Dotenv","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkrzski%2FDotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkrzski%2FDotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkrzski%2FDotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fkrzski%2FDotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fkrzski","download_url":"https://codeload.github.com/fkrzski/Dotenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240254292,"owners_count":19772392,"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":["configuration","dotenv","env","environment","environment-variables","php"],"created_at":"2025-01-04T01:58:52.571Z","updated_at":"2025-02-23T01:12:46.185Z","avatar_url":"https://github.com/fkrzski.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dotenv\nLibrary that adds the ability to access variables from '.env', $_ENV, and $_SERVER using the getenv() function\n\n# Installation\n```shell\ncomposer require fkrzski/dotenv\n```\n\n# Usage\n\n### Basics\nAdd your application configuration variables to `.env` file in your project. Next add `.env` to `.gitignore` file! You should create a `.env.example` file to have a skeleton with variable names for your contributors\n```shell\nAPP_NAME=\"My App Name\"  # My app name\nAPI_KEY=YourApiKey      # My api key\n```\n\n### Include ` Dotenv ` class\n```php\nuse Dotenv\\Dotenv;\n```\n\n### Load ` .env ` variables\n```php\n$dotenv = new Dotenv('.env');\n$dotenv-\u003estart();\n```\n\n### Custom path or file name\n```php\n$dotenv = new Dotenv('path/to/file/myenvfile.env');\n\n// Now you are using myenvfile.env from /path/to/file folder\n```\n\n### Many `.env` files\n```php\n$dotenv = new Dotenv('path/to/file/myenvfile.env', 'path/to/file/mysecondenvfile.env');\n```\n\n### Retrieving variables values\n```php\necho getenv('APP_NAME');\necho $_SERVER['APP_NAME'];\necho $_ENV['APP_NAME'];\n\n// output: My App Name\n```\n\n### Overwrtitting a variable\n`.env` file\n```shell\nAPP_NAME=\"App Name\"\nAPI_KEY=ApiKey\n\nAPP_NAME=\"Second App Name\"\nAPI_KEY=SecondApiKey\n```\n\nPHP file\n```php\n$dotenv-\u003estart(['APP_NAME']);\n\necho getenv('APP_NAME');\necho getenv('API_KEY');\n\n// Output:\n// Second App Name\n// ApiKey\n```\n\nSecond possibility\n`.env` file\n```shell\nAPP_NAME=\"App Name\"\nAPI_KEY=ApiKey\n\nAPP_NAME=\"Second App Name\"\nAPI_KEY=SecondApiKey\n```\n\nPHP file\n```php\n$dotenv-\u003estart(['*']);\n\necho getenv('APP_NAME');\necho getenv('API_KEY');\n\n// Output:\n// Second App Name\n// SecondApiKey\n```\n\n### Validating and requiring variables\n`.env` file\n```shell\nAPP_NAME=\"App Name\"\nPHONE_NUMBER=111222333\n```\n\nPHP file\n```php\n$dotenv-\u003estart();\n\n$dotenv-\u003evalidator()-\u003evalidate([\n    'APP_NAME'     =\u003e 'required|alnum',\n    'PHONE_NUMBER' =\u003e 'required|integer',\n]);\n\n/* All validating rules:\n * - required\n * - letters (Letters and spaces only)\n * - alnum (Letters, numers and spaces)\n * - integer\n * - boolean (true/false)\n * - float\n */ \n```\n\n### Put single variable\n```php\nDotenv::single('VAR', 'value');\necho getenv(\"VAR\");\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffkrzski%2Fdotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffkrzski%2Fdotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffkrzski%2Fdotenv/lists"}