• Stars
    star
    248
  • Rank 163,560 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 7 years ago
  • Updated about 1 year ago

Reviews

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

Repository Details

Companion for .env files

Companienv

Your companion for .env files. Everybody knows about 12 factor and environments variables now. A lot of frameworks such as Symfony are using a .env file to configure the application, but we don't have anything to help users to complete their local .env file.

Companienv will helps you manage the .env files, from a reference .env.dist version in your code repository. Companienv can:

Usage

  1. Require sroze/companienv as your project dependency:
composer req sroze/companienv
  1. Run your companion:
vendor/bin/companienv

Composer automation

You can run Companienv automatically after composer install or composer update commands by configuring the scripts in your composer.json file:

{
    "scripts": {
        "post-install-cmd": [
            "Companienv\\Composer\\ScriptHandler::run"
        ],
        "post-update-cmd": [
            "Companienv\\Composer\\ScriptHandler::run"
        ]
    }
}

By default, the file used as a template is .env.dist and the written file is .env. You can change these defaults within your composer.json file:

{
    "extra": {
        "companienv-parameters": [
            {
                "file": ".env.foo",
                "dist-file": ".env.foo.dist"
            }
        ]
    }
}

The .env.dist file

All your configuration is directly in your .env.dist file, as comments. The configuration is divided in blocks that will be displayed to the user for a greater understanding of the configuration. Here are the fondations for Companienv:

  • Blocks. They logically group variables together. They are defined by a title (line starting with a double-comment ##) and a description (every comment line directly bellow)
  • Attributes. Defined by a line starting with #+, an attribute is associated to one or multiple variables. These attributes are the entrypoint for extensions. In the example above, it says that the JWT_* variables are associated with an RSA key pair, so Companienv will automatically offer the user to generate one for them.
  • Comments. Lines starting by #~ will be ignored by Companienv.

Example of .env.dist. file

# .env.dist

## Welcome in the configuration of [my-project]
#
#~ Please run the `bin/start` command.
#~ These lines starting with `~` are not going to be displayed to the user

## GitHub
# In order to be able to login with GitHub, you need to create a GitHub application. To get access to the code
# repositories, you need to create a GitHub integration.
#
#+file-to-propagate(GITHUB_INTEGRATION_KEY_PATH)
#
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GITHUB_INTEGRATION_ID=
GITHUB_INTEGRATION_KEY_PATH=
GITHUB_SECRET=

## Security
# We need sauce! Well, no, we need an SSL certificate.
#
#+rsa-pair(JWT_PRIVATE_KEY_PATH JWT_PUBLIC_KEY_PATH JWT_PRIVATE_KEY_PASS_PHRASE)
#
JWT_PRIVATE_KEY_PATH=/runtime/keys/jwt-private.pem
JWT_PUBLIC_KEY_PATH=/runtime/keys/jwt-public.pem
JWT_PRIVATE_KEY_PASS_PHRASE=

## Another block
# With its (optional) description
AND_OTHER_VARIABLES=

Built-in extensions

only-if extension

Some of the blocks of your .env file might not even be relevant if some other variable was disabling a given feature.

Example: This will only ask for the INTERCOM_APPLICATION_ID variable if INTERCOM_ENABLED has the value (current or entered by the user) true.

## Support & Feedback
# If you would like to allow your users to get some support from you, give you some feedback and this
# sort of things, select the integrations you'd like.
#
#+only-if(INTERCOM_APPLICATION_ID):(INTERCOM_ENABLED=true)
#
INTERCOM_ENABLED=false
INTERCOM_APPLICATION_ID=none

file-to-propagate extension

Will ask the path of an existing file and copy it to the destination mentioned in the reference.

Example: this will ask the user to give the path of an existing file. It will copy this file to the path /runtime/keys/firebase.json, relative to the root directory of the project.

#+file-to-propagate(FIREBASE_SERVICE_ACCOUNT_PATH)
FIREBASE_SERVICE_ACCOUNT_PATH=/runtime/keys/firebase.json

rsa-pair extension

If the public/private key pair does not exist, Companienv will offer to generate one for the user.

#+rsa-pair(JWT_PRIVATE_KEY_PATH JWT_PUBLIC_KEY_PATH JWT_PRIVATE_KEY_PASS_PHRASE)
JWT_PRIVATE_KEY_PATH=/runtime/keys/jwt-private.pem
JWT_PUBLIC_KEY_PATH=/runtime/keys/jwt-public.pem
JWT_PRIVATE_KEY_PASS_PHRASE=

ssl-certificate-extension

Similar to the RSA keys pair: Companienv will offer to generate a self-signed SSL certificate if it does not exist yet.

#+ssl-certificate(SSL_CERTIFICATE_PRIVATE_KEY_PATH SSL_CERTIFICATE_CERTIFICATE_PATH SSL_CERTIFICATE_DOMAIN_NAME)
SSL_CERTIFICATE_PRIVATE_KEY_PATH=/runtime/keys/server.key
SSL_CERTIFICATE_CERTIFICATE_PATH=/runtime/keys/server.crt
SSL_CERTIFICATE_DOMAIN_NAME=

Your own extensions

You can easily create and use your own extensions with Companienv. In order to do so, you'll have to start Companienv with your own PHP file and use the registerExtension method of the Application:

use Companienv\Application;
use Companienv\Extension;

$application = new Application($rootDirectory);
$application->registerExtension(new class() implements Extension {
    // Implements the interface...
});
$application->run();

More Repositories

1

ngInfiniteScroll

Infinite Scrolling for AngularJS
JavaScript
2,903
star
2

messenger-enqueue-transport

Uses Enqueue with Symfony's Messenger component.
PHP
191
star
3

backbone-upload-manager

An upload manager written using Backbone.js
JavaScript
105
star
4

docker-compose-zsh-plugin

ZSH plugin that display status of project containers
Shell
48
star
5

SRIORestUploadBundle

A symfony bundle to handle multiple upload ways on your REST API.
PHP
46
star
6

live-twig

Adding realtime to Twig templates directly
PHP
34
star
7

PHP-Voronoi-algorithm

Steven Fortune's algorithm in PHP
PHP
31
star
8

api-platform-messenger

Uses API Platform to exposes Commands & Queries dispatched to your Symfony Messenger bus
PHP
31
star
9

ChainOfResponsibility

A light library that simplify the implementation of a chain of responsibility
PHP
24
star
10

kubernetes-client

PHP client for the Kubernetes API
PHP
12
star
11

awesome-venturing

Awesome list of practices, tools and products especially useful in your startup adventure(s).
Ruby
11
star
12

angular-simple-model

Simple model layer for AngularJS applications
JavaScript
9
star
13

kubernetes-vamp-router

Vamp Router integration with Kubernetes
Go
9
star
14

ArgumentResolver

A PHP library to inject arguments to callables based on type hints and arguments' names
PHP
9
star
15

enqueue-bridge

Enqueue bridge for Symfony's Messenger component
8
star
16

fossil

🚧 Fossil is an horizontally scalable event store build on top of a key-value store.
Go
6
star
17

api-platform-messenger-example

API Platform + Symfony Messenger example
PHP
5
star
18

openwhisk-bundle

PHP
5
star
19

tsuru-php-example

PHP Silex application example that run on a Tsuru cluster
PHP
4
star
20

HipacheClient

PHP implementation of an Hipache client
PHP
4
star
21

messenger-workshop

Messenger workshop
PHP
3
star
22

flynn-php-example

Example of PHP application that runs on Flynn
PHP
3
star
23

ngInfiniteScroll-bower

Bower package for ngInfiniteScroll
JavaScript
3
star
24

dockerfiles

My Docker files & composes
Dockerfile
3
star
25

discoverd-client

PHP client of Flynn Discoverd
PHP
3
star
26

message

Symfony Message component split
PHP
2
star
27

backbone.realtime-models

A backbone models and collection realtime synchronization system based on WebSockets (in development)
JavaScript
2
star
28

logstream-client

PHP LogStream client
PHP
2
star
29

SocialShareBundle

Share content on multiple social network at the same time from your Symfony2 application.
PHP
2
star
30

backbone-file-browser

A backbone file browser. (still in development)
JavaScript
2
star
31

live-twig-example

PHP
2
star
32

tsuru-environment

Run Tsuru in a Docker container
ApacheConf
1
star
33

events

PHP
1
star
34

kubernetes-load-balancer-proxifier

Load Balancer proxifier for Kubernetes
Go
1
star
35

PgSQL-parse_url

Librairie parse_url pour PostgreSQL
1
star
36

api-platform-workshop

PHP
1
star
37

miniwiki

MiniWiki created for 24h info 2012
PHP
1
star
38

landing-page

JavaScript
1
star
39

angular-cordova-file

AngularJS module that helps file integration with Apache Cordova
JavaScript
1
star
40

jquery-plugin-vinlinedit

Inline edit with vi style for jQuery
JavaScript
1
star
41

PHP-Gettext-Edit

PHP Gettext files editor
PHP
1
star
42

backbone-defered-view-loader

A backbone view overlay that loads view only when needed
JavaScript
1
star