Download the PHP package phpdevcommunity/php-dotenv without Composer
On this page you can find all versions of the php package phpdevcommunity/php-dotenv. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phpdevcommunity/php-dotenv
More information about phpdevcommunity/php-dotenv
Files in phpdevcommunity/php-dotenv
Package php-dotenv
Short Description PHP-DotEnv is a lightweight PHP library designed to simplify the management of environment variables in your PHP applications.
License MIT
Informations about the package php-dotenv
PHP-DotEnv
PHP-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.
Installation
To install PHP-DotEnv, you can use Composer, the dependency manager for PHP.
Composer Require
Requirements
- PHP version 7.4 or higher
Usage
1. Define Environment Variables
Before 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.
2. Load the Variables
After defining your environment variables, you can load them into your PHP application using PHP-DotEnv.
3. Access Environment Variables
Once loaded, you can access the environment variables using PHP's getenv()
function.
Automatic Type Conversion
PHP-DotEnv provides automatic type conversion for certain types of values:
- Booleans: Processed as
true
orfalse
. - Quoted Strings: Surrounding quotes are removed.
- Null Values: Converted to
null
. - Numeric Values: Converted to integers or floats.
Processors
PHP-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.
BooleanProcessor
The BooleanProcessor
converts boolean values specified in the .env
file to PHP boolean types (true
or false
).
QuotedProcessor
The QuotedProcessor
removes surrounding quotes from quoted strings in the .env
file.
NullProcessor
The NullProcessor
converts the string "null" to the PHP null
value.
NumberProcessor
The NumberProcessor
converts numeric values to integers or floats.
Conclusion
PHP-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.