Completed
Push — master ( f3de4e...8ad472 )
by Ryan
02:12
created

ConfigurationModel::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php namespace Anomaly\ConfigurationModule\Configuration;
2
3
use Anomaly\ConfigurationModule\Configuration\Command\GetValueFieldType;
4
use Anomaly\ConfigurationModule\Configuration\Command\GetValuePresenter;
5
use Anomaly\ConfigurationModule\Configuration\Command\ModifyValue;
6
use Anomaly\ConfigurationModule\Configuration\Contract\ConfigurationInterface;
7
use Anomaly\Streams\Platform\Addon\FieldType\FieldType;
8
use Anomaly\Streams\Platform\Addon\FieldType\FieldTypePresenter;
9
use Anomaly\Streams\Platform\Model\Configuration\ConfigurationConfigurationEntryModel;
10
11
/**
12
 * Class ConfigurationModel
13
 *
14
 * @link          http://pyrocms.com/
15
 * @author        PyroCMS, Inc. <[email protected]>
16
 * @author        Ryan Thompson <[email protected]>
17
 */
18
class ConfigurationModel extends ConfigurationConfigurationEntryModel implements ConfigurationInterface
19
{
20
21
    /**
22
     * Return the value field.
23
     *
24
     * @return FieldType
25
     */
26
    public function field()
27
    {
28
        /* @var FieldType $field */
29
        $field = $this->dispatch(new GetValueFieldType($this));
30
31
        if (!$field) {
32
            return null;
33
        }
34
35
        return $field;
36
    }
37
38
    /**
39
     * Get the key.
40
     *
41
     * @return string
42
     */
43
    public function getKey()
44
    {
45
        return $this->key;
46
    }
47
48
    /**
49
     * Set the key.
50
     *
51
     * @param $key
52
     * @return $this
53
     */
54
    public function setKey($key)
55
    {
56
        $this->key = $key;
57
58
        return $this;
59
    }
60
61
    /**
62
     * Get the scope.
63
     *
64
     * @return mixed
65
     */
66
    public function getScope()
67
    {
68
        return $this->scope;
69
    }
70
71
    /**
72
     * Set the scope.
73
     *
74
     * @param $scope
75
     * @return $this
76
     */
77
    public function setScope($scope)
78
    {
79
        $this->scope = $scope;
80
81
        return $this;
82
    }
83
84
    /**
85
     * Get the value.
86
     *
87
     * @return mixed
88
     */
89
    public function getValue()
90
    {
91
        return $this->value;
92
    }
93
94
    /**
95
     * Set the value.
96
     *
97
     * @param $value
98
     * @return $this
99
     */
100
    public function setValue($value)
101
    {
102
        $this->value = $value;
103
104
        return $this;
105
    }
106
107
    /**
108
     * Set the value.
109
     *
110
     * @param $value
111
     * @return $this
112
     */
113
    protected function setValueAttribute($value)
114
    {
115
        $this->attributes['value'] = $this->dispatch(new ModifyValue($this, $value));
116
117
        return $this;
118
    }
119
120
    /**
121
     * Get the value attribute.
122
     *
123
     * @return mixed
124
     */
125
    protected function getValueAttribute()
126
    {
127
        if (!$field = $this->field()) {
128
            return null;
129
        }
130
131
        return $field->getValue();
132
    }
133
134
    /**
135
     * Get the field type's presenter
136
     * for a given field slug.
137
     *
138
     * We're overriding this to catch
139
     * the "value" key.
140
     *
141
     * @param $fieldSlug
142
     * @return FieldTypePresenter
143
     */
144
    public function getFieldTypePresenter($fieldSlug)
145
    {
146
        if ($fieldSlug == 'value') {
147
            return $this->dispatch(new GetValuePresenter($this));
148
        }
149
150
        return parent::getFieldTypePresenter($fieldSlug);
151
    }
152
}
153