{"id":17437125,"url":"https://github.com/kariricode-framework/kariricode-dotenv","last_synced_at":"2026-01-30T01:14:03.380Z","repository":{"id":257823784,"uuid":"870292169","full_name":"KaririCode-Framework/kariricode-dotenv","owner":"KaririCode-Framework","description":"A highly optimized, extensible, and reliable Dotenv component designed to load environment variables for PHP applications in the KaririCode Framework, ensuring secure and efficient configuration management.","archived":false,"fork":false,"pushed_at":"2024-10-30T22:01:45.000Z","size":119,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-12-02T22:45:58.859Z","etag":null,"topics":["dotenv","env","environment","environment-variables","framework","kariricode","php"],"latest_commit_sha":null,"homepage":"https://kariricode.org","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/KaririCode-Framework.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":"2024-10-09T19:20:42.000Z","updated_at":"2024-10-30T22:01:21.000Z","dependencies_parsed_at":"2024-10-19T10:11:28.086Z","dependency_job_id":null,"html_url":"https://github.com/KaririCode-Framework/kariricode-dotenv","commit_stats":null,"previous_names":["kariricode-framework/kariricode-dotenv"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaririCode-Framework%2Fkariricode-dotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaririCode-Framework%2Fkariricode-dotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaririCode-Framework%2Fkariricode-dotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaririCode-Framework%2Fkariricode-dotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KaririCode-Framework","download_url":"https://codeload.github.com/KaririCode-Framework/kariricode-dotenv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228555268,"owners_count":17936319,"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","env","environment","environment-variables","framework","kariricode","php"],"created_at":"2024-10-17T11:05:54.460Z","updated_at":"2026-01-30T01:14:03.347Z","avatar_url":"https://github.com/KaririCode-Framework.png","language":"PHP","readme":"# KaririCode Framework: Dotenv Component\n\n[![en](https://img.shields.io/badge/lang-en-red.svg)](README.md) [![pt-br](https://img.shields.io/badge/lang-pt--br-green.svg)](README.pt-br.md)\n\n![PHP](https://img.shields.io/badge/PHP-777BB4?style=for-the-badge\u0026logo=php\u0026logoColor=white) ![Docker](https://img.shields.io/badge/Docker-2496ED?style=for-the-badge\u0026logo=docker\u0026logoColor=white) ![PHPUnit](https://img.shields.io/badge/PHPUnit-3776AB?style=for-the-badge\u0026logo=php\u0026logoColor=white)\n\nA robust and flexible environment variable management component for the KaririCode Framework, providing advanced features for handling .env files in PHP applications.\n\n## Features\n\n- Parse and load environment variables from .env files\n- Support for variable interpolation\n- **Automatic type detection and casting**\n  - Detects and converts common types (string, integer, float, boolean, array, JSON)\n  - Preserves data types for more accurate usage in your application\n- **Customizable type system**\n  - Extensible with custom type detectors and casters\n  - Fine-grained control over how your environment variables are processed\n- Strict mode for variable name validation\n- Easy access to environment variables through a global helper function\n- Support for complex data structures (arrays and JSON) in environment variables\n\n## Installation\n\nTo install the KaririCode Dotenv component in your project, run the following command:\n\n```bash\ncomposer require kariricode/dotenv\n```\n\n## Usage\n\n### Basic Usage\n\n1. Create a `.env` file in your project's root directory:\n\n```env\nKARIRI_APP_ENV=develop\nKARIRI_APP_NAME=KaririCode\nKARIRI_PHP_VERSION=8.3\nKARIRI_PHP_PORT=9003\nKARIRI_APP_DEBUG=true\nKARIRI_APP_URL=https://kariricode.com\nKARIRI_MAIL_FROM_NAME=\"${KARIRI_APP_NAME}\"\nKARIRI_JSON_CONFIG={\"key\": \"value\", \"nested\": {\"subkey\": \"subvalue\"}}\nKARIRI_ARRAY_CONFIG=[\"item1\", \"item2\", \"item with spaces\"]\n```\n\n2. In your application's bootstrap file:\n\n```php\n\u003c?php\n\nrequire_once __DIR__ . '/../vendor/autoload.php';\n\nuse KaririCode\\Dotenv\\DotenvFactory;\nuse function KaririCode\\Dotenv\\env;\n\n$dotenv = DotenvFactory::create(__DIR__ . '/../.env');\n$dotenv-\u003eload();\n\n// Now you can use the env() function to access your environment variables\n$appName = env('KARIRI_APP_NAME');\n$debug = env('KARIRI_APP_DEBUG');\n$jsonConfig = env('KARIRI_JSON_CONFIG');\n$arrayConfig = env('KARIRI_ARRAY_CONFIG');\n```\n\n### Type Detection and Casting\n\nThe KaririCode Dotenv component automatically detects and casts the following types:\n\n- Strings\n- Integers\n- Floats\n- Booleans\n- Null values\n- Arrays\n- JSON objects\n\nExample:\n\n```env\nSTRING_VAR=Hello World\nINT_VAR=42\nFLOAT_VAR=3.14\nBOOL_VAR=true\nNULL_VAR=null\nARRAY_VAR=[\"item1\", \"item2\", \"item3\"]\nJSON_VAR={\"key\": \"value\", \"nested\": {\"subkey\": \"subvalue\"}}\n```\n\nWhen accessed using the `env()` function, these variables will be automatically cast to their appropriate PHP types:\n\n```php\n$stringVar = env('STRING_VAR'); // string: \"Hello World\"\n$intVar = env('INT_VAR');       // integer: 42\n$floatVar = env('FLOAT_VAR');   // float: 3.14\n$boolVar = env('BOOL_VAR');     // boolean: true\n$nullVar = env('NULL_VAR');     // null\n$arrayVar = env('ARRAY_VAR');   // array: [\"item1\", \"item2\", \"item3\"]\n$jsonVar = env('JSON_VAR');     // array: [\"key\" =\u003e \"value\", \"nested\" =\u003e [\"subkey\" =\u003e \"subvalue\"]]\n```\n\nThis automatic typing ensures that you're working with the correct data types in your application, reducing type-related errors and improving overall code reliability.\n\n### Advanced Usage\n\n#### Custom Type Detectors\n\nCreate custom type detectors to handle specific formats:\n\n```php\nuse KaririCode\\Dotenv\\Type\\Detector\\AbstractTypeDetector;\n\nclass CustomDetector extends AbstractTypeDetector\n{\n    public const PRIORITY = 100;\n\n    public function detect(mixed $value): ?string\n    {\n        // Your detection logic here\n        // Return the detected type as a string, or null if not detected\n    }\n}\n\n$dotenv-\u003eaddTypeDetector(new CustomDetector());\n```\n\n#### Custom Type Casters\n\nCreate custom type casters to handle specific data types:\n\n```php\nuse KaririCode\\Dotenv\\Contract\\Type\\TypeCaster;\n\nclass CustomCaster implements TypeCaster\n{\n    public function cast(mixed $value): mixed\n    {\n        // Your casting logic here\n    }\n}\n\n$dotenv-\u003eaddTypeCaster('custom_type', new CustomCaster());\n```\n\n## Development and Testing\n\nFor development and testing purposes, this package uses Docker and Docker Compose to ensure consistency across different environments. A Makefile is provided for convenience.\n\n### Prerequisites\n\n- Docker\n- Docker Compose\n- Make (optional, but recommended for easier command execution)\n\n### Setup for Development\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/KaririCode-Framework/kariricode-dotenv.git\n   cd kariricode-dotenv\n   ```\n\n2. Set up the environment:\n\n   ```bash\n   make setup-env\n   ```\n\n3. Start the Docker containers:\n\n   ```bash\n   make up\n   ```\n\n4. Install dependencies:\n   ```bash\n   make composer-install\n   ```\n\n### Available Make Commands\n\n- `make up`: Start all services in the background\n- `make down`: Stop and remove all containers\n- `make build`: Build Docker images\n- `make shell`: Access the shell of the PHP container\n- `make test`: Run tests\n- `make coverage`: Run test coverage with visual formatting\n- `make cs-fix`: Run PHP CS Fixer to fix code style\n- `make quality`: Run all quality commands (cs-check, test, security-check)\n\nFor a full list of available commands, run:\n\n```bash\nmake help\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Support and Community\n\n- **Documentation**: [https://kariricode.org/docs/dotenv](https://kariricode.org/docs/dotenv)\n- **Issue Tracker**: [GitHub Issues](https://github.com/KaririCode-Framework/kariricode-dotenv/issues)\n- **Community**: [KaririCode Club Community](https://kariricode.club)\n\n## Acknowledgments\n\n- The KaririCode Framework team and contributors.\n- Inspired by other popular PHP Dotenv libraries.\n\n---\n\nBuilt with ❤️ by the KaririCode team. Empowering developers to build more robust and flexible PHP applications.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkariricode-framework%2Fkariricode-dotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkariricode-framework%2Fkariricode-dotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkariricode-framework%2Fkariricode-dotenv/lists"}