Debian Codegraph @

lib/3rdParty/composer/illuminate/support/ViewErrorBag.php

raw symbols SCIP
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 * @mixin \Illuminate\Contracts\Support\MessageBag
11 */
12 class ViewErrorBag implements Countable, Stringable
13 {
14 /**
15 * The array of the view error bags.
16 *
17 * @var array<string, \Illuminate\Contracts\Support\MessageBag>
18 */
19 protected $bags = [];
20
21 /**
22 * Checks if a named MessageBag exists in the bags.
23 *
24 * @param string $key
25 * @return bool
26 */
27 public function hasBag($key = 'default')
28 {
29 return isset($this->bags[$key]);
30 }
31
32 /**
33 * Get a MessageBag instance from the bags.
34 *
35 * @param string $key
36 * @return \Illuminate\Contracts\Support\MessageBag
37 */
38 public function getBag($key)
39 {
40 return Arr::get($this->bags, $key) ?: new MessageBag;
41 }
42
43 /**
44 * Get all the bags.
45 *
46 * @return array<string, \Illuminate\Contracts\Support\MessageBag>
47 */
48 public function getBags()
49 {
50 return $this->bags;
51 }
52
53 /**
54 * Add a new MessageBag instance to the bags.
55 *
56 * @param string $key
57 * @param \Illuminate\Contracts\Support\MessageBag $bag
58 * @return $this
59 */
60 public function put($key, MessageBagContract $bag)
61 {
62 $this->bags[$key] = $bag;
63
64 return $this;
65 }
66
67 /**
68 * Determine if the default message bag has any messages.
69 *
70 * @return bool
71 */
72 public function any()
73 {
74 return $this->count() > 0;
75 }
76
77 /**
78 * Get the number of messages in the default bag.
79 *
80 * @return int
81 */
82 public function count(): int
83 {
84 return $this->getBag('default')->count();
85 }
86
87 /**
88 * Dynamically call methods on the default bag.
89 *
90 * @param string $method
91 * @param array $parameters
92 * @return mixed
93 */
94 public function __call($method, $parameters)
95 {
96 return $this->getBag('default')->$method(...$parameters);
97 }
98
99 /**
100 * Dynamically access a view error bag.
101 *
102 * @param string $key
103 * @return \Illuminate\Contracts\Support\MessageBag
104 */
105 public function __get($key)
106 {
107 return $this->getBag($key);
108 }
109
110 /**
111 * Dynamically set a view error bag.
112 *
113 * @param string $key
114 * @param \Illuminate\Contracts\Support\MessageBag $value
115 * @return void
116 */
117 public function __set($key, $value)
118 {
119 $this->put($key, $value);
120 }
121
122 /**
123 * Convert the default bag to its string representation.
124 *
125 * @return string
126 */
127 public function __toString()
128 {
129 return (string) $this->getBag('default');
130 }
131 }