https://github.com/tina4stack/tina4php-env
Environment support for your PHP project
https://github.com/tina4stack/tina4php-env
Last synced: 3 months ago
JSON representation
Environment support for your PHP project
- Host: GitHub
- URL: https://github.com/tina4stack/tina4php-env
- Owner: tina4stack
- Created: 2021-06-23T22:21:08.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-08-19T13:29:14.000Z (10 months ago)
- Last Synced: 2025-09-16T08:35:28.507Z (9 months ago)
- Language: PHP
- Size: 61.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# tina4php-env
Environment variable loader for the Tina4 PHP framework, reading `.env` files and exposing values as PHP constants and `$_ENV` entries.
## Installation
```bash
composer require tina4stack/tina4php-env
```
## Requirements
- PHP >= 8.1
## Usage
### Basic .env File
Create a `.env` file in your project root:
```ini
[Database]
DB_HOST=localhost
DB_PORT=3306
DB_NAME=myapp
[App]
APP_DEBUG=true
VERSION=1.0.0
```
### Loading the Environment
```php
use Tina4\Env;
// Loads .env from the project root
new Env();
// Access variables as constants or via $_ENV
echo DB_HOST; // "localhost"
echo $_ENV["DB_NAME"]; // "myapp"
```
### Environment-Specific Files
Set an `ENVIRONMENT` OS variable to load `.env.{ENVIRONMENT}` instead:
```php
// If ENVIRONMENT=staging, loads .env.staging
new Env();
// Or force a specific environment
new Env("production"); // loads .env.production
```
## Testing
```bash
composer test
```
## License
MIT - see [LICENSE](LICENSE)
---
## Our Sponsors
**Sponsored with 🩵 by Code Infinity**
[
](https://codeinfinity.co.za/about-open-source-policy?utm_source=github&utm_medium=website&utm_campaign=opensource_campaign&utm_id=opensource)
*Supporting open source communities • Innovate • Code • Empower*