Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| HttpFilterableTrait | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
7 | |
100.00% |
1 / 1 |
| filter | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
7 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Http; |
| 16 | |
| 17 | use Pop\Filter\FilterableTrait; |
| 18 | |
| 19 | /** |
| 20 | * HTTP filterable trait |
| 21 | * |
| 22 | * @category Pop |
| 23 | * @package Pop\Http |
| 24 | * @author Nick Sagona, III <nick@popphp.org> |
| 25 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 26 | * @license https://www.popphp.org/license New BSD License |
| 27 | * @version 6.0.0 |
| 28 | */ |
| 29 | trait HttpFilterableTrait |
| 30 | { |
| 31 | |
| 32 | use FilterableTrait; |
| 33 | |
| 34 | /** |
| 35 | * Cached parse of ini's disable_functions list - a static php.ini setting that cannot |
| 36 | * change during a request, so re-parsing it on every filter() call is pure waste |
| 37 | * @var ?array |
| 38 | */ |
| 39 | protected static ?array $disabledFunctions = null; |
| 40 | |
| 41 | /** |
| 42 | * Filter values |
| 43 | * |
| 44 | * @param mixed $values |
| 45 | * @return mixed |
| 46 | */ |
| 47 | public function filter(mixed $values): mixed |
| 48 | { |
| 49 | if (self::$disabledFunctions === null) { |
| 50 | self::$disabledFunctions = array_filter(array_map('trim', explode(',', (string)ini_get('disable_functions')))); |
| 51 | } |
| 52 | $disabledFunctions = self::$disabledFunctions; |
| 53 | |
| 54 | foreach ($this->filters as $filter) { |
| 55 | if (is_array($values)) { |
| 56 | foreach ($values as $key => $value) { |
| 57 | if (!in_array($value, $disabledFunctions)) { |
| 58 | $values[$key] = $filter->filter($value, $key); |
| 59 | } |
| 60 | } |
| 61 | } else { |
| 62 | if (!in_array($values, $disabledFunctions)) { |
| 63 | $values = $filter->filter($values); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | return $values; |
| 69 | } |
| 70 | |
| 71 | } |