crasivo / bitrix-dotenv
Dotenv library adapter for 1C-Bitrix
                                    Fund package maintenance!
                                                                            
                                                                                                                                        crasivo
                                                                                    
                                                                
Installs: 3
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/crasivo/bitrix-dotenv
Requires
- php: ^7.2 || ^8.0
- vlucas/phpdotenv: >=5.0
This package is auto-updated.
Last update: 2025-10-18 14:29:31 UTC
README
Adapter for the popular Dotenv library for 1C-Bitrix & Bitrix24.
Implementation features:
- Simple and quick integration into an existing project
- Formatting of scalar values
Minimum requirements for installation:
- 1C-Bitrix kernel version (main): v20.5.400
- PHP version: v7.2
- Dotenv version: v5.0
🚀 Quick Start
To use the library (adapter), simply install the Composer package via the command:
$ cd /path/to/project
$ composer require crasivo/bitrix-dotenv
It is initially assumed that autoload.php is already connected to your project.
If this is not the case, you can add it to one of the following files:
- /bitrix/.settings.php
- /bitrix/.settings_extra.php
- /local/php_interface/init.php
Next, you need to initialize the EnvLocator service (similar to the standard one) and load the environment variables.
Below is an example of initializing and loading environment variables.
// document root Crasivo\Bitrix\Dotenv\EnvLocator::getInstance()->load(); // specified dir Crasivo\Bitrix\Dotenv\EnvLocator::getInstance()->load('/path/to/another/dir');
Access to values is via EnvLocator or via the helper function env.
Below are examples of working with environment variables.
$envLocator = Crasivo\Bitrix\Dotenv\EnvLocator::getInstance(); echo $envLocator->get('LOG_LEVEL', 'debug'); // 'debug' (string) echo $envLocator->get('APP_DEBUG', false); // true (bool) echo $envLocator->get('SOME_INTEGER_PARAM'); // 415454 (integer) echo $envLocator->get('SOME_FLOAT_PARAM'); // 154.69 (float)
Via the helper function:
echo env('LOG_LEVEL', 'debug'); // 'debug' (string) echo env('APP_DEBUG', false); // true (bool) echo env('SOME_INTEGER_PARAM'); // 415454 (integer) echo env('SOME_FLOAT_PARAM'); // 154.69 (float)
📜 License
This project is distributed under the MIT license. The full text of the license can be read in the corresponding file.