定制 axy/envnorm 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

axy/envnorm

最新稳定版本:0.1.5

Composer 安装命令:

composer require axy/envnorm

包简介

Initial normalization of the environment

README 文档

README

Initial normalization of the environment

Latest Stable Version Minimum PHP Version Build Status Coverage Status License

  • 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):

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

Or (custom configuration):

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

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

The library is intended for rearrangement of the PHP-environment before the application start.

The configuration

The default configuration is this

[
    '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().

NULL in a value means that action should not be performed.

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

  • 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.

level (int)

The bitmask of handled error types. By default is E_ALL.

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).

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.

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

$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.

allowSuppression (bool)

This option allows suppression of error by @-operator.

$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 @.

exceptionHandler (callback)

The top level handler for exceptions. See set_exception_handler().

The default is NULL: the handler will not set.

Timezone

datetime.timezone (string)

The default timezone. UTC by default.

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.

Encoding

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

Options

All other PHP-options that should be changed.

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

统计信息

  • 总下载量: 70
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-11