Config
4 years ago
Helpers
4 years ago
Migrations
4 years ago
Routes
1 year ago
Setup
5 months ago
Wizard
1 year ago
BlockFactory.php
1 year ago
DefaultFormFactory.php
1 year ago
FormRepository.php
1 year ago
LocaleCollection.php
4 years ago
SettingsRepository.php
4 years ago
SettingsRepositoryFactory.php
4 years ago
SettingsRepository.php
85 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Onboarding; |
| 4 | |
| 5 | /** |
| 6 | * @since 2.8.0 |
| 7 | */ |
| 8 | class SettingsRepository |
| 9 | { |
| 10 | |
| 11 | /** @var array */ |
| 12 | protected $settings; |
| 13 | |
| 14 | /** @var callable */ |
| 15 | protected $persistCallback; |
| 16 | |
| 17 | /** |
| 18 | * @since 2.8.0 |
| 19 | * |
| 20 | * @param callable $persistCallback |
| 21 | * |
| 22 | * @param array $settings |
| 23 | */ |
| 24 | public function __construct(array $settings, callable $persistCallback) |
| 25 | { |
| 26 | $this->settings = $settings; |
| 27 | $this->persistCallback = $persistCallback; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @since 2.8.0 |
| 32 | * |
| 33 | * @param string $name The setting name. |
| 34 | * |
| 35 | * @return mixed The setting value. |
| 36 | * |
| 37 | */ |
| 38 | public function get($name) |
| 39 | { |
| 40 | return ($this->has($name)) |
| 41 | ? $this->settings[$name] |
| 42 | : null; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @since 2.8.0 |
| 47 | * |
| 48 | * @param mixed $value The setting value. |
| 49 | * |
| 50 | * @param string $name The setting name. |
| 51 | * |
| 52 | * @return void |
| 53 | * |
| 54 | */ |
| 55 | public function set($name, $value) |
| 56 | { |
| 57 | $this->settings[$name] = $value; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @since 2.8.0 |
| 62 | * |
| 63 | * @param string $name The setting name. |
| 64 | * |
| 65 | * @return bool |
| 66 | * |
| 67 | */ |
| 68 | public function has($name) |
| 69 | { |
| 70 | return isset($this->settings[$name]); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @since 2.8.0 |
| 75 | * @return bool False if value was not updated and true if value was updated. |
| 76 | * |
| 77 | */ |
| 78 | public function save() |
| 79 | { |
| 80 | return $this->persistCallback->__invoke( |
| 81 | $this->settings |
| 82 | ); |
| 83 | } |
| 84 | } |
| 85 |