PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.1.2
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.1.2
2.5.0 2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 All 34 releases
fluent-booking / vendor / woocommerce / action-scheduler / classes / abstracts / ActionScheduler_Lock.php

ActionScheduler_Lock.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 2.1.2, at vendor/woocommerce/action-scheduler/classes/abstracts/ActionScheduler_Lock.php

65 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Abstract class for setting a basic lock to throttle some action.
5 *
6 * Class ActionScheduler_Lock
7 */
8 abstract class ActionScheduler_Lock {
9
10 /** @var ActionScheduler_Lock */
11 private static $locker = NULL;
12
13 /** @var int */
14 protected static $lock_duration = MINUTE_IN_SECONDS;
15
16 /**
17 * Check if a lock is set for a given lock type.
18 *
19 * @param string $lock_type A string to identify different lock types.
20 * @return bool
21 */
22 public function is_locked( $lock_type ) {
23 return ( $this->get_expiration( $lock_type ) >= time() );
24 }
25
26 /**
27 * Set a lock.
28 *
29 * To prevent race conditions, implementations should avoid setting the lock if the lock is already held.
30 *
31 * @param string $lock_type A string to identify different lock types.
32 * @return bool
33 */
34 abstract public function set( $lock_type );
35
36 /**
37 * If a lock is set, return the timestamp it was set to expiry.
38 *
39 * @param string $lock_type A string to identify different lock types.
40 * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire.
41 */
42 abstract public function get_expiration( $lock_type );
43
44 /**
45 * Get the amount of time to set for a given lock. 60 seconds by default.
46 *
47 * @param string $lock_type A string to identify different lock types.
48 * @return int
49 */
50 protected function get_duration( $lock_type ) {
51 return apply_filters( 'action_scheduler_lock_duration', self::$lock_duration, $lock_type );
52 }
53
54 /**
55 * @return ActionScheduler_Lock
56 */
57 public static function instance() {
58 if ( empty( self::$locker ) ) {
59 $class = apply_filters( 'action_scheduler_lock_class', 'ActionScheduler_OptionLock' );
60 self::$locker = new $class();
61 }
62 return self::$locker;
63 }
64 }
65