Completed
Push — master ( deca00...5388ff )
by Sam
24s
created

Config_ForClass::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Core\Config;
4
5
use SilverStripe\Dev\Deprecation;
6
7
class Config_ForClass
8
{
9
    /**
10
     * @var string $class
11
     */
12
    protected $class;
13
14
    /**
15
     * @param string|object $class
16
     */
17
    public function __construct($class)
18
    {
19
        $this->class = is_object($class) ? get_class($class) : $class;
20
    }
21
22
    /**
23
     * @param string $name
24
     * @return mixed
25
     */
26
    public function __get($name)
27
    {
28
        return $this->get($name);
29
    }
30
31
    /**
32
     * @param string $name
33
     * @param mixed $val
34
     */
35
    public function __set($name, $val)
36
    {
37
        $this->set($name, $val);
38
    }
39
40
    /**
41
     * Explicit pass-through to Config::update()
42
     *
43
     * @param string $name
44
     * @param mixed $value
45
     * @return $this
46
     */
47
    public function update($name, $value)
48
    {
49
        Deprecation::notice('5.0', 'Use merge() instead');
50
        return $this->merge($name, $value);
51
    }
52
53
    /**
54
     * Merge a given config
55
     *
56
     * @param string $name
57
     * @param mixed $value
58
     * @return $this
59
     */
60
    public function merge($name, $value)
61
    {
62
        Config::modify()->merge($this->class, $name, $value);
63
        return $this;
64
    }
65
66
    /**
67
     * Replace config value
68
     *
69
     * @param string $name
70
     * @param mixed $value
71
     * @return $this
72
     */
73
    public function set($name, $value)
74
    {
75
        Config::modify()->set($this->class, $name, $value);
76
        return $this;
77
    }
78
79
        /**
80
     * @param string $name
81
     * @return bool
82
     */
83
    public function __isset($name)
84
    {
85
        $val = $this->__get($name);
86
        return isset($val);
87
    }
88
89
    /**
90
     * @param string $name
91
     * @param mixed $options
92
     * @return mixed
93
     */
94
    public function get($name, $options = 0)
95
    {
96
        return Config::inst()->get($this->class, $name, $options);
97
    }
98
99
    /**
100
     * Remove the given config key
101
     *
102
     * @param string $name
103
     * @return $this
104
     */
105
    public function remove($name)
106
    {
107
        Config::modify()->remove($this->class, $name);
108
        return $this;
109
    }
110
111
    /**
112
     * @param string
113
     *
114
     * @return Config_ForClass
115
     */
116
    public function forClass($class)
117
    {
118
        return Config::forClass($class);
119
    }
120
121
    /**
122
     * Get uninherited config
123
     *
124
     * @param string $name Name of config
125
     * @return mixed
126
     */
127
    public function uninherited($name)
128
    {
129
        return $this->get($name, Config::UNINHERITED);
130
    }
131
}
132