Environments

Environments system on production, development or else and how we can impact system.

Environments are set of system commands that will run on very first lines of entry-script and impact the system behaviors on error handling or define some const or environment variables.

Available Environment Attributes

Attribute

Value

Equivalent PHP Command

display_errors

(int) 0, 1

ini_set('display_errors', $value);

error_reporting

(string) 'E_ALL' , 'E_..'

error_reporting(E_ALL);

display_startup_errors

(int) 0, 1

ini_set('display_startup_errors', $value);

time_zone

(string) UTC

date_default_timezone_set('UCT')

html_errors

(int) 0, 1

ini_set('html_errors', $value);

defined_const

['const_name' => 'value']

! could be used to override default system constants

define((string) $const, $value);

environments

['env_name' => 'value']

$_ENV[$name] = $value; //simplified

How environment system works

At very beginning of system setup Poirot looks for .env.php and then.env.local.php on root directory of project PT_DIR_ROOT and merge the attributes of these files together and apply the environment commands that mentioned above.

We also could add extra .env file by setting PT_ENV environment variable on OS level to Poirot. examine that PT_ENV has a value of europe_server merging attributes would be: .env.php + .env.local.php + .env.europe_server.php + .env.europe_server.local.php

what is inside .env files?

<?php
/** @see \Poirot\Std\Environment\EnvBase */
return [
     'time_zone'  => 'UCT',
     'display_errors'  => 0,
     'error_reporting' => 0, // 'E_ALL'  E_NOTICE  E_WARNING
     'display_startup_errors' => 0,
     'html_errors' => 0,
     'defined_const' => [
        #'PT_SERVER_URL' => 'https://server-name/',
        #'PT_BASEURL'    => 'basepath/',
        #'PT_SITE_NAME'  => 'custom_config',

        #'PT_DIR_CONFIG' => constant('PT_DIR_ROOT').'/config/',
        #'PT_DIR_DATA'   => '/path/to/data/',
        #'PT_DIR_TMP'    => '/tmp/',
        #'PT_DIR_CORE'   => constant('PT_DIR_ROOT').'/core/',
     ],
     'environments' => [
        #'PT_SERVER_URL' => 'https://server-name/',
        #'PT_BASEURL'    => 'basepath/',
        #'PT_SITE_NAME'  => 'custom_config',

        #'YOUR_ENV'      => 'value',
     ],
];

Use Pre-Defined Environment Context

Some predefined environment files are exists that environment variables will merge and apply to that set of classes. Poirot instantiate that based on PT_ENV_PROFILE environment variable and use default if it's not set.

Available environment classes are:

  • Production: production, prod

  • Development: development, devel, debug

  • Current PHP Setting: php, default

Determining The Current Environment

The current application environment is built upon your predefined .env file and environment profile You may access these environment settings via the environment static method:

FactoryEnvironment::hasCurrentEnvironment() : ?EnvBase

Last updated

Was this helpful?