• Stars
    star
    150
  • Rank 247,323 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 9 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Makes values from a .env file available as environment variables for composer based projects

dotenv connector Build Status

This is a composer plugin, that makes environment variables from a .env file available for any composer based project, without the need to modify code in the project.

Background info

You may want to read why it is a good idea to store config in the environment. The idea of dotenv is to make this as easy as possible and this is why the phpdotenv library was created. phpdotenv loads environment variables from an .env file to getenv(), $_ENV and $_SERVER, but you need to add the parsing code for that yourself.

composer + symfony/dotenv + dotenv connector = <3

The idea of this library is, that every composer managed project, a .env file (in the same location as your root composer.json) is automatically parsed and loaded, at composer autoload initialisation time. This means that the environment variables are available very early, so that you can use it also during boot time of your application.

If the environment variable APP_ENV is set to any value, or the specified .env file does not exist, no operation is performed, so that you can safely require this package for production.

If you have the possibility to expose environment variables in a production environment, it is recommended to do so and also set APP_ENV and use the variables that are directly exposed in the environment.

However for smaller scale projects it is still a valid and easy solution to use a .env file also for production environments.

configuration options

Usually you don't need any configuration options. However if you need to, you can adapt the path or name of the .env to fit your requirements.

You configure dotenv connector in the extra section of the root composer.json file like that:

  "extra": {
      "helhum/dotenv-connector": {
          "env-file": ".env",
          "adapter": "Helhum\\DotEnvConnector\\Adapter\\SymfonyDotEnv"
      }
    }

env-file

You can specify a relative path from the base directory, if you want to put your .env file a different location.

The default value is ".env", which means next to your root composer.json.

Side note for quoting values in the .env file

As the .env file parsing behaves like if it was included in a shell, you have to be aware of that values with literal $ signs need to be enclosed in single quotes. This may be the case if you use hashed values of credentials you pass via .env, for example.

adapter

You can specify a class that implements \Helhum\DotEnvConnector\DotEnvVars interface, if you need a different way to expose env vars.

The default value is "Helhum\DotEnvConnector\Adapter\SymfonyDotEnv", which uses symfony/dotenv default parsing of the one .env file.

This could be useful though e.g. if you prefer to use another dotenv parsing library to expose the variables defined in .env or you want to switch to another parsing strategy of the Symfony dotenv parsing. In the latter case use "Helhum\DotEnvConnector\Adapter\SymfonyLoadEnv" as value for this option. Have a look at the existing implementations for examples.

Feedback

Any feedback is appreciated. Please write bug reports, feature request, create pull requests, or just drop me a "thank you" via Twitter or spread the word.

Thank you!

More Repositories

1

upload_example

File Upload using Extbase and FAL
PHP
102
star
2

TYPO3-Distribution

A distribution package for TYPO3 CMS with added typo3_console support
PHP
81
star
3

typoscript_rendering

Render a TypoScript path by URL, especially useful for Ajax dispatching
PHP
66
star
4

typo3-secure-web

Secure your TYPO3 installation by only exposing public files
PHP
60
star
5

ext_scaffold

Extension skeleton for TYPO3 >= 7.4.0 including complete test setup
PHP
38
star
6

typo3-config-handling

Manage TYPO3 configuration for multiple environments or contexts with ease
PHP
35
star
7

realurl

TYPO3 CMS Extension RealURL fork
PHP
35
star
8

typo3-crontab

Improved command scheduling for TYPO3
PHP
31
star
9

config-loader

PHP
28
star
10

sentry-typo3

TYPO3 Sentry integration
PHP
20
star
11

ajax_example

PHP
18
star
12

typo3-composer-step-by-step-example

Shell
14
star
13

typo3-composer-setup

PHP
13
star
14

typo3-frontend-request

PHP
13
star
15

minimal-typo3-distribution

PHP
12
star
16

Surf.CMS

A TYPO3 Surf distribution featuring additional tools for TYPO3 CMS deployments
PHP
11
star
17

typo3-top-image

PHP
8
star
18

deprecated-class-alias-loader

This project is abandoned in favor of its successor: https://github.com/TYPO3/class-alias-loader
PHP
7
star
19

ter-client

PHP
7
star
20

typo3-deployer-recipe

PHP
6
star
21

TYPO3SurfCms.SurfTools

PHP
5
star
22

env-ts

PHP
4
star
23

TYPO3.IHS

Incident Handling System
CSS
4
star
24

t3satis

Repository Generator with support for TYPO3 CMS extension (git) repositories
PHP
4
star
25

ext-tools

PHP
3
star
26

fluid_security

Demo TYPO Extension which only features some tests for presentation purposes
PHP
3
star
27

image_cropper_test

PHP
2
star
28

typo3-env-enabled-patch

2
star
29

php-error-reporting

PHP
2
star
30

typo3-no-symlink-install

PHP
2
star
31

TYPO3.Surf.Distribution

TYPO3 Surf Distribution featuring tools to accomodate TYPO3 CMS deployments
1
star
32

easydb-typo3-integration

easydb integration for TYPO3
PHP
1
star