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