| 1 |
<?php |
| 2 |
|
| 3 |
use Pluginus\CurrencySwitcher\Storage\Storage; |
| 4 |
use Pluginus\CurrencySwitcher\Storage\TransientStorage; |
| 5 |
use Pluginus\CurrencySwitcher\Storage\CookieStorage; |
| 6 |
use Pluginus\CurrencySwitcher\Storage\SessionStorage; |
| 7 |
|
| 8 |
|
| 9 |
if (!defined('ABSPATH')) |
| 10 |
die('No direct access allowed'); |
| 11 |
|
| 12 |
//keeps current user data |
| 13 |
class WPCS_STORAGE { |
| 14 |
|
| 15 |
public $type = 'transient'; //session, transient, cookie |
| 16 |
|
| 17 |
private $storage = null; |
| 18 |
|
| 19 |
public function __construct( string $type = 'transient') { |
| 20 |
|
| 21 |
$this->storage = $this->get_storage_object($type); |
| 22 |
if ($this->storage === false) { |
| 23 |
$this->storage = $this->get_storage_object( $this->type ); |
| 24 |
} |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
public function set_val($key, $value) { |
| 29 |
$value = sanitize_text_field(esc_html($value)); |
| 30 |
$this->storage->setValue($key, $value); |
| 31 |
} |
| 32 |
|
| 33 |
public function get_val($key) { |
| 34 |
return $this->storage->getValue($key); |
| 35 |
} |
| 36 |
|
| 37 |
public function is_isset($key) { |
| 38 |
return $this->storage->isIsset($key); |
| 39 |
} |
| 40 |
|
| 41 |
private function get_storage_object(string $type) { |
| 42 |
$class = 'Pluginus\CurrencySwitcher\Storage\\' . ucfirst($type) . 'Storage'; |
| 43 |
return $class::create(); |
| 44 |
} |
| 45 |
|
| 46 |
} |
| 47 |
|