1 | <?php namespace Modules\Setting\Support; |
||
6 | class Settings implements Setting |
||
7 | { |
||
8 | /** |
||
9 | * @var SettingRepository |
||
10 | */ |
||
11 | private $setting; |
||
12 | |||
13 | /** |
||
14 | * @param SettingRepository $setting |
||
15 | */ |
||
16 | public function __construct(SettingRepository $setting) |
||
20 | |||
21 | /** |
||
22 | * Getting the setting |
||
23 | * @param string $name |
||
24 | * @param string $locale |
||
25 | * @param string $default |
||
26 | * @return mixed |
||
27 | */ |
||
28 | public function get($name, $locale = null, $default = null) |
||
29 | { |
||
30 | $defaultFromConfig = $this->getDefaultFromConfigFor($name); |
||
31 | |||
32 | $setting = $this->setting->get($name); |
||
33 | if (! $setting) { |
||
34 | return is_null($default) ? $defaultFromConfig : $default; |
||
35 | } |
||
36 | |||
37 | if ($setting->isTranslatable) { |
||
38 | if ($setting->hasTranslation($locale)) { |
||
39 | return empty($setting->translate($locale)->value) ? $defaultFromConfig : $setting->translate($locale)->value; |
||
40 | } |
||
41 | } else { |
||
42 | return empty($setting->plainValue) ? $defaultFromConfig : $setting->plainValue; |
||
43 | } |
||
44 | |||
45 | return $defaultFromConfig; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Determine if the given configuration value exists. |
||
50 | * |
||
51 | * @param string $name |
||
52 | * @return bool |
||
53 | */ |
||
54 | public function has($name) |
||
60 | |||
61 | /** |
||
62 | * Set a given configuration value. |
||
63 | * |
||
64 | * @param string $key |
||
65 | * @param mixed $value |
||
66 | * @return void |
||
67 | */ |
||
68 | public function set($key, $value) |
||
71 | |||
72 | /** |
||
73 | * Get the default value from the settings configuration file, |
||
74 | * for the given setting name. |
||
75 | * @param string $name |
||
76 | * @return string |
||
77 | */ |
||
78 | private function getDefaultFromConfigFor($name) |
||
84 | } |
||
85 |