PluginProbe
WANotifier for Forms and Actions / 2.7.5
WANotifier for Forms and Actions v2.7.5
3.1.1 3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 All 67 releases
notifier / libraries / action-scheduler / classes / abstracts / ActionScheduler_Lock.php

ActionScheduler_Lock.php in WANotifier for Forms and Actions 2.7.5, at libraries/action-scheduler/classes/abstracts/ActionScheduler_Lock.php

63 lines 1.6 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 * @param string $lock_type A string to identify different lock types.
30 * @return bool
31 */
32 abstract public function set( $lock_type );
33
34 /**
35 * If a lock is set, return the timestamp it was set to expiry.
36 *
37 * @param string $lock_type A string to identify different lock types.
38 * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire.
39 */
40 abstract public function get_expiration( $lock_type );
41
42 /**
43 * Get the amount of time to set for a given lock. 60 seconds by default.
44 *
45 * @param string $lock_type A string to identify different lock types.
46 * @return int
47 */
48 protected function get_duration( $lock_type ) {
49 return apply_filters( 'action_scheduler_lock_duration', self::$lock_duration, $lock_type );
50 }
51
52 /**
53 * @return ActionScheduler_Lock
54 */
55 public static function instance() {
56 if ( empty( self::$locker ) ) {
57 $class = apply_filters( 'action_scheduler_lock_class', 'ActionScheduler_OptionLock' );
58 self::$locker = new $class();
59 }
60 return self::$locker;
61 }
62 }
63