2017 © Pedro Peláez
 

library environment

Environment Class for PHP

image

aequasi/environment

Environment Class for PHP

  • Tuesday, April 24, 2018
  • by aequasi
  • Repository
  • 4 Watchers
  • 11 Stars
  • 19,223 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 10 Versions
  • 6 % Grown

The README.md

Environment

This class is pretty simple. It adds environments to your PHP project., (*1)

To Install

Install with composer:, (*2)

composer require aequasi/environment

To Use

To get set up, drop the Environment class in your front controller. For example:, (*3)

<?php

require_once __DIR__.'/vendor/autoload.php';

$environment = new Aequasi\Environment\Environment;

// By default, the environment is set to 'dev'
echo $environment->getType();
// Above will echo 'dev';
var_dump($environment->isDebug());
// Above will dump true

You can set what the default environment is with Environment::$DEFAULT_ENVIRONMENT (string), and you can set what environments are in debug mode with Environment::$DEBUG_TYPES (string[])., (*4)

The allowed environments can also be changed by overriding the Environment::$DEFAULT_TYPE (string[]) parameter., (*5)

Setting Environments

Once you are ready to start using other environments (test, staging, and prod), there are a couple ways to do that., (*6)

1. php.ini

In your php.ini file, setting php.environment will set the environment for all processes using the php for that php.ini, (*7)

2. $_SERVER['PHP_ENVIRONMENT']

You can either use Apache or Nginx to set a server variable, or you can modify your $_SERVER header to set the environment, (*8)

  • For Apache, use [SetEnv]0
  • And Nginx is a little different. Check this StackOverflow post for an example.

3. CLI Arguments

If you are using the SymfonyEnvironment class, you can tie into the arguments (--env and --no-debug) by creating your environment a little differently:, (*9)

#!/usr/bin/env php
<?php
set_time_limit(0);

require_once __DIR__.'/bootstrap.php.cache';
require_once __DIR__.'/AppKernel.php';

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
use Aequasi\Environment\SymfonyEnvironment;

$input = new ArgvInput( );
$env = new SymfonyEnvironment( $input );

if( $env->isDebug() ) {
  Debug::enable();
}

$kernel = new AppKernel( $env->getType(), $env->isDebug() );
$application = new Application($kernel);
$application->run( $input );

The Versions

24/04 2018

dev-master

9999999-dev

Environment Class for PHP

  Sources   Download

Apache-2.0 Apache V2

The Development Requires

24/04 2018

3.0.1

3.0.1.0

Environment Class for PHP

  Sources   Download

Apache-2.0

The Development Requires

21/04 2018

3.0.0

3.0.0.0

Environment Class for PHP

  Sources   Download

Apache V2

The Development Requires

12/10 2017

dev-aequasi-patch-1

dev-aequasi-patch-1

Environment Class for PHP

  Sources   Download

Apache V2

The Development Requires

30/05 2015

2.0.0

2.0.0.0

Environment Class for PHP

  Sources   Download

Apache V2

The Development Requires

21/05 2014

0.4.0

0.4.0.0

Environment Class for PHP

  Sources   Download

Apache V2

The Development Requires

21/05 2014

1.0.0

1.0.0.0

Environment Class for PHP

  Sources   Download

Apache V2

The Development Requires

16/04 2014

0.3.0

0.3.0.0

Environment Class for PHP

  Sources   Download

Apache V2

The Development Requires

12/04 2014

0.2.0

0.2.0.0

Environment Class for PHP

  Sources   Download

Apache V2

The Development Requires

08/04 2014

0.1.0

0.1.0.0

Environment Class for PHP

  Sources   Download

Apache V2

The Development Requires