PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / Dependencies / ActionScheduler / classes / abstracts / ActionScheduler_Abstract_Schedule.php

ActionScheduler_Abstract_Schedule.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at inc/Dependencies/ActionScheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php

90 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class ActionScheduler_Abstract_Schedule
5 */
6 abstract class ActionScheduler_Abstract_Schedule extends ActionScheduler_Schedule_Deprecated {
7
8 /**
9 * The date & time the schedule is set to run.
10 *
11 * @var DateTime
12 */
13 private $scheduled_date = null;
14
15 /**
16 * Timestamp equivalent of @see $this->scheduled_date
17 *
18 * @var int
19 */
20 protected $scheduled_timestamp = null;
21
22 /**
23 * Construct.
24 *
25 * @param DateTime $date The date & time to run the action.
26 */
27 public function __construct( DateTime $date ) {
28 $this->scheduled_date = $date;
29 }
30
31 /**
32 * Check if a schedule should recur.
33 *
34 * @return bool
35 */
36 abstract public function is_recurring();
37
38 /**
39 * Calculate when the next instance of this schedule would run based on a given date & time.
40 *
41 * @param DateTime $after Start timestamp.
42 * @return DateTime
43 */
44 abstract protected function calculate_next( DateTime $after );
45
46 /**
47 * Get the next date & time when this schedule should run after a given date & time.
48 *
49 * @param DateTime $after Start timestamp.
50 * @return DateTime|null
51 */
52 public function get_next( DateTime $after ) {
53 $after = clone $after;
54 if ( $after > $this->scheduled_date ) {
55 $after = $this->calculate_next( $after );
56 return $after;
57 }
58 return clone $this->scheduled_date;
59 }
60
61 /**
62 * Get the date & time the schedule is set to run.
63 *
64 * @return DateTime|null
65 */
66 public function get_date() {
67 return $this->scheduled_date;
68 }
69
70 /**
71 * For PHP 5.2 compat, because DateTime objects can't be serialized
72 *
73 * @return array
74 */
75 public function __sleep() {
76 $this->scheduled_timestamp = $this->scheduled_date->getTimestamp();
77 return array(
78 'scheduled_timestamp',
79 );
80 }
81
82 /**
83 * Wakeup.
84 */
85 public function __wakeup() {
86 $this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp );
87 unset( $this->scheduled_timestamp );
88 }
89 }
90