| @@ -13,110 +13,106 @@ | ||
| 13 | 13 | * @property string $expires_at |
| 14 | 14 | * |
| 15 | 15 | * @package Boxzilla\Licensing |
| 16 | 16 | */ |
| 17 | -class License | |
| 18 | -{ | |
| 19 | - /** | |
| 20 | - * @var string The name of the option that holds the License data | |
| 21 | - */ | |
| 22 | - protected $option_key = ''; | |
| 17 | +class License { | |
| 23 | 18 | |
| 24 | - /** | |
| 25 | - * @var bool Loaded? | |
| 26 | - */ | |
| 27 | - protected $loaded = false; | |
| 28 | 19 | |
| 29 | - /** | |
| 30 | - * @var bool Any changes? | |
| 31 | - */ | |
| 32 | - protected $dirty = false; | |
| 20 | + /** | |
| 21 | + * @var string The name of the option that holds the License data | |
| 22 | + */ | |
| 23 | + protected $option_key = ''; | |
| 33 | 24 | |
| 34 | - /** | |
| 35 | - * @var array | |
| 36 | - */ | |
| 37 | - protected $data; | |
| 25 | + /** | |
| 26 | + * @var bool Loaded? | |
| 27 | + */ | |
| 28 | + protected $loaded = false; | |
| 38 | 29 | |
| 39 | - /** | |
| 40 | - * @param string $option_key | |
| 41 | - */ | |
| 42 | - public function __construct($option_key) | |
| 43 | - { | |
| 44 | - $this->option_key = $option_key; | |
| 45 | - } | |
| 30 | + /** | |
| 31 | + * @var bool Any changes? | |
| 32 | + */ | |
| 33 | + protected $dirty = false; | |
| 46 | 34 | |
| 47 | - /** | |
| 48 | - * @param string $name | |
| 49 | - * @param mixed $value | |
| 50 | - */ | |
| 51 | - public function __set($name, $value) | |
| 52 | - { | |
| 53 | - $this->load(); | |
| 54 | - $this->data[ $name ] = $value; | |
| 55 | - $this->dirty = true; | |
| 56 | - } | |
| 35 | + /** | |
| 36 | + * @var array | |
| 37 | + */ | |
| 38 | + protected $data; | |
| 57 | 39 | |
| 58 | - /** | |
| 59 | - * @param string $name | |
| 60 | - * | |
| 61 | - * @return mixed | |
| 62 | - */ | |
| 63 | - public function __get($name) | |
| 64 | - { | |
| 65 | - $this->load(); | |
| 66 | - return $this->data[ $name ]; | |
| 67 | - } | |
| 40 | + /** | |
| 41 | + * @param string $option_key | |
| 42 | + */ | |
| 43 | + public function __construct( $option_key ) { | |
| 44 | + $this->option_key = $option_key; | |
| 45 | + } | |
| 68 | 46 | |
| 69 | - /** | |
| 70 | - * @param $name | |
| 71 | - * | |
| 72 | - * @return bool | |
| 73 | - */ | |
| 74 | - public function __isset($name) | |
| 75 | - { | |
| 76 | - $this->load(); | |
| 77 | - return isset($this->data[ $name ]); | |
| 78 | - } | |
| 47 | + /** | |
| 48 | + * @param string $name | |
| 49 | + * @param mixed $value | |
| 50 | + */ | |
| 51 | + public function __set( $name, $value ) { | |
| 52 | + $this->load(); | |
| 53 | + $this->data[ $name ] = $value; | |
| 54 | + $this->dirty = true; | |
| 55 | + } | |
| 79 | 56 | |
| 80 | - /** | |
| 81 | - * Load the license data from the database | |
| 82 | - */ | |
| 83 | - protected function load() | |
| 84 | - { | |
| 85 | - if ($this->loaded) { | |
| 86 | - return; | |
| 87 | - } | |
| 57 | + /** | |
| 58 | + * @param string $name | |
| 59 | + * | |
| 60 | + * @return mixed | |
| 61 | + */ | |
| 62 | + public function __get( $name ) { | |
| 63 | + $this->load(); | |
| 64 | + return $this->data[ $name ]; | |
| 65 | + } | |
| 88 | 66 | |
| 89 | - $defaults = [ | |
| 90 | - 'key' => '', | |
| 91 | - 'activation_key' => '', | |
| 92 | - 'activated' => false, | |
| 93 | - 'expires_at' => '', | |
| 94 | - ]; | |
| 67 | + /** | |
| 68 | + * @param $name | |
| 69 | + * | |
| 70 | + * @return bool | |
| 71 | + */ | |
| 72 | + public function __isset( $name ) { | |
| 73 | + $this->load(); | |
| 74 | + return isset( $this->data[ $name ] ); | |
| 75 | + } | |
| 95 | 76 | |
| 96 | - $data = (array) get_option($this->option_key, []); | |
| 97 | - $this->data = array_replace($defaults, $data); | |
| 98 | - $this->loaded = true; | |
| 99 | - } | |
| 77 | + /** | |
| 78 | + * Load the license data from the database | |
| 79 | + */ | |
| 80 | + protected function load() { | |
| 81 | + if ( $this->loaded ) { | |
| 82 | + return; | |
| 83 | + } | |
| 100 | 84 | |
| 101 | - /** | |
| 102 | - * Reload the license data from DB | |
| 103 | - */ | |
| 104 | - public function reload() | |
| 105 | - { | |
| 106 | - $this->loaded = false; | |
| 107 | - $this->load(); | |
| 108 | - } | |
| 85 | + $defaults = array( | |
| 86 | + 'key' => '', | |
| 87 | + 'activation_key' => '', | |
| 88 | + 'activated' => false, | |
| 89 | + 'expires_at' => '', | |
| 90 | + ); | |
| 109 | 91 | |
| 110 | - /** | |
| 111 | - * Save the license in the database | |
| 112 | - */ | |
| 113 | - public function save() | |
| 114 | - { | |
| 115 | - if (! $this->dirty) { | |
| 116 | - return; | |
| 117 | - } | |
| 92 | + $data = (array) get_option( $this->option_key, array() ); | |
| 93 | + $this->data = array_replace( $defaults, $data ); | |
| 94 | + $this->loaded = true; | |
| 95 | + } | |
| 118 | 96 | |
| 119 | - update_option($this->option_key, $this->data, true); | |
| 120 | - $this->dirty = false; | |
| 121 | - } | |
| 97 | + /** | |
| 98 | + * Reload the license data from DB | |
| 99 | + */ | |
| 100 | + public function reload() { | |
| 101 | + $this->loaded = false; | |
| 102 | + $this->load(); | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * Save the license in the database | |
| 107 | + * | |
| 108 | + * @return License | |
| 109 | + */ | |
| 110 | + public function save() { | |
| 111 | + if ( ! $this->dirty ) { | |
| 112 | + return; | |
| 113 | + } | |
| 114 | + | |
| 115 | + update_option( $this->option_key, $this->data ); | |
| 116 | + $this->dirty = false; | |
| 117 | + } | |
| 122 | 118 | } |