summaryrefslogtreecommitdiff
path: root/src/Config/Config.php
blob: b1a93324dff624aa25ea0dad2089f4d5a1212361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

namespace Engelsystem\Config;

use Illuminate\Support\Fluent;

class Config extends Fluent
{
    /**
     * The config values
     *
     * @var array
     */
    protected $attributes = [];

    /**
     * @param string|null $key
     * @param mixed       $default
     * @return mixed
     */
    public function get($key, $default = null)
    {
        if (is_null($key)) {
            return $this->attributes;
        }

        if ($this->has($key)) {
            return $this->attributes[$key];
        }

        return $default;
    }

    /**
     * @param string|array $key
     * @param mixed        $value
     */
    public function set($key, $value = null)
    {
        if (is_array($key)) {
            foreach ($key as $configKey => $configValue) {
                $this->set($configKey, $configValue);
            }

            return;
        }

        $this->attributes[$key] = $value;
    }

    /**
     * @param string $key
     * @return bool
     */
    public function has($key)
    {
        return $this->offsetExists($key);
    }

    /**
     * @param string $key
     */
    public function remove($key)
    {
        $this->offsetUnset($key);
    }
}