An open API service indexing awesome lists of open source software.

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

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**

[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*