123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace Symfony\Component\HttpFoundation;
- use Symfony\Component\HttpFoundation\Exception\BadRequestException;
- final class InputBag extends ParameterBag
- {
-
- public function get(string $key, $default = null)
- {
- if (null !== $default && !\is_scalar($default) && !(\is_object($default) && method_exists($default, '__toString'))) {
- 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__);
- }
- $value = parent::get($key, $this);
- if (null !== $value && $this !== $value && !\is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
- 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__);
- }
- return $this === $value ? $default : $value;
- }
-
- public function all(?string $key = null): array
- {
- return parent::all($key);
- }
-
- public function replace(array $inputs = [])
- {
- $this->parameters = [];
- $this->add($inputs);
- }
-
- public function add(array $inputs = [])
- {
- foreach ($inputs as $input => $value) {
- $this->set($input, $value);
- }
- }
-
- public function set(string $key, $value)
- {
- if (null !== $value && !\is_scalar($value) && !\is_array($value) && !method_exists($value, '__toString')) {
- 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__);
- }
- $this->parameters[$key] = $value;
- }
-
- public function filter(string $key, $default = null, int $filter = \FILTER_DEFAULT, $options = [])
- {
- $value = $this->has($key) ? $this->all()[$key] : $default;
-
- if (!\is_array($options) && $options) {
- $options = ['flags' => $options];
- }
- if (\is_array($value) && !(($options['flags'] ?? 0) & (\FILTER_REQUIRE_ARRAY | \FILTER_FORCE_ARRAY))) {
- 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__);
- if (!isset($options['flags'])) {
- $options['flags'] = \FILTER_REQUIRE_ARRAY;
- }
- }
- if ((\FILTER_CALLBACK & $filter) && !(($options['options'] ?? null) instanceof \Closure)) {
- 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__);
-
- }
- return filter_var($value, $filter, $options);
- }
- }
|