2017 © Pedro Peláez
 

library laravel-4-env-polyfill

Enables the env() function for providing default environment values and retrieving a variable from $_ENV.

image

zvps/laravel-4-env-polyfill

Enables the env() function for providing default environment values and retrieving a variable from $_ENV.

  • Tuesday, February 13, 2018
  • by Caffe1neAdd1ct
  • Repository
  • 2 Watchers
  • 0 Stars
  • 25 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Laravel 4 Env Polyfill

Laravel 5 has a nice function env() which can assign a default variable if empty/null/blank., (*1)

Laravel 4 applications are generally missing this functionality and if not running on >= PHP 7.0 can't use the ?? notation to keep (isset($_ENV(thing))) ? $_ENV(thing) : default short and sweet e.g $_ENV(thing) ?? default., (*2)

Installation

composer require zvps/laravel-4-env-polyfill

Setup

Make sure to start using the detectEnvironment functionality inside boostrap/start.php so .env.local.php for example are available and selected correctly., (*3)

$env = $app->detectEnvironment(array(
  'local' => array('your-machine-name'),
));

Next setup .env files and a .env.example.php so required defaults are documented., (*4)

.env.local.php



<?php
return array(
  'DATABASE_NAME' => 'my_database',
  'DATABASE_USER' => 'username',
  'DATABASE_PASSWORD' => 'totally_secure_password'
);

Next update all files in app/config/*.php with the env() polyfill:, (*5)

Without polyfill:, (*6)

'host'      => if(isset($_ENV['DATABASEHOST']) ? $_ENV['DATABASE_HOST'] : 'localhost',
'database'  => if(isset($_ENV['DATABASE_NAME']) ? $_ENV['DATABASE_NAME'] : 'default_db',
'username'  => if(isset($_ENV['DATABASE_USERNAME']) ? $_ENV['DATABASE_USERNAME'] : 'default_user',
'password'  => if(isset($_ENV['DATABASE_PASSWORD']) ? $_ENV['DATABASE_PASSWORD'] : 'default_pass',

With polyfill:, (*7)

'host'      => env('DATABASE_HOST', 'localhost')
'database'  => env('DATABASE_NAME', 'default_db'),
'username'  => env('DATABASE_USER', 'default_user'),
'password'  => env('DATABASE_PASSWORD', 'default_pass')

The Versions

13/02 2018

dev-master

9999999-dev

Enables the env() function for providing default environment values and retrieving a variable from $_ENV.

  Sources   Download

GPL 3.0 GPL-3.0-or-later

The Requires

 

13/02 2018

v1.0.1

1.0.1.0

Enables the env() function for providing default environment values and retrieving a variable from $_ENV.

  Sources   Download

GPL-3.0-or-later

The Requires

 

04/12 2017

v1.0.0

1.0.0.0

Enables the env() function for providing default environment values and retrieving a variable from $_ENV.

  Sources   Download

GPL 3.0

The Requires