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\Config;
4
 
5
use ArrayAccess;
6
use Illuminate\Contracts\Config\Repository as ConfigContract;
7
use Illuminate\Support\Arr;
8
use Illuminate\Support\Traits\Macroable;
9
 
10
class Repository implements ArrayAccess, ConfigContract
11
{
12
    use Macroable;
13
 
14
    /**
15
     * All of the configuration items.
16
     *
17
     * @var array
18
     */
19
    protected $items = [];
20
 
21
    /**
22
     * Create a new configuration repository.
23
     *
24
     * @param  array  $items
25
     * @return void
26
     */
27
    public function __construct(array $items = [])
28
    {
29
        $this->items = $items;
30
    }
31
 
32
    /**
33
     * Determine if the given configuration value exists.
34
     *
35
     * @param  string  $key
36
     * @return bool
37
     */
38
    public function has($key)
39
    {
40
        return Arr::has($this->items, $key);
41
    }
42
 
43
    /**
44
     * Get the specified configuration value.
45
     *
46
     * @param  array|string  $key
47
     * @param  mixed  $default
48
     * @return mixed
49
     */
50
    public function get($key, $default = null)
51
    {
52
        if (is_array($key)) {
53
            return $this->getMany($key);
54
        }
55
 
56
        return Arr::get($this->items, $key, $default);
57
    }
58
 
59
    /**
60
     * Get many configuration values.
61
     *
62
     * @param  array  $keys
63
     * @return array
64
     */
65
    public function getMany($keys)
66
    {
67
        $config = [];
68
 
69
        foreach ($keys as $key => $default) {
70
            if (is_numeric($key)) {
71
                [$key, $default] = [$default, null];
72
            }
73
 
74
            $config[$key] = Arr::get($this->items, $key, $default);
75
        }
76
 
77
        return $config;
78
    }
79
 
80
    /**
81
     * Set a given configuration value.
82
     *
83
     * @param  array|string  $key
84
     * @param  mixed  $value
85
     * @return void
86
     */
87
    public function set($key, $value = null)
88
    {
89
        $keys = is_array($key) ? $key : [$key => $value];
90
 
91
        foreach ($keys as $key => $value) {
92
            Arr::set($this->items, $key, $value);
93
        }
94
    }
95
 
96
    /**
97
     * Prepend a value onto an array configuration value.
98
     *
99
     * @param  string  $key
100
     * @param  mixed  $value
101
     * @return void
102
     */
103
    public function prepend($key, $value)
104
    {
105
        $array = $this->get($key, []);
106
 
107
        array_unshift($array, $value);
108
 
109
        $this->set($key, $array);
110
    }
111
 
112
    /**
113
     * Push a value onto an array configuration value.
114
     *
115
     * @param  string  $key
116
     * @param  mixed  $value
117
     * @return void
118
     */
119
    public function push($key, $value)
120
    {
121
        $array = $this->get($key, []);
122
 
123
        $array[] = $value;
124
 
125
        $this->set($key, $array);
126
    }
127
 
128
    /**
129
     * Get all of the configuration items for the application.
130
     *
131
     * @return array
132
     */
133
    public function all()
134
    {
135
        return $this->items;
136
    }
137
 
138
    /**
139
     * Determine if the given configuration option exists.
140
     *
141
     * @param  string  $key
142
     * @return bool
143
     */
144
    public function offsetExists($key): bool
145
    {
146
        return $this->has($key);
147
    }
148
 
149
    /**
150
     * Get a configuration option.
151
     *
152
     * @param  string  $key
153
     * @return mixed
154
     */
155
    public function offsetGet($key): mixed
156
    {
157
        return $this->get($key);
158
    }
159
 
160
    /**
161
     * Set a configuration option.
162
     *
163
     * @param  string  $key
164
     * @param  mixed  $value
165
     * @return void
166
     */
167
    public function offsetSet($key, $value): void
168
    {
169
        $this->set($key, $value);
170
    }
171
 
172
    /**
173
     * Unset a configuration option.
174
     *
175
     * @param  string  $key
176
     * @return void
177
     */
178
    public function offsetUnset($key): void
179
    {
180
        $this->set($key, null);
181
    }
182
}