PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.2.0
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.2.0
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / vendor / woocommerce / action-scheduler / classes / abstracts / ActionScheduler_Lock.php

ActionScheduler_Lock.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.2.0, 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