axy\envnorm
Initial normalization of the environment, (*1)
, (*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,
],
];