1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Lenevor Framework |
5
|
|
|
* |
6
|
|
|
* LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the new BSD license that is bundled |
9
|
|
|
* with this package in the file license.md. |
10
|
|
|
* It is also available through the world-wide-web at this URL: |
11
|
|
|
* https://lenevor.com/license |
12
|
|
|
* If you did not receive a copy of the license and are unable to |
13
|
|
|
* obtain it through the world-wide-web, please send an email |
14
|
|
|
* to [email protected] so we can send you a copy immediately. |
15
|
|
|
* |
16
|
|
|
* @package Lenevor |
17
|
|
|
* @subpackage Base |
18
|
|
|
* @link https://lenevor.com |
19
|
|
|
* @copyright Copyright (c) 2019 - 2021 Alexander Campo <[email protected]> |
20
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /license.md |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace Syscodes\Http\Contributors; |
24
|
|
|
|
25
|
|
|
use Syscodes\Core\Http\Exceptions\BadRequestHttpException; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Inputs is a container for user input values such as |
29
|
|
|
* $_GET, $_POST, $_REQUEST, and $_COOKIE. |
30
|
|
|
* |
31
|
|
|
* @author Alexander Campo <[email protected]> |
32
|
|
|
*/ |
33
|
|
|
final class Inputs extends Parameters |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function all(string $key = null) |
39
|
|
|
{ |
40
|
|
|
return parent::all($key); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
public function replace(array $inputs = []) |
47
|
|
|
{ |
48
|
|
|
$this->parameters = []; |
49
|
|
|
$this->add($inputs); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Adds input values. |
54
|
|
|
* |
55
|
|
|
* @param array $inputs |
56
|
|
|
* |
57
|
|
|
* @return mixed |
58
|
|
|
*/ |
59
|
|
|
public function add(array $inputs = []) |
60
|
|
|
{ |
61
|
|
|
foreach ($inputs as $key => $file) { |
62
|
|
|
$this->set($key, $file); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Gets a string input value by name. |
68
|
|
|
* |
69
|
|
|
* @param string $key |
70
|
|
|
* @param string|null $default |
71
|
|
|
* |
72
|
|
|
* @return string|null |
73
|
|
|
*/ |
74
|
|
|
public function get($key, $default = null) |
75
|
|
|
{ |
76
|
|
|
if (null !== $default && ! is_scalar($default) && ! (is_object($default)) && ! method_exist($default, '__toString')) { |
|
|
|
|
77
|
|
|
throw new BadRequestHttpException(sprintf('Passing a non-string value as 2nd argument to "%s()" is deprecated, pass a string or null instead', __METHOD__)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$value = parent::get($key, $this); |
|
|
|
|
81
|
|
|
|
82
|
|
|
if (null !== $value && $this !== $value && ! is_scalar($value) && ! (is_object($value)) && ! method_exist($value, '__toString')) { |
83
|
|
|
throw new BadRequestHttpException(sprintf('Retrieving a non-string value from "%s()" is deprecated, and will throw a exception in Syscodes, use "%s::all($key)" instead', __METHOD__, __CLASS__)); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $value === $this ? $default : $value; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Sets an input by name. |
91
|
|
|
* |
92
|
|
|
* @param string $key |
93
|
|
|
* @param string|array|null $value |
94
|
|
|
* |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
|
|
public function set($key, $value) |
98
|
|
|
{ |
99
|
|
|
if (null !== $value && ! is_scalar($value) && ! is_array($value) && ! method_exist($value, '__toString')) { |
|
|
|
|
100
|
|
|
throw new BadRequestHttpException(sprintf('Passing "%s" as a 2nd Argument to "%s()" is deprecated, pass a string, array, or null instead', get_debug_type($value), __METHOD__)); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$this->parameters[$key] = $value; |
104
|
|
|
} |
105
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.