| 1 | <?php |
||
| 5 | class FileBag implements \Iterator, \ArrayAccess |
||
| 6 | { |
||
| 7 | |||
| 8 | private $entries = []; |
||
| 9 | |||
| 10 | private $current = 0; |
||
| 11 | |||
| 12 | |||
| 13 | // implementing Iterator interface |
||
| 14 | 1 | public function current() |
|
| 18 | |||
| 19 | |||
| 20 | 1 | public function key() |
|
| 24 | |||
| 25 | |||
| 26 | 1 | public function next() |
|
| 30 | |||
| 31 | |||
| 32 | 2 | public function rewind() |
|
| 36 | |||
| 37 | |||
| 38 | 2 | public function valid() |
|
| 42 | |||
| 43 | |||
| 44 | // implementing ArrayAccess interface |
||
| 45 | 3 | public function offsetExists($offset) |
|
| 49 | |||
| 50 | |||
| 51 | 3 | public function offsetSet($offset, $value) |
|
| 52 | { |
||
| 53 | // attempts to add invalid file in a filebag er ignored |
||
| 54 | 3 | if (is_a($value, 'Fracture\Http\UploadedFile') === true && |
|
| 55 | 3 | $value->isValid() === false) { |
|
| 56 | 1 | return; |
|
| 57 | } |
||
| 58 | |||
| 59 | 2 | if (is_null($offset) === true) { |
|
| 60 | 1 | $this->entries[] = $value; |
|
| 61 | } else { |
||
| 62 | 1 | $this->entries[$offset] = $value; |
|
| 63 | } |
||
| 64 | 2 | } |
|
| 65 | |||
| 66 | |||
| 67 | 2 | public function offsetGet($offset) |
|
| 75 | |||
| 76 | |||
| 77 | 2 | public function offsetUnset($offset) |
|
| 81 | } |
||
| 82 |