| 1 | <?php |
||
| 10 | class Writing_On_GitHub_Semaphore { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Sempahore's option key. |
||
| 14 | */ |
||
| 15 | const KEY = 'wogh_semaphore_lock'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Option key when semaphore is locked. |
||
| 19 | */ |
||
| 20 | const VALUE_LOCKED = 'yes'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Option key when semaphore is unlocked. |
||
| 24 | */ |
||
| 25 | const VALUE_UNLOCKED = 'no'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Clean up the old values on instantiation. |
||
| 29 | */ |
||
| 30 | public function __construct() { |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Checks if the Semaphore is open. |
||
| 36 | * |
||
| 37 | * Fails to report it's open if the the Api class can't make a call |
||
| 38 | * or the push lock has been enabled. |
||
| 39 | * |
||
| 40 | * @return bool |
||
| 41 | */ |
||
| 42 | public function is_open() { |
||
| 43 | if ( self::VALUE_LOCKED === get_transient( self::KEY ) ) { |
||
| 44 | return false; |
||
| 45 | } |
||
| 46 | |||
| 47 | return true; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Enables the push lock. |
||
| 52 | */ |
||
| 53 | public function lock() { |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Disables the push lock. |
||
| 59 | */ |
||
| 60 | public function unlock() { |
||
| 62 | } |
||
| 63 | } |
||
| 64 |