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