josegarcia/nexus

Helps to read and inject all the variables from the .env file into the global variables $_env and $-_server

1.0.3 2024-02-26 01:55 UTC

This package is auto-updated.

Last update: 2025-06-16 02:23:26 UTC


README

  • A utility package designed to read .env files and inject environment variables into your PHP application.

Description

  • Nexus provides an easy and configuration-free method for loading environment variables from a .env file. It’s a lightweight and user-friendly solution to manage environment settings in your application.

Features

  • Load environment variables from a .env file into your application.
  • Access environment variables using getenv(), $_ENV, or $GLOBALS.
  • No configuration required.
  • No dependencies.
  • Lightweight.
  • Easy to use.
  • Works with PHP 7.4 and above.
  • Works with any PHP framework, library, or application.

Installation

composer require josegarcia/nexus

Usage

use Garcia\Nexus;

$filePath = __DIR__ . '/.env.test'; // Assuming .env is present for testing purposes

// Create a temporary .env file for testing
file_put_contents($filePath, "TEST_VAR=123\nANOTHER_VAR=abc");

// Load the .env file
Nexus::load($filePath);

// Check if environment variables are set
echo getenv('TEST_VAR') . "\n";
echo $_ENV['ANOTHER_VAR'] . "\n";
echo $GLOBALS['TEST_VAR'] . "\n";
echo getenv('ANOTHER_VAR') . "\n";