coercive/全局

强制全局工具

1.1.2 2020-07-31 14:07 UTC

This package is auto-updated.

Last update: 2024-08-29 04:25:25 UTC


README

GLOBALS 允许您通过自动或特定地过滤内容,轻松管理 PHP 中的全局变量,如果为数组,还支持批量处理。

获取

composer require coercive/globals

用法

use Coercive\Utility\Globals;

# LOAD
$oGlobals = new Globals;

# DEFAULT
$oGlobals->filter(true);
# You can turn off by setting 'false'

# SET VAR
$oGlobals->GET('name', 'value');

# GET VAR
$var = $oGlobals->GET('name');

# FOR EXAMPLE :
$_GET['array'] = ['email@email.email', 'not an email'];
$_GET['notInt'] = '01234';
$_GET['int'] = '14244';
$_GET['_int'] = '-14244';
$_GET['float'] = '142.24';
$_GET['_float'] = '+142.24';
$_GET['bool'] = 'false';
$_GET['_bool'] = true;
$_GET['quote'] = '"';

# FILTER ALL
$var = $oGlobals->GET()->filterAll();

/**
      ["array"]
            [0]=> string(17) "email@email.email"
            [1]=> string(12) "not an email"
      ["notInt"]=> string(5) "01234"
      ["int"]=> int(14244)
      ["_int"]=> int(-14244)
      ["float"]=> float(142.24)
      ["_float"]=> float(142.24)
      ["bool"]=> bool(false)
      ["quote"]=> string(10) """
*/


# FILTER ONE (including array of elements)
$var = $oGlobals->email()->GET('array');

/**
    ["array"]
        [0]=> string(17) "email@email.email"
        [1]=> bool(false)
*/

过滤器

->octal()->...
->int()->...
->float()->...
->bool()->...
->ip()->...
->ipv4()->...
->ipv6()->...
->callback()->...
->rArray()->...
->email()->...
->url()->...
->mac()->...
->string()->...
->stringFull()->...
->noFilter()->...

新选项

# You can now filter a variable (or a part of global for re-inject)
$Result = $oGlobals->autoFilterManualVar($YourVar);