Php DotEnv
A simple and standalone DotEnv parser for PHP 5.6+
Any contribution or feedback is highly welcomed, please feel free to create a pull request or submit a new issue.
Installation
Simply install the library using composer:
composer require bgaze/php-dotenv
Usage
Quick start
This package ships two classes :
Bgaze\Dotenv\Parser
wich do the parsing job.Bgaze\Dotenv\Helpers
wich provides static functions for a quick usage of the parser.
To quickly parse Dotenv, use helper functions from the Helpers
class:
use \Bgaze\Dotenv\Helpers as DotEnv;
try {
var_dump(DotEnv::fromString('a dotenv string', [ /* some default values */ ]));
} catch (\Exception $e) {
echo "<pre>{$e}</pre>";
}
try {
var_dump(DotEnv::fromFile('path/to/dotenv/file', [ /* some default values */ ]));
} catch (\Exception $e) {
echo "<pre>{$e}</pre>";
}
You can also use directly the Parser
class:
use \Bgaze\Dotenv\Parser;
$parser = new Parser();
if ($parser->parseString('a dotenv string')) {
var_dump($parser->get());
} else {
var_dump($parser->errors());
}
if ($parser->parseFile('path/to/dotenv/file')) {
var_dump($parser->get());
} else {
var_dump($parser->errors());
}
Helpers class
fromString:
Parse provided string, throw an exception if invalid, otherwise return parsed content as a key-value array.
/**
* @param string $string The string to parse
* @param array $defaults An array of defaults values
* @return array The parsed content
*
* @throws \UnexpectedValueException
*/
public static function fromString($string, array $defaults = []);
fromFile:
Parse provided file, throw an exception if invalid, otherwise return parsed content as a key-value array.
/**
* @param string $path The file to parse
* @param array $defaults An array of defaults values
* @return array The parsed content
*
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
*/
public static function fromFile($path, array $defaults = []);
Parser class
parseString:
Reset parser then parse provided string.
/**
* @param string $string The string to parse
* @return boolean
*/
public function parseString($string);
parseFile:
Reset parser then parse provided file.
/**
* @param string $path Path oh the file to parse
* @return boolean
*/
public function parseFile($path);
get:
Get parsed content array.
/**
* @return array
*/
public function get();
errors:
Get parsing errors array.
/**
* @return array
*/
public function errors();
Packages
Feel free to visit my other packages:
Bootstrap 4 forms builder for Laravel 5.8+
This package uses in background Laravel Collective HTML to simplify Bootstrap 4 forms creation into Laravel applications.
Model form binding and automatic error display are supported, as well as most of Bootstrap forms features : form layouts, custom fields, input groups, ...
PHP-CS-Fixer for Laravel 5.5+
This package allows to use PHP-CS-Fixer right into Laravel 5.5+ applications to format PHP code.
Bootstrap 4 dialogs
BSD is a tiny and flexible collection of dialog popups based on Bootstrap 4 modals.
Custom dialogs can be easily defined, in addition to built-in ones (alert, confirm and prompt).
Bootstrap Color Palette
BCP is a simple color palette for Bootstrap 4, like in Google doc, built on the top of Bootstrap 4 Popover plugin.
Laravel Kvstore
A simple and easy to use key-value database store for Laravel 5.5+
All values are stored into database and managed using cache to avoid unecessary queries.
Casting is supported to manage values type.
Blade Indenter
A very simple formatter for Laravel 5.8+ Blade templates