{"id":18309807,"url":"https://github.com/phpdevcommunity/php-dotenv","last_synced_at":"2025-04-12T15:38:13.325Z","repository":{"id":44425298,"uuid":"316993996","full_name":"phpdevcommunity/php-dotenv","owner":"phpdevcommunity","description":"PHP-DotEnv is a lightweight PHP library designed to simplify the management of environment variables in your PHP applications.","archived":false,"fork":false,"pushed_at":"2024-12-05T18:35:26.000Z","size":44,"stargazers_count":76,"open_issues_count":0,"forks_count":25,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-03T16:11:18.764Z","etag":null,"topics":["component","dotenv","dotenv-loader","dotenv-parser","php-library","php7"],"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/phpdevcommunity.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":"2020-11-29T16:30:03.000Z","updated_at":"2025-02-02T08:12:19.000Z","dependencies_parsed_at":"2024-11-05T16:12:43.024Z","dependency_job_id":"bbc3a02b-8e1a-46bd-afda-e015b1c816bb","html_url":"https://github.com/phpdevcommunity/php-dotenv","commit_stats":{"total_commits":22,"total_committers":8,"mean_commits":2.75,"dds":0.6818181818181819,"last_synced_commit":"50bc75ae13a670766e10e2d916774b2923140c0d"},"previous_names":["phpdevcommunity/php-dotenv","devcoder-xyz/php-dotenv"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpdevcommunity%2Fphp-dotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpdevcommunity%2Fphp-dotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpdevcommunity%2Fphp-dotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpdevcommunity%2Fphp-dotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpdevcommunity","download_url":"https://codeload.github.com/phpdevcommunity/php-dotenv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248590568,"owners_count":21129848,"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":["component","dotenv","dotenv-loader","dotenv-parser","php-library","php7"],"created_at":"2024-11-05T16:12:28.441Z","updated_at":"2025-04-12T15:38:13.272Z","avatar_url":"https://github.com/phpdevcommunity.png","language":"PHP","readme":"# PHP-DotEnv \n\nPHP-DotEnv is a lightweight PHP library designed to simplify the management of environment variables in your PHP applications. It provides an elegant solution for loading configuration values from a `.env` file into the environment variables accessible via `getenv()`, `$_ENV`, and `$_SERVER`. This documentation aims to guide you through the installation, usage, and features of PHP-DotEnv.\n\n## Installation\n\nTo install PHP-DotEnv, you can use [Composer](https://getcomposer.org/), the dependency manager for PHP.\n\n### Composer Require\n```bash\ncomposer require phpdevcommunity/php-dotenv\n```\n\n## Requirements\n\n- PHP version 7.4 or higher\n\n## Usage\n\n### 1. Define Environment Variables\n\nBefore using PHP-DotEnv, you need to define your environment variables in a `.env` file. This file should be placed in the root directory of your project. Each line in the file should follow the `KEY=VALUE` format.\n\n```dotenv\nAPP_ENV=dev\nDATABASE_DNS=mysql:host=localhost;dbname=test;\nDATABASE_USER=\"root\"\nDATABASE_PASSWORD=root\nMODULE_ENABLED=true\nNUMBER_LITERAL=0\nNULL_VALUE=null\n```\n\n### 2. Load the Variables\n\nAfter defining your environment variables, you can load them into your PHP application using PHP-DotEnv.\n\n```php\n\u003c?php\nuse PhpDevCommunity\\DotEnv;\n\n$absolutePathToEnvFile = __DIR__ . '/.env';\n\n(new DotEnv($absolutePathToEnvFile))-\u003eload();\n```\n\n### 3. Access Environment Variables\n\nOnce loaded, you can access the environment variables using PHP's `getenv()` function.\n\n```php\n/**\n * Retrieve the value of DATABASE_DNS\n */\nvar_dump(getenv('DATABASE_DNS'));\n```\n\n### Automatic Type Conversion\n\nPHP-DotEnv provides automatic type conversion for certain types of values:\n\n- Booleans: Processed as `true` or `false`.\n- Quoted Strings: Surrounding quotes are removed.\n- Null Values: Converted to `null`.\n- Numeric Values: Converted to integers or floats.\n\n## Processors\n\nPHP-DotEnv allows you to define custom processors to handle specific types of values in your `.env` file. These processors enable you to control how values are parsed and converted.\n\n### BooleanProcessor\n\nThe `BooleanProcessor` converts boolean values specified in the `.env` file to PHP boolean types (`true` or `false`).\n\n```dotenv\nMODULE_ENABLED=true\n```\n\n### QuotedProcessor\n\nThe `QuotedProcessor` removes surrounding quotes from quoted strings in the `.env` file.\n\n```dotenv\nDATABASE_USER=\"root\"\n```\n\n### NullProcessor\n\nThe `NullProcessor` converts the string \"null\" to the PHP `null` value.\n\n```dotenv\nNULL_VALUE=null\n```\n\n### NumberProcessor\n\nThe `NumberProcessor` converts numeric values to integers or floats.\n\n```dotenv\nNUMBER_LITERAL=0\n```\n\n## Conclusion\n\nPHP-DotEnv offers a straightforward and efficient solution for managing environment variables in PHP applications. By providing automatic type conversion and customizable processors, it simplifies the process of loading and handling configuration values from `.env` files. Whether you're working on a small project or a large-scale application, PHP-DotEnv can help streamline your development process and ensure smooth configuration management. Explore its features, integrate it into your projects, and experience the convenience it brings to your PHP development workflow.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpdevcommunity%2Fphp-dotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpdevcommunity%2Fphp-dotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpdevcommunity%2Fphp-dotenv/lists"}