2017 © Pedro Peláez
 

library envnorm

Initial normalization of the environment

image

axy/envnorm

Initial normalization of the environment

  • Monday, January 8, 2018
  • by axy
  • Repository
  • 1 Watchers
  • 1 Stars
  • 34 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

axy\envnorm

Initial normalization of the environment, (*1)

Latest Stable Version Minimum PHP Version Build Status Coverage Status License, (*2)

  • The library does not require any dependencies (except composer packages).
  • Tested on PHP 5.4+, PHP 7, HHVM (on Linux), PHP 5.5 (on Windows).
  • Install: composer require axy/envnorm.
  • License: MIT.

Documentation

How to use

use axy\envnorm\Normalizer;

$normalizer = new Normalizer();
$normalizer->normalize();

Or (do not litter in the global scope):, (*3)

Normalizer::createInstance()->normalize();

Or (custom configuration):, (*4)

$config = [
    'datetime' => null,
    'encoding' => 'Windows-1251',
];

Normalizer::createInstance($config)->normalize();

The library is intended for rearrangement of the PHP-environment before the application start., (*5)

The configuration

The default configuration is this, (*6)

[
    'errors' => [
        'level' => E_ALL,
        'display' => null,
        'handler' => true,
        'ErrorException' => 'ErrorException',
        'exceptionHandler' => null,
        'allowSuppression' => true,
    ],
    'datetime' => [
        'timezone' => 'UTC',
        'keepTimezone' => true,
    ],
    'encoding' => 'UTF-8',
    'options' => [],
];

You can override the parameters that you need. A custom configuration merges with the default by array_replace_recursive()., (*7)

NULL in a value means that action should not be performed., (*8)

$custom = [
    'errors' => [
        'handler' => null, // do not use a custom error handler
    ],
    'datetime' => null, // do not perform any action on the date and time settings
];

Errors

Default means the following behavior:, (*9)

  • All errors (including warnings, notices and etc) lead to the stop (by an exception).
  • Show or hide the error depends on the platform (development or production).

The following describes the fields of the configuration section errors., (*10)

level (int)

The bitmask of handled error types. By default is E_ALL., (*11)

display (boolean)

The value for the display_errors option. By default is NULL: a script shouldn't set display_errors, it must be set in php.ini (depends on the platform)., (*12)

handler (callback)

The callback for the error handler (see set_error_handler()). IF NULL then do not set a custom handler. IF TRUE then set the handler from the library., (*13)

The library handler throws an exception (ErrorException or its child) for each error., (*14)

$a = [];
$a['a'] = $a['b']; // ErrorException
ErrorException (string)

The library handler uses this option. This is the class name of the exception. It is ErrorException by default and can be a child of ErrorException., (*15)

allowSuppression (bool)

This option allows suppression of error by @-operator., (*16)

$a = [];
$a['a'] = @$a['b'];

The default (allowSuppression=TRUE) it do not lead to the exception. If set this option to FALSE the exception will be thrown regardless of @., (*17)

exceptionHandler (callback)

The top level handler for exceptions. See set_exception_handler()., (*18)

The default is NULL: the handler will not set., (*19)

Timezone

datetime.timezone (string)

The default timezone. UTC by default., (*20)

datetime.keepTimezone (bool)

The default (keepTimezone=TRUE) remains the timezone from php.ini. datetime.timezone only used if the timezone is not defined in php.ini., (*21)

Encoding

The encoding option used in mbstring (if it is installed)., (*22)

Options

All other PHP-options that should be changed., (*23)

$config = [
    'options' => [
        'sendmail_from' => 'me@server.loc',
        'mysqli.default_port' => 3307,
    ],
];

The Versions

08/01 2018

dev-master

9999999-dev https://github.com/axypro/envnorm

Initial normalization of the environment

  Sources   Download

MIT

The Requires

 

timezone error_handler error_reporting

24/06 2016

0.1.5

0.1.5.0 https://github.com/axypro/envnorm

Initial normalization of the environment

  Sources   Download

MIT

The Requires

 

timezone error_handler error_reporting

10/11 2015

0.1.4

0.1.4.0 https://github.com/axypro/envnorm

Initial normalization of the environment

  Sources   Download

MIT

The Requires

 

timezone error_handler error_reporting

05/11 2015

0.1.3

0.1.3.0 https://github.com/axypro/envnorm

Initial normalization of the environment

  Sources   Download

MIT

The Requires

 

timezone error_handler error_reporting

10/02 2015

0.1.2

0.1.2.0 https://github.com/axypro/envnorm

Initial normalization of the environment

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

timezone error_handler error_reporting

12/01 2015

0.1.1

0.1.1.0 https://github.com/axypro/envnorm

Initial normalization of the environment

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

timezone error_handler error_reporting

11/01 2015

0.1.0

0.1.0.0 https://github.com/axypro/envnorm

Initial normalization of the environment

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

timezone error_handler error_reporting