flexible-shipping
/
vendor_prefixed
/
wpdesk
/
wp-mutex
/
src
/
WPDesk
/
Mutex
/
StaticMutexStorage.php
Mutex.php
2 weeks ago
MutexNotFoundInStorage.php
2 weeks ago
MutexStorage.php
2 weeks ago
StaticMutexStorage.php
2 weeks ago
WordpressMySQLLockMutex.php
2 weeks ago
WordpressPostMutex.php
2 weeks ago
WordpressWpdb.php
2 weeks ago
StaticMutexStorage.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor\WPDesk\Mutex; |
| 4 | |
| 5 | class StaticMutexStorage implements MutexStorage |
| 6 | { |
| 7 | /** |
| 8 | * @var Mutex[] |
| 9 | */ |
| 10 | public static $mutexStorage; |
| 11 | /** |
| 12 | * Add to storage. |
| 13 | * |
| 14 | * @param string $name |
| 15 | * @param Mutex $mutex |
| 16 | */ |
| 17 | public function addToStorage($name, $mutex) |
| 18 | { |
| 19 | self::$mutexStorage[$name] = $mutex; |
| 20 | } |
| 21 | /** |
| 22 | * @param string $name |
| 23 | * |
| 24 | * @return null|Mutex |
| 25 | */ |
| 26 | public function getFromStorage($name) |
| 27 | { |
| 28 | return isset(self::$mutexStorage[$name]) ? self::$mutexStorage[$name] : null; |
| 29 | } |
| 30 | /** |
| 31 | * @param string $name |
| 32 | * |
| 33 | * @return void |
| 34 | */ |
| 35 | public function removeFromStorage($name) |
| 36 | { |
| 37 | if (isset(self::$mutexStorage[$name])) { |
| 38 | unset(self::$mutexStorage[$name]); |
| 39 | } else { |
| 40 | throw new MutexNotFoundInStorage(); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 |