# Environments

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.&#x20;

### 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**           | <p>\['const\_name' => 'value']</p><p></p><p>! <em>could be used to override default system</em> <a href="constant-and-environment-variables"><em>constants</em></a></p> | `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
<?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.&#x20;

Available environment classes are:&#x20;

* **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:

```php
FactoryEnvironment::hasCurrentEnvironment() : ?EnvBase
```
