PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / vendor / vendor-prefixed / symfony / http-foundation / InputBag.php

InputBag.php in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at vendor/vendor-prefixed/symfony/http-foundation/InputBag.php

114 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Give\Vendors\Symfony\Component\HttpFoundation;
13
14 use Give\Vendors\Symfony\Component\HttpFoundation\Exception\BadRequestException;
15
16 /**
17 * InputBag is a container for user input values such as $_GET, $_POST, $_REQUEST, and $_COOKIE.
18 *
19 * @author Saif Eddin Gmati <[email protected]>
20 */
21 final class InputBag extends ParameterBag
22 {
23 /**
24 * Returns a scalar input value by name.
25 *
26 * @param string|int|float|bool|null $default The default value if the input key does not exist
27 *
28 * @return string|int|float|bool|null
29 */
30 public function get(string $key, $default = null)
31 {
32 if (null !== $default && !\is_scalar($default) && !(\is_object($default) && method_exists($default, '__toString'))) {
33 trigger_deprecation('symfony/http-foundation', '5.1', 'Passing a non-scalar value as 2nd argument to "%s()" is deprecated, pass a scalar or null instead.', __METHOD__);
34 }
35
36 $value = parent::get($key, $this);
37
38 if (null !== $value && $this !== $value && !\is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
39 trigger_deprecation('symfony/http-foundation', '5.1', 'Retrieving a non-scalar value from "%s()" is deprecated, and will throw a "%s" exception in Symfony 6.0, use "%s::all($key)" instead.', __METHOD__, BadRequestException::class, __CLASS__);
40 }
41
42 return $this === $value ? $default : $value;
43 }
44
45 /**
46 * {@inheritdoc}
47 */
48 public function all(?string $key = null): array
49 {
50 return parent::all($key);
51 }
52
53 /**
54 * Replaces the current input values by a new set.
55 */
56 public function replace(array $inputs = [])
57 {
58 $this->parameters = [];
59 $this->add($inputs);
60 }
61
62 /**
63 * Adds input values.
64 */
65 public function add(array $inputs = [])
66 {
67 foreach ($inputs as $input => $value) {
68 $this->set($input, $value);
69 }
70 }
71
72 /**
73 * Sets an input by name.
74 *
75 * @param string|int|float|bool|array|null $value
76 */
77 public function set(string $key, $value)
78 {
79 if (null !== $value && !\is_scalar($value) && !\is_array($value) && !method_exists($value, '__toString')) {
80 trigger_deprecation('symfony/http-foundation', '5.1', 'Passing "%s" as a 2nd Argument to "%s()" is deprecated, pass a scalar, array, or null instead.', get_debug_type($value), __METHOD__);
81 }
82
83 $this->parameters[$key] = $value;
84 }
85
86 /**
87 * {@inheritdoc}
88 */
89 public function filter(string $key, $default = null, int $filter = \FILTER_DEFAULT, $options = [])
90 {
91 $value = $this->has($key) ? $this->all()[$key] : $default;
92
93 // Always turn $options into an array - this allows filter_var option shortcuts.
94 if (!\is_array($options) && $options) {
95 $options = ['flags' => $options];
96 }
97
98 if (\is_array($value) && !(($options['flags'] ?? 0) & (\FILTER_REQUIRE_ARRAY | \FILTER_FORCE_ARRAY))) {
99 trigger_deprecation('symfony/http-foundation', '5.1', 'Filtering an array value with "%s()" without passing the FILTER_REQUIRE_ARRAY or FILTER_FORCE_ARRAY flag is deprecated', __METHOD__);
100
101 if (!isset($options['flags'])) {
102 $options['flags'] = \FILTER_REQUIRE_ARRAY;
103 }
104 }
105
106 if ((\FILTER_CALLBACK & $filter) && !(($options['options'] ?? null) instanceof \Closure)) {
107 trigger_deprecation('symfony/http-foundation', '5.2', 'Not passing a Closure together with FILTER_CALLBACK to "%s()" is deprecated. Wrap your filter in a closure instead.', __METHOD__);
108 // throw new \InvalidArgumentException(sprintf('A Closure must be passed to "%s()" when FILTER_CALLBACK is used, "%s" given.', __METHOD__, get_debug_type($options['options'] ?? null)));
109 }
110
111 return filter_var($value, $filter, $options);
112 }
113 }
114