1 | <?php |
||
8 | trait HasSettings |
||
9 | { |
||
10 | /** |
||
11 | * Instance of Settings. |
||
12 | * |
||
13 | * @var LaravelPropertyBag\Settings\Settings |
||
14 | */ |
||
15 | protected $settings = null; |
||
16 | |||
17 | /** |
||
18 | * A resource has many settings in a property bag. |
||
19 | * |
||
20 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
21 | */ |
||
22 | public function propertyBag() |
||
26 | |||
27 | /** |
||
28 | * If passed is string, get settings class for the resource or return value |
||
29 | * for given key. If passed is array, set the key value pair. |
||
30 | * |
||
31 | * @param string|array $passed |
||
32 | * |
||
33 | * @return LaravelPropertyBag\Settings\Settings|mixed |
||
34 | */ |
||
35 | public function settings($passed = null) |
||
47 | |||
48 | /** |
||
49 | * Get settings off this or create new instance. |
||
50 | * |
||
51 | * @return LaravelPropertyBag\Settings\Settings |
||
52 | */ |
||
53 | protected function getSettingsInstance() |
||
63 | |||
64 | /** |
||
65 | * Get the settings class name. |
||
66 | * |
||
67 | * @throws ResourceNotFound |
||
68 | * |
||
69 | * @return LaravelPropertyBag\Settings\ResourceConfig |
||
70 | */ |
||
71 | protected function getSettingsConfig() |
||
87 | |||
88 | /** |
||
89 | * Get the short name of the model. |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | protected function getShortClassName() |
||
99 | |||
100 | /** |
||
101 | * Set settings. |
||
102 | * |
||
103 | * @param array $attributes |
||
104 | * |
||
105 | * @return LaravelPropertyBag\Settings\Settings |
||
106 | */ |
||
107 | public function setSettings(array $attributes) |
||
111 | |||
112 | /** |
||
113 | * Set all allowed settings by Request. |
||
114 | * |
||
115 | * @return LaravelPropertyBag\Settings\Settings |
||
116 | */ |
||
117 | public function setSettingsByRequest() |
||
123 | |||
124 | /** |
||
125 | * Get all settings. |
||
126 | * |
||
127 | * @return \Illuminate\Support\Collection |
||
128 | */ |
||
129 | public function allSettings() |
||
133 | |||
134 | /** |
||
135 | * Get all default settings or default setting for single key if given. |
||
136 | * |
||
137 | * @param string $key |
||
138 | * |
||
139 | * @return \Illuminate\Support\Collection|mixed |
||
140 | */ |
||
141 | public function defaultSetting($key = null) |
||
149 | |||
150 | /** |
||
151 | * Get all allowed settings or allowed settings for single ke if given. |
||
152 | * |
||
153 | * @param string $key |
||
154 | * |
||
155 | * @return \Illuminate\Support\Collection |
||
156 | */ |
||
157 | public function allowedSetting($key = null) |
||
165 | |||
166 | /** |
||
167 | * Get an array with all stored rows with a given setting and/or value. |
||
168 | * |
||
169 | * @param $key |
||
170 | * @param null $value |
||
171 | * |
||
172 | * @return \Illuminate\Support\Collection |
||
173 | */ |
||
174 | public static function withSetting($key, $value = null) |
||
184 | } |
||
185 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.