PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.2
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.2
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / Libraries / action-scheduler / classes / abstracts / ActionScheduler_Lock.php

ActionScheduler_Lock.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.2, at app/Services/Libraries/action-scheduler/classes/abstracts/ActionScheduler_Lock.php

75 lines 1.8 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 /**
11 * Instance.
12 *
13 * @var ActionScheduler_Lock
14 */
15 private static $locker = null;
16
17 /**
18 * Duration of lock.
19 *
20 * @var int
21 */
22 protected static $lock_duration = MINUTE_IN_SECONDS;
23
24 /**
25 * Check if a lock is set for a given lock type.
26 *
27 * @param string $lock_type A string to identify different lock types.
28 * @return bool
29 */
30 public function is_locked( $lock_type ) {
31 return ( $this->get_expiration( $lock_type ) >= time() );
32 }
33
34 /**
35 * Set a lock.
36 *
37 * To prevent race conditions, implementations should avoid setting the lock if the lock is already held.
38 *
39 * @param string $lock_type A string to identify different lock types.
40 * @return bool
41 */
42 abstract public function set( $lock_type );
43
44 /**
45 * If a lock is set, return the timestamp it was set to expiry.
46 *
47 * @param string $lock_type A string to identify different lock types.
48 * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire.
49 */
50 abstract public function get_expiration( $lock_type );
51
52 /**
53 * Get the amount of time to set for a given lock. 60 seconds by default.
54 *
55 * @param string $lock_type A string to identify different lock types.
56 * @return int
57 */
58 protected function get_duration( $lock_type ) {
59 return apply_filters( 'action_scheduler_lock_duration', self::$lock_duration, $lock_type );
60 }
61
62 /**
63 * Get instance.
64 *
65 * @return ActionScheduler_Lock
66 */
67 public static function instance() {
68 if ( empty( self::$locker ) ) {
69 $class = apply_filters( 'action_scheduler_lock_class', 'ActionScheduler_OptionLock' );
70 self::$locker = new $class();
71 }
72 return self::$locker;
73 }
74 }
75