Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Support;
4
 
5
use ArrayIterator;
6
use Illuminate\Contracts\Support\ValidatedData;
7
use stdClass;
8
use Traversable;
9
 
10
class ValidatedInput implements ValidatedData
11
{
12
    /**
13
     * The underlying input.
14
     *
15
     * @var array
16
     */
17
    protected $input;
18
 
19
    /**
20
     * Create a new validated input container.
21
     *
22
     * @param  array  $input
23
     * @return void
24
     */
25
    public function __construct(array $input)
26
    {
27
        $this->input = $input;
28
    }
29
 
30
    /**
31
     * Determine if the validated input has one or more keys.
32
     *
33
     * @param  mixed  $keys
34
     * @return bool
35
     */
36
    public function has($keys)
37
    {
38
        $keys = is_array($keys) ? $keys : func_get_args();
39
 
40
        foreach ($keys as $key) {
41
            if (! Arr::has($this->input, $key)) {
42
                return false;
43
            }
44
        }
45
 
46
        return true;
47
    }
48
 
49
    /**
50
     * Determine if the validated input is missing one or more keys.
51
     *
52
     * @param  mixed  $keys
53
     * @return bool
54
     */
55
    public function missing($keys)
56
    {
57
        return ! $this->has($keys);
58
    }
59
 
60
    /**
61
     * Get a subset containing the provided keys with values from the input data.
62
     *
63
     * @param  mixed  $keys
64
     * @return array
65
     */
66
    public function only($keys)
67
    {
68
        $results = [];
69
 
70
        $input = $this->input;
71
 
72
        $placeholder = new stdClass;
73
 
74
        foreach (is_array($keys) ? $keys : func_get_args() as $key) {
75
            $value = data_get($input, $key, $placeholder);
76
 
77
            if ($value !== $placeholder) {
78
                Arr::set($results, $key, $value);
79
            }
80
        }
81
 
82
        return $results;
83
    }
84
 
85
    /**
86
     * Get all of the input except for a specified array of items.
87
     *
88
     * @param  mixed  $keys
89
     * @return array
90
     */
91
    public function except($keys)
92
    {
93
        $keys = is_array($keys) ? $keys : func_get_args();
94
 
95
        $results = $this->input;
96
 
97
        Arr::forget($results, $keys);
98
 
99
        return $results;
100
    }
101
 
102
    /**
103
     * Merge the validated input with the given array of additional data.
104
     *
105
     * @param  array  $items
106
     * @return static
107
     */
108
    public function merge(array $items)
109
    {
110
        return new static(array_merge($this->input, $items));
111
    }
112
 
113
    /**
114
     * Get the input as a collection.
115
     *
116
     * @return \Illuminate\Support\Collection
117
     */
118
    public function collect()
119
    {
120
        return new Collection($this->input);
121
    }
122
 
123
    /**
124
     * Get the raw, underlying input array.
125
     *
126
     * @return array
127
     */
128
    public function all()
129
    {
130
        return $this->input;
131
    }
132
 
133
    /**
134
     * Get the instance as an array.
135
     *
136
     * @return array
137
     */
138
    public function toArray()
139
    {
140
        return $this->all();
141
    }
142
 
143
    /**
144
     * Dynamically access input data.
145
     *
146
     * @param  string  $name
147
     * @return mixed
148
     */
149
    public function __get($name)
150
    {
151
        return $this->input[$name];
152
    }
153
 
154
    /**
155
     * Dynamically set input data.
156
     *
157
     * @param  string  $name
158
     * @param  mixed  $value
159
     * @return mixed
160
     */
161
    public function __set($name, $value)
162
    {
163
        $this->input[$name] = $value;
164
    }
165
 
166
    /**
167
     * Determine if an input key is set.
168
     *
169
     * @return bool
170
     */
171
    public function __isset($name)
172
    {
173
        return isset($this->input[$name]);
174
    }
175
 
176
    /**
177
     * Remove an input key.
178
     *
179
     * @param  string  $name
180
     * @return void
181
     */
182
    public function __unset($name)
183
    {
184
        unset($this->input[$name]);
185
    }
186
 
187
    /**
188
     * Determine if an item exists at an offset.
189
     *
190
     * @param  mixed  $key
191
     * @return bool
192
     */
193
    public function offsetExists($key): bool
194
    {
195
        return isset($this->input[$key]);
196
    }
197
 
198
    /**
199
     * Get an item at a given offset.
200
     *
201
     * @param  mixed  $key
202
     * @return mixed
203
     */
204
    public function offsetGet($key): mixed
205
    {
206
        return $this->input[$key];
207
    }
208
 
209
    /**
210
     * Set the item at a given offset.
211
     *
212
     * @param  mixed  $key
213
     * @param  mixed  $value
214
     * @return void
215
     */
216
    public function offsetSet($key, $value): void
217
    {
218
        if (is_null($key)) {
219
            $this->input[] = $value;
220
        } else {
221
            $this->input[$key] = $value;
222
        }
223
    }
224
 
225
    /**
226
     * Unset the item at a given offset.
227
     *
228
     * @param  string  $key
229
     * @return void
230
     */
231
    public function offsetUnset($key): void
232
    {
233
        unset($this->input[$key]);
234
    }
235
 
236
    /**
237
     * Get an iterator for the input.
238
     *
239
     * @return \ArrayIterator
240
     */
241
    public function getIterator(): Traversable
242
    {
243
        return new ArrayIterator($this->input);
244
    }
245
}