Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
84.62% covered (success)
84.62%
11 / 13
50.00% covered (warning)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
AbstractRequest
84.62% covered (success)
84.62%
11 / 13
50.00% covered (warning)
50.00%
1 / 2
9.29
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 filter
77.78% covered (success)
77.78%
7 / 9
0.00% covered (danger)
0.00%
0 / 1
6.40
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Http;
15
16use Pop\Filter\FilterableTrait;
17
18/**
19 * Abstract HTTP request class
20 *
21 * @category   Pop
22 * @package    Pop\Http
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    4.1.0
27 */
28abstract class AbstractRequest extends AbstractHttp
29{
30
31    use FilterableTrait;
32
33    /**
34     * Constructor
35     *
36     * Instantiate the request object
37     *
38     * @param  mixed  $filters
39     */
40    public function __construct($filters = null)
41    {
42        if (null !== $filters) {
43            if (is_array($filters)) {
44                $this->addFilters($filters);
45            } else {
46                $this->addFilter($filters);
47            }
48        }
49    }
50
51    /**
52     * Filter values
53     *
54     * @param  mixed $values
55     * @return mixed
56     */
57    public function filter($values)
58    {
59        $disabledFunctions = array_filter(array_map('trim', explode(',', ini_get('disable_functions'))));
60
61        foreach ($this->filters as $filter) {
62            if (is_array($values)) {
63                foreach ($values as $key => $value) {
64                    if (!in_array($value, $disabledFunctions)) {
65                        $values[$key] = $filter->filter($value, $key);
66                    }
67                }
68            } else {
69                if (!in_array($values, $disabledFunctions)) {
70                    $values = $filter->filter($values);
71                }
72            }
73        }
74
75        return $values;
76    }
77
78}