stefanocbt/phpdotenv-sync

A package that makes sure that your .env file is in sync with your .env.example

1.3.0 2023-10-14 16:37 UTC

This package is auto-updated.

Last update: 2024-03-14 17:42:43 UTC


README

Tests Actions Status Tests Actions Status

phpdotenv-sync

A package that makes sure that your .env file is in sync with your .env.example

Usage

add the library to your project with composer:

composer require stefanocbt/phpdotenv-sync

using the library: phpdotenv-sync has the following operations:

  • check: to check diffs between two dotenv files (Example: .env.example and .env)
  • sync: to sync two dotenv files (add missing dotenv parameters to destination dotenv file)

Executing:

./vendor/bin/phpdotenvsync [options]

Options:
    --opt[=OPT]               Specify the right operation (Required) ("check" or "sync")
    --src[=SOURCE]            Specify the source dotenv file (Optional) (default: current-folder-path/.env.example)
    --dest[=DESTINATION]      Specify the destination dotenv file (Optional) (default: current-folder-path/.env)
    --no-interaction          Avoid all kind of user interactions. Default action is to syncing by copying all parameters with their default values (Optional)

if you are in a standard environment and you have .env.example and .env inside the root project folder you can just execute the following command to sync .env.example and .env files:

./vendor/bin/phpdotenvsync --opt=sync

for --src and --dest options you can use absolute and/or relative paths. If, for example, you have the files inside the current pwd folder but dotenv files have different filenames you can launch phpdotenvsync this way:

./vendor/bin/phpdotenvsync --opt=sync --src=./[SRC_FILENAME] --dest=./[DEST_FILENAME]

or if you want to specify an absolute path:

./vendor/bin/phpdotenvsync --opt=sync --src=/absolute/path/to/[SRC_FILENAME] --dest=/absolute/path/to/[DEST_FILENAME]

Development

testing CHECK command into development environment (execute from project root dir):
php bin/phpdotenvsync --opt=check --src="./bin/dev_testing/.env.example" --dest="./bin/dev_testing/.env"

testing SYNC command into development environment (execute from project root dir):

php bin/phpdotenvsync --opt=sync --src="./bin/dev_testing/.env.example" --dest="./bin/dev_testing/.env"

Codequality tests

phpcs
automatic fix with phpcs:
php vendor/bin/phpcbf --standard=PSR12 -n -p src/