| 1 |
<?php |
| 2 |
|
| 3 |
namespace Illuminate\Support; |
| 4 |
|
| 5 |
use Countable; |
| 6 |
use Illuminate\Contracts\Support\MessageBag as MessageBagContract; |
| 7 |
use Stringable; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class ViewErrorBag implements Countable, Stringable |
| 13 |
{ |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
protected $bags = []; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public function hasBag($key = 'default') |
| 28 |
{ |
| 29 |
return isset($this->bags[$key]); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public function getBag($key) |
| 39 |
{ |
| 40 |
return Arr::get($this->bags, $key) ?: new MessageBag; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public function getBags() |
| 49 |
{ |
| 50 |
return $this->bags; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public function put($key, MessageBagContract $bag) |
| 61 |
{ |
| 62 |
$this->bags[$key] = $bag; |
| 63 |
|
| 64 |
return $this; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public function any() |
| 73 |
{ |
| 74 |
return $this->count() > 0; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public function count(): int |
| 83 |
{ |
| 84 |
return $this->getBag('default')->count(); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public function __call($method, $parameters) |
| 95 |
{ |
| 96 |
return $this->getBag('default')->$method(...$parameters); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public function __get($key) |
| 106 |
{ |
| 107 |
return $this->getBag($key); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
public function __set($key, $value) |
| 118 |
{ |
| 119 |
$this->put($key, $value); |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
public function __toString() |
| 128 |
{ |
| 129 |
return (string) $this->getBag('default'); |
| 130 |
} |
| 131 |
} |