@@ -7,56 +7,56 @@ |
||
7 | 7 | */ |
8 | 8 | class CronExpression_MonthField extends CronExpression_AbstractField { |
9 | 9 | |
10 | - /** |
|
11 | - * {@inheritdoc} |
|
12 | - */ |
|
13 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | - // Convert text month values to integers |
|
15 | - $value = str_ireplace( |
|
16 | - array( |
|
17 | - 'JAN', |
|
18 | - 'FEB', |
|
19 | - 'MAR', |
|
20 | - 'APR', |
|
21 | - 'MAY', |
|
22 | - 'JUN', |
|
23 | - 'JUL', |
|
24 | - 'AUG', |
|
25 | - 'SEP', |
|
26 | - 'OCT', |
|
27 | - 'NOV', |
|
28 | - 'DEC', |
|
29 | - ), |
|
30 | - range( 1, 12 ), |
|
31 | - $value |
|
32 | - ); |
|
10 | + /** |
|
11 | + * {@inheritdoc} |
|
12 | + */ |
|
13 | + public function isSatisfiedBy( DateTime $date, $value ) { |
|
14 | + // Convert text month values to integers |
|
15 | + $value = str_ireplace( |
|
16 | + array( |
|
17 | + 'JAN', |
|
18 | + 'FEB', |
|
19 | + 'MAR', |
|
20 | + 'APR', |
|
21 | + 'MAY', |
|
22 | + 'JUN', |
|
23 | + 'JUL', |
|
24 | + 'AUG', |
|
25 | + 'SEP', |
|
26 | + 'OCT', |
|
27 | + 'NOV', |
|
28 | + 'DEC', |
|
29 | + ), |
|
30 | + range( 1, 12 ), |
|
31 | + $value |
|
32 | + ); |
|
33 | 33 | |
34 | - return $this->isSatisfied( $date->format( 'm' ), $value ); |
|
35 | - } |
|
34 | + return $this->isSatisfied( $date->format( 'm' ), $value ); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * {@inheritdoc} |
|
39 | - */ |
|
40 | - public function increment( DateTime $date, $invert = false ) { |
|
41 | - if ( $invert ) { |
|
42 | - // $date->modify('last day of previous month'); // remove for php 5.2 compat |
|
43 | - $date->modify( 'previous month' ); |
|
44 | - $date->modify( $date->format( 'Y-m-t' ) ); |
|
45 | - $date->setTime( 23, 59 ); |
|
46 | - } else { |
|
47 | - // $date->modify('first day of next month'); // remove for php 5.2 compat |
|
48 | - $date->modify( 'next month' ); |
|
49 | - $date->modify( $date->format( 'Y-m-01' ) ); |
|
50 | - $date->setTime( 0, 0 ); |
|
51 | - } |
|
37 | + /** |
|
38 | + * {@inheritdoc} |
|
39 | + */ |
|
40 | + public function increment( DateTime $date, $invert = false ) { |
|
41 | + if ( $invert ) { |
|
42 | + // $date->modify('last day of previous month'); // remove for php 5.2 compat |
|
43 | + $date->modify( 'previous month' ); |
|
44 | + $date->modify( $date->format( 'Y-m-t' ) ); |
|
45 | + $date->setTime( 23, 59 ); |
|
46 | + } else { |
|
47 | + // $date->modify('first day of next month'); // remove for php 5.2 compat |
|
48 | + $date->modify( 'next month' ); |
|
49 | + $date->modify( $date->format( 'Y-m-01' ) ); |
|
50 | + $date->setTime( 0, 0 ); |
|
51 | + } |
|
52 | 52 | |
53 | - return $this; |
|
54 | - } |
|
53 | + return $this; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - public function validate( $value ) { |
|
60 | - return (bool) preg_match( '/[\*,\/\-0-9A-Z]+/', $value ); |
|
61 | - } |
|
56 | + /** |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + public function validate( $value ) { |
|
60 | + return (bool) preg_match( '/[\*,\/\-0-9A-Z]+/', $value ); |
|
61 | + } |
|
62 | 62 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * {@inheritdoc} |
12 | 12 | */ |
13 | - public function isSatisfiedBy( DateTime $date, $value ) { |
|
13 | + public function isSatisfiedBy(DateTime $date, $value) { |
|
14 | 14 | // Convert text month values to integers |
15 | 15 | $value = str_ireplace( |
16 | 16 | array( |
@@ -27,27 +27,27 @@ discard block |
||
27 | 27 | 'NOV', |
28 | 28 | 'DEC', |
29 | 29 | ), |
30 | - range( 1, 12 ), |
|
30 | + range(1, 12), |
|
31 | 31 | $value |
32 | 32 | ); |
33 | 33 | |
34 | - return $this->isSatisfied( $date->format( 'm' ), $value ); |
|
34 | + return $this->isSatisfied($date->format('m'), $value); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * {@inheritdoc} |
39 | 39 | */ |
40 | - public function increment( DateTime $date, $invert = false ) { |
|
41 | - if ( $invert ) { |
|
40 | + public function increment(DateTime $date, $invert = false) { |
|
41 | + if ($invert) { |
|
42 | 42 | // $date->modify('last day of previous month'); // remove for php 5.2 compat |
43 | - $date->modify( 'previous month' ); |
|
44 | - $date->modify( $date->format( 'Y-m-t' ) ); |
|
45 | - $date->setTime( 23, 59 ); |
|
43 | + $date->modify('previous month'); |
|
44 | + $date->modify($date->format('Y-m-t')); |
|
45 | + $date->setTime(23, 59); |
|
46 | 46 | } else { |
47 | 47 | // $date->modify('first day of next month'); // remove for php 5.2 compat |
48 | - $date->modify( 'next month' ); |
|
49 | - $date->modify( $date->format( 'Y-m-01' ) ); |
|
50 | - $date->setTime( 0, 0 ); |
|
48 | + $date->modify('next month'); |
|
49 | + $date->modify($date->format('Y-m-01')); |
|
50 | + $date->setTime(0, 0); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | return $this; |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | /** |
57 | 57 | * {@inheritdoc} |
58 | 58 | */ |
59 | - public function validate( $value ) { |
|
60 | - return (bool) preg_match( '/[\*,\/\-0-9A-Z]+/', $value ); |
|
59 | + public function validate($value) { |
|
60 | + return (bool) preg_match('/[\*,\/\-0-9A-Z]+/', $value); |
|
61 | 61 | } |
62 | 62 | } |
@@ -7,33 +7,33 @@ |
||
7 | 7 | */ |
8 | 8 | interface CronExpression_FieldInterface { |
9 | 9 | |
10 | - /** |
|
11 | - * Check if the respective value of a DateTime field satisfies a CRON exp |
|
12 | - * |
|
13 | - * @param DateTime $date DateTime object to check |
|
14 | - * @param string $value CRON expression to test against |
|
15 | - * |
|
16 | - * @return bool Returns TRUE if satisfied, FALSE otherwise |
|
17 | - */ |
|
18 | - public function isSatisfiedBy( DateTime $date, $value); |
|
10 | + /** |
|
11 | + * Check if the respective value of a DateTime field satisfies a CRON exp |
|
12 | + * |
|
13 | + * @param DateTime $date DateTime object to check |
|
14 | + * @param string $value CRON expression to test against |
|
15 | + * |
|
16 | + * @return bool Returns TRUE if satisfied, FALSE otherwise |
|
17 | + */ |
|
18 | + public function isSatisfiedBy( DateTime $date, $value); |
|
19 | 19 | |
20 | - /** |
|
21 | - * When a CRON expression is not satisfied, this method is used to increment |
|
22 | - * or decrement a DateTime object by the unit of the cron field |
|
23 | - * |
|
24 | - * @param DateTime $date DateTime object to change |
|
25 | - * @param bool $invert (optional) Set to TRUE to decrement |
|
26 | - * |
|
27 | - * @return CronExpression_FieldInterface |
|
28 | - */ |
|
29 | - public function increment( DateTime $date, $invert = false); |
|
20 | + /** |
|
21 | + * When a CRON expression is not satisfied, this method is used to increment |
|
22 | + * or decrement a DateTime object by the unit of the cron field |
|
23 | + * |
|
24 | + * @param DateTime $date DateTime object to change |
|
25 | + * @param bool $invert (optional) Set to TRUE to decrement |
|
26 | + * |
|
27 | + * @return CronExpression_FieldInterface |
|
28 | + */ |
|
29 | + public function increment( DateTime $date, $invert = false); |
|
30 | 30 | |
31 | - /** |
|
32 | - * Validates a CRON expression for a given field |
|
33 | - * |
|
34 | - * @param string $value CRON expression value to validate |
|
35 | - * |
|
36 | - * @return bool Returns TRUE if valid, FALSE otherwise |
|
37 | - */ |
|
38 | - public function validate( $value); |
|
31 | + /** |
|
32 | + * Validates a CRON expression for a given field |
|
33 | + * |
|
34 | + * @param string $value CRON expression value to validate |
|
35 | + * |
|
36 | + * @return bool Returns TRUE if valid, FALSE otherwise |
|
37 | + */ |
|
38 | + public function validate( $value); |
|
39 | 39 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return bool Returns TRUE if satisfied, FALSE otherwise |
17 | 17 | */ |
18 | - public function isSatisfiedBy( DateTime $date, $value); |
|
18 | + public function isSatisfiedBy(DateTime $date, $value); |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * When a CRON expression is not satisfied, this method is used to increment |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return CronExpression_FieldInterface |
28 | 28 | */ |
29 | - public function increment( DateTime $date, $invert = false); |
|
29 | + public function increment(DateTime $date, $invert = false); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Validates a CRON expression for a given field |
@@ -35,5 +35,5 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return bool Returns TRUE if valid, FALSE otherwise |
37 | 37 | */ |
38 | - public function validate( $value); |
|
38 | + public function validate($value); |
|
39 | 39 | } |
@@ -8,47 +8,47 @@ |
||
8 | 8 | */ |
9 | 9 | class CronExpression_FieldFactory { |
10 | 10 | |
11 | - /** |
|
12 | - * @var array Cache of instantiated fields |
|
13 | - */ |
|
14 | - private $fields = array(); |
|
11 | + /** |
|
12 | + * @var array Cache of instantiated fields |
|
13 | + */ |
|
14 | + private $fields = array(); |
|
15 | 15 | |
16 | - /** |
|
17 | - * Get an instance of a field object for a cron expression position |
|
18 | - * |
|
19 | - * @param int $position CRON expression position value to retrieve |
|
20 | - * |
|
21 | - * @return CronExpression_FieldInterface |
|
22 | - * @throws InvalidArgumentException if a position is not valid |
|
23 | - */ |
|
24 | - public function getField( $position ) { |
|
25 | - if ( ! isset( $this->fields[ $position ] ) ) { |
|
26 | - switch ( $position ) { |
|
27 | - case 0: |
|
28 | - $this->fields[ $position ] = new CronExpression_MinutesField(); |
|
29 | - break; |
|
30 | - case 1: |
|
31 | - $this->fields[ $position ] = new CronExpression_HoursField(); |
|
32 | - break; |
|
33 | - case 2: |
|
34 | - $this->fields[ $position ] = new CronExpression_DayOfMonthField(); |
|
35 | - break; |
|
36 | - case 3: |
|
37 | - $this->fields[ $position ] = new CronExpression_MonthField(); |
|
38 | - break; |
|
39 | - case 4: |
|
40 | - $this->fields[ $position ] = new CronExpression_DayOfWeekField(); |
|
41 | - break; |
|
42 | - case 5: |
|
43 | - $this->fields[ $position ] = new CronExpression_YearField(); |
|
44 | - break; |
|
45 | - default: |
|
46 | - throw new InvalidArgumentException( |
|
47 | - $position . ' is not a valid position' |
|
48 | - ); |
|
49 | - } |
|
50 | - } |
|
16 | + /** |
|
17 | + * Get an instance of a field object for a cron expression position |
|
18 | + * |
|
19 | + * @param int $position CRON expression position value to retrieve |
|
20 | + * |
|
21 | + * @return CronExpression_FieldInterface |
|
22 | + * @throws InvalidArgumentException if a position is not valid |
|
23 | + */ |
|
24 | + public function getField( $position ) { |
|
25 | + if ( ! isset( $this->fields[ $position ] ) ) { |
|
26 | + switch ( $position ) { |
|
27 | + case 0: |
|
28 | + $this->fields[ $position ] = new CronExpression_MinutesField(); |
|
29 | + break; |
|
30 | + case 1: |
|
31 | + $this->fields[ $position ] = new CronExpression_HoursField(); |
|
32 | + break; |
|
33 | + case 2: |
|
34 | + $this->fields[ $position ] = new CronExpression_DayOfMonthField(); |
|
35 | + break; |
|
36 | + case 3: |
|
37 | + $this->fields[ $position ] = new CronExpression_MonthField(); |
|
38 | + break; |
|
39 | + case 4: |
|
40 | + $this->fields[ $position ] = new CronExpression_DayOfWeekField(); |
|
41 | + break; |
|
42 | + case 5: |
|
43 | + $this->fields[ $position ] = new CronExpression_YearField(); |
|
44 | + break; |
|
45 | + default: |
|
46 | + throw new InvalidArgumentException( |
|
47 | + $position . ' is not a valid position' |
|
48 | + ); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - return $this->fields[ $position ]; |
|
53 | - } |
|
52 | + return $this->fields[ $position ]; |
|
53 | + } |
|
54 | 54 | } |
@@ -21,34 +21,34 @@ |
||
21 | 21 | * @return CronExpression_FieldInterface |
22 | 22 | * @throws InvalidArgumentException if a position is not valid |
23 | 23 | */ |
24 | - public function getField( $position ) { |
|
25 | - if ( ! isset( $this->fields[ $position ] ) ) { |
|
26 | - switch ( $position ) { |
|
24 | + public function getField($position) { |
|
25 | + if ( ! isset($this->fields[$position])) { |
|
26 | + switch ($position) { |
|
27 | 27 | case 0: |
28 | - $this->fields[ $position ] = new CronExpression_MinutesField(); |
|
28 | + $this->fields[$position] = new CronExpression_MinutesField(); |
|
29 | 29 | break; |
30 | 30 | case 1: |
31 | - $this->fields[ $position ] = new CronExpression_HoursField(); |
|
31 | + $this->fields[$position] = new CronExpression_HoursField(); |
|
32 | 32 | break; |
33 | 33 | case 2: |
34 | - $this->fields[ $position ] = new CronExpression_DayOfMonthField(); |
|
34 | + $this->fields[$position] = new CronExpression_DayOfMonthField(); |
|
35 | 35 | break; |
36 | 36 | case 3: |
37 | - $this->fields[ $position ] = new CronExpression_MonthField(); |
|
37 | + $this->fields[$position] = new CronExpression_MonthField(); |
|
38 | 38 | break; |
39 | 39 | case 4: |
40 | - $this->fields[ $position ] = new CronExpression_DayOfWeekField(); |
|
40 | + $this->fields[$position] = new CronExpression_DayOfWeekField(); |
|
41 | 41 | break; |
42 | 42 | case 5: |
43 | - $this->fields[ $position ] = new CronExpression_YearField(); |
|
43 | + $this->fields[$position] = new CronExpression_YearField(); |
|
44 | 44 | break; |
45 | 45 | default: |
46 | 46 | throw new InvalidArgumentException( |
47 | - $position . ' is not a valid position' |
|
47 | + $position.' is not a valid position' |
|
48 | 48 | ); |
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - return $this->fields[ $position ]; |
|
52 | + return $this->fields[$position]; |
|
53 | 53 | } |
54 | 54 | } |
@@ -15,293 +15,293 @@ |
||
15 | 15 | */ |
16 | 16 | class CronExpression { |
17 | 17 | |
18 | - const MINUTE = 0; |
|
19 | - const HOUR = 1; |
|
20 | - const DAY = 2; |
|
21 | - const MONTH = 3; |
|
22 | - const WEEKDAY = 4; |
|
23 | - const YEAR = 5; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var array CRON expression parts |
|
27 | - */ |
|
28 | - private $cronParts; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var CronExpression_FieldFactory CRON field factory |
|
32 | - */ |
|
33 | - private $fieldFactory; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array Order in which to test of cron parts |
|
37 | - */ |
|
38 | - private static $order = array( self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE ); |
|
39 | - |
|
40 | - /** |
|
41 | - * Factory method to create a new CronExpression. |
|
42 | - * |
|
43 | - * @param string $expression The CRON expression to create. There are |
|
44 | - * several special predefined values which can be used to substitute the |
|
45 | - * CRON expression: |
|
46 | - * |
|
47 | - * @yearly, @annually) - Run once a year, midnight, Jan. 1 - 0 0 1 1 * |
|
48 | - * @monthly - Run once a month, midnight, first of month - 0 0 1 * * |
|
49 | - * @weekly - Run once a week, midnight on Sun - 0 0 * * 0 |
|
50 | - * @daily - Run once a day, midnight - 0 0 * * * |
|
51 | - * @hourly - Run once an hour, first minute - 0 * * * * |
|
52 | - * |
|
53 | - * @param CronExpression_FieldFactory $fieldFactory (optional) Field factory to use |
|
54 | - * |
|
55 | - * @return CronExpression |
|
56 | - */ |
|
57 | - public static function factory( $expression, CronExpression_FieldFactory $fieldFactory = null ) { |
|
58 | - $mappings = array( |
|
59 | - '@yearly' => '0 0 1 1 *', |
|
60 | - '@annually' => '0 0 1 1 *', |
|
61 | - '@monthly' => '0 0 1 * *', |
|
62 | - '@weekly' => '0 0 * * 0', |
|
63 | - '@daily' => '0 0 * * *', |
|
64 | - '@hourly' => '0 * * * *', |
|
65 | - ); |
|
66 | - |
|
67 | - if ( isset( $mappings[ $expression ] ) ) { |
|
68 | - $expression = $mappings[ $expression ]; |
|
69 | - } |
|
70 | - |
|
71 | - return new self( $expression, $fieldFactory ? $fieldFactory : new CronExpression_FieldFactory() ); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Parse a CRON expression |
|
76 | - * |
|
77 | - * @param string $expression CRON expression (e.g. '8 * * * *') |
|
78 | - * @param CronExpression_FieldFactory $fieldFactory Factory to create cron fields |
|
79 | - */ |
|
80 | - public function __construct( $expression, CronExpression_FieldFactory $fieldFactory ) { |
|
81 | - $this->fieldFactory = $fieldFactory; |
|
82 | - $this->setExpression( $expression ); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Set or change the CRON expression |
|
87 | - * |
|
88 | - * @param string $value CRON expression (e.g. 8 * * * *) |
|
89 | - * |
|
90 | - * @return CronExpression |
|
91 | - * @throws InvalidArgumentException if not a valid CRON expression |
|
92 | - */ |
|
93 | - public function setExpression( $value ) { |
|
94 | - $this->cronParts = preg_split( '/\s/', $value, -1, PREG_SPLIT_NO_EMPTY ); |
|
95 | - if ( count( $this->cronParts ) < 5 ) { |
|
96 | - throw new InvalidArgumentException( |
|
97 | - $value . ' is not a valid CRON expression' |
|
98 | - ); |
|
99 | - } |
|
100 | - |
|
101 | - foreach ( $this->cronParts as $position => $part ) { |
|
102 | - $this->setPart( $position, $part ); |
|
103 | - } |
|
104 | - |
|
105 | - return $this; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Set part of the CRON expression |
|
110 | - * |
|
111 | - * @param int $position The position of the CRON expression to set |
|
112 | - * @param string $value The value to set |
|
113 | - * |
|
114 | - * @return CronExpression |
|
115 | - * @throws InvalidArgumentException if the value is not valid for the part |
|
116 | - */ |
|
117 | - public function setPart( $position, $value ) { |
|
118 | - if ( ! $this->fieldFactory->getField( $position )->validate( $value ) ) { |
|
119 | - throw new InvalidArgumentException( |
|
120 | - 'Invalid CRON field value ' . $value . ' as position ' . $position |
|
121 | - ); |
|
122 | - } |
|
123 | - |
|
124 | - $this->cronParts[ $position ] = $value; |
|
125 | - |
|
126 | - return $this; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Get a next run date relative to the current date or a specific date |
|
131 | - * |
|
132 | - * @param string|DateTime $currentTime (optional) Relative calculation date |
|
133 | - * @param int $nth (optional) Number of matches to skip before returning a |
|
134 | - * matching next run date. 0, the default, will return the current |
|
135 | - * date and time if the next run date falls on the current date and |
|
136 | - * time. Setting this value to 1 will skip the first match and go to |
|
137 | - * the second match. Setting this value to 2 will skip the first 2 |
|
138 | - * matches and so on. |
|
139 | - * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
140 | - * current date if it matches the cron expression |
|
141 | - * |
|
142 | - * @return DateTime |
|
143 | - * @throws RuntimeException on too many iterations |
|
144 | - */ |
|
145 | - public function getNextRunDate( $currentTime = 'now', $nth = 0, $allowCurrentDate = false ) { |
|
146 | - return $this->getRunDate( $currentTime, $nth, false, $allowCurrentDate ); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Get a previous run date relative to the current date or a specific date |
|
151 | - * |
|
152 | - * @param string|DateTime $currentTime (optional) Relative calculation date |
|
153 | - * @param int $nth (optional) Number of matches to skip before returning |
|
154 | - * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
155 | - * current date if it matches the cron expression |
|
156 | - * |
|
157 | - * @return DateTime |
|
158 | - * @throws RuntimeException on too many iterations |
|
159 | - * @see CronExpression::getNextRunDate |
|
160 | - */ |
|
161 | - public function getPreviousRunDate( $currentTime = 'now', $nth = 0, $allowCurrentDate = false ) { |
|
162 | - return $this->getRunDate( $currentTime, $nth, true, $allowCurrentDate ); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Get multiple run dates starting at the current date or a specific date |
|
167 | - * |
|
168 | - * @param int $total Set the total number of dates to calculate |
|
169 | - * @param string|DateTime $currentTime (optional) Relative calculation date |
|
170 | - * @param bool $invert (optional) Set to TRUE to retrieve previous dates |
|
171 | - * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
172 | - * current date if it matches the cron expression |
|
173 | - * |
|
174 | - * @return array Returns an array of run dates |
|
175 | - */ |
|
176 | - public function getMultipleRunDates( $total, $currentTime = 'now', $invert = false, $allowCurrentDate = false ) { |
|
177 | - $matches = array(); |
|
178 | - for ( $i = 0; $i < max( 0, $total ); $i++ ) { |
|
179 | - $matches[] = $this->getRunDate( $currentTime, $i, $invert, $allowCurrentDate ); |
|
180 | - } |
|
181 | - |
|
182 | - return $matches; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Get all or part of the CRON expression |
|
187 | - * |
|
188 | - * @param string $part (optional) Specify the part to retrieve or NULL to |
|
189 | - * get the full cron schedule string. |
|
190 | - * |
|
191 | - * @return string|null Returns the CRON expression, a part of the |
|
192 | - * CRON expression, or NULL if the part was specified but not found |
|
193 | - */ |
|
194 | - public function getExpression( $part = null ) { |
|
195 | - if ( null === $part ) { |
|
196 | - return implode( ' ', $this->cronParts ); |
|
197 | - } elseif ( array_key_exists( $part, $this->cronParts ) ) { |
|
198 | - return $this->cronParts[ $part ]; |
|
199 | - } |
|
200 | - |
|
201 | - return null; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Helper method to output the full expression. |
|
206 | - * |
|
207 | - * @return string Full CRON expression |
|
208 | - */ |
|
209 | - public function __toString() { |
|
210 | - return $this->getExpression(); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Determine if the cron is due to run based on the current date or a |
|
215 | - * specific date. This method assumes that the current number of |
|
216 | - * seconds are irrelevant, and should be called once per minute. |
|
217 | - * |
|
218 | - * @param string|DateTime $currentTime (optional) Relative calculation date |
|
219 | - * |
|
220 | - * @return bool Returns TRUE if the cron is due to run or FALSE if not |
|
221 | - */ |
|
222 | - public function isDue( $currentTime = 'now' ) { |
|
223 | - if ( 'now' === $currentTime ) { |
|
224 | - $currentDate = date( 'Y-m-d H:i' ); |
|
225 | - $currentTime = strtotime( $currentDate ); |
|
226 | - } elseif ( $currentTime instanceof DateTime ) { |
|
227 | - $currentDate = $currentTime->format( 'Y-m-d H:i' ); |
|
228 | - $currentTime = strtotime( $currentDate ); |
|
229 | - } else { |
|
230 | - $currentTime = new DateTime( $currentTime ); |
|
231 | - $currentTime->setTime( $currentTime->format( 'H' ), $currentTime->format( 'i' ), 0 ); |
|
232 | - $currentDate = $currentTime->format( 'Y-m-d H:i' ); |
|
233 | - $currentTime = (int) ( $currentTime->getTimestamp() ); |
|
234 | - } |
|
235 | - |
|
236 | - return $this->getNextRunDate( $currentDate, 0, true )->getTimestamp() == $currentTime; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Get the next or previous run date of the expression relative to a date |
|
241 | - * |
|
242 | - * @param string|DateTime $currentTime (optional) Relative calculation date |
|
243 | - * @param int $nth (optional) Number of matches to skip before returning |
|
244 | - * @param bool $invert (optional) Set to TRUE to go backwards in time |
|
245 | - * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
246 | - * current date if it matches the cron expression |
|
247 | - * |
|
248 | - * @return DateTime |
|
249 | - * @throws RuntimeException on too many iterations |
|
250 | - */ |
|
251 | - protected function getRunDate( $currentTime = null, $nth = 0, $invert = false, $allowCurrentDate = false ) { |
|
252 | - if ( $currentTime instanceof DateTime ) { |
|
253 | - $currentDate = $currentTime; |
|
254 | - } else { |
|
255 | - $currentDate = new DateTime( $currentTime ? $currentTime : 'now' ); |
|
256 | - $currentDate->setTimezone( new DateTimeZone( date_default_timezone_get() ) ); |
|
257 | - } |
|
258 | - |
|
259 | - $currentDate->setTime( $currentDate->format( 'H' ), $currentDate->format( 'i' ), 0 ); |
|
260 | - $nextRun = clone $currentDate; |
|
261 | - $nth = (int) $nth; |
|
262 | - |
|
263 | - // Set a hard limit to bail on an impossible date |
|
264 | - for ( $i = 0; $i < 1000; $i++ ) { |
|
265 | - |
|
266 | - foreach ( self::$order as $position ) { |
|
267 | - $part = $this->getExpression( $position ); |
|
268 | - if ( null === $part ) { |
|
269 | - continue; |
|
270 | - } |
|
271 | - |
|
272 | - $satisfied = false; |
|
273 | - // Get the field object used to validate this part |
|
274 | - $field = $this->fieldFactory->getField( $position ); |
|
275 | - // Check if this is singular or a list |
|
276 | - if ( strpos( $part, ',' ) === false ) { |
|
277 | - $satisfied = $field->isSatisfiedBy( $nextRun, $part ); |
|
278 | - } else { |
|
279 | - foreach ( array_map( 'trim', explode( ',', $part ) ) as $listPart ) { |
|
280 | - if ( $field->isSatisfiedBy( $nextRun, $listPart ) ) { |
|
281 | - $satisfied = true; |
|
282 | - break; |
|
283 | - } |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - // If the field is not satisfied, then start over |
|
288 | - if ( ! $satisfied ) { |
|
289 | - $field->increment( $nextRun, $invert ); |
|
290 | - continue 2; |
|
291 | - } |
|
292 | - } |
|
293 | - |
|
294 | - // Skip this match if needed |
|
295 | - if ( ( ! $allowCurrentDate && $nextRun == $currentDate ) || --$nth > -1 ) { |
|
296 | - $this->fieldFactory->getField( 0 )->increment( $nextRun, $invert ); |
|
297 | - continue; |
|
298 | - } |
|
299 | - |
|
300 | - return $nextRun; |
|
301 | - } |
|
302 | - |
|
303 | - // @codeCoverageIgnoreStart |
|
304 | - throw new RuntimeException( 'Impossible CRON expression' ); |
|
305 | - // @codeCoverageIgnoreEnd |
|
306 | - } |
|
18 | + const MINUTE = 0; |
|
19 | + const HOUR = 1; |
|
20 | + const DAY = 2; |
|
21 | + const MONTH = 3; |
|
22 | + const WEEKDAY = 4; |
|
23 | + const YEAR = 5; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var array CRON expression parts |
|
27 | + */ |
|
28 | + private $cronParts; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var CronExpression_FieldFactory CRON field factory |
|
32 | + */ |
|
33 | + private $fieldFactory; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array Order in which to test of cron parts |
|
37 | + */ |
|
38 | + private static $order = array( self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE ); |
|
39 | + |
|
40 | + /** |
|
41 | + * Factory method to create a new CronExpression. |
|
42 | + * |
|
43 | + * @param string $expression The CRON expression to create. There are |
|
44 | + * several special predefined values which can be used to substitute the |
|
45 | + * CRON expression: |
|
46 | + * |
|
47 | + * @yearly, @annually) - Run once a year, midnight, Jan. 1 - 0 0 1 1 * |
|
48 | + * @monthly - Run once a month, midnight, first of month - 0 0 1 * * |
|
49 | + * @weekly - Run once a week, midnight on Sun - 0 0 * * 0 |
|
50 | + * @daily - Run once a day, midnight - 0 0 * * * |
|
51 | + * @hourly - Run once an hour, first minute - 0 * * * * |
|
52 | + * |
|
53 | + * @param CronExpression_FieldFactory $fieldFactory (optional) Field factory to use |
|
54 | + * |
|
55 | + * @return CronExpression |
|
56 | + */ |
|
57 | + public static function factory( $expression, CronExpression_FieldFactory $fieldFactory = null ) { |
|
58 | + $mappings = array( |
|
59 | + '@yearly' => '0 0 1 1 *', |
|
60 | + '@annually' => '0 0 1 1 *', |
|
61 | + '@monthly' => '0 0 1 * *', |
|
62 | + '@weekly' => '0 0 * * 0', |
|
63 | + '@daily' => '0 0 * * *', |
|
64 | + '@hourly' => '0 * * * *', |
|
65 | + ); |
|
66 | + |
|
67 | + if ( isset( $mappings[ $expression ] ) ) { |
|
68 | + $expression = $mappings[ $expression ]; |
|
69 | + } |
|
70 | + |
|
71 | + return new self( $expression, $fieldFactory ? $fieldFactory : new CronExpression_FieldFactory() ); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Parse a CRON expression |
|
76 | + * |
|
77 | + * @param string $expression CRON expression (e.g. '8 * * * *') |
|
78 | + * @param CronExpression_FieldFactory $fieldFactory Factory to create cron fields |
|
79 | + */ |
|
80 | + public function __construct( $expression, CronExpression_FieldFactory $fieldFactory ) { |
|
81 | + $this->fieldFactory = $fieldFactory; |
|
82 | + $this->setExpression( $expression ); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Set or change the CRON expression |
|
87 | + * |
|
88 | + * @param string $value CRON expression (e.g. 8 * * * *) |
|
89 | + * |
|
90 | + * @return CronExpression |
|
91 | + * @throws InvalidArgumentException if not a valid CRON expression |
|
92 | + */ |
|
93 | + public function setExpression( $value ) { |
|
94 | + $this->cronParts = preg_split( '/\s/', $value, -1, PREG_SPLIT_NO_EMPTY ); |
|
95 | + if ( count( $this->cronParts ) < 5 ) { |
|
96 | + throw new InvalidArgumentException( |
|
97 | + $value . ' is not a valid CRON expression' |
|
98 | + ); |
|
99 | + } |
|
100 | + |
|
101 | + foreach ( $this->cronParts as $position => $part ) { |
|
102 | + $this->setPart( $position, $part ); |
|
103 | + } |
|
104 | + |
|
105 | + return $this; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Set part of the CRON expression |
|
110 | + * |
|
111 | + * @param int $position The position of the CRON expression to set |
|
112 | + * @param string $value The value to set |
|
113 | + * |
|
114 | + * @return CronExpression |
|
115 | + * @throws InvalidArgumentException if the value is not valid for the part |
|
116 | + */ |
|
117 | + public function setPart( $position, $value ) { |
|
118 | + if ( ! $this->fieldFactory->getField( $position )->validate( $value ) ) { |
|
119 | + throw new InvalidArgumentException( |
|
120 | + 'Invalid CRON field value ' . $value . ' as position ' . $position |
|
121 | + ); |
|
122 | + } |
|
123 | + |
|
124 | + $this->cronParts[ $position ] = $value; |
|
125 | + |
|
126 | + return $this; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Get a next run date relative to the current date or a specific date |
|
131 | + * |
|
132 | + * @param string|DateTime $currentTime (optional) Relative calculation date |
|
133 | + * @param int $nth (optional) Number of matches to skip before returning a |
|
134 | + * matching next run date. 0, the default, will return the current |
|
135 | + * date and time if the next run date falls on the current date and |
|
136 | + * time. Setting this value to 1 will skip the first match and go to |
|
137 | + * the second match. Setting this value to 2 will skip the first 2 |
|
138 | + * matches and so on. |
|
139 | + * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
140 | + * current date if it matches the cron expression |
|
141 | + * |
|
142 | + * @return DateTime |
|
143 | + * @throws RuntimeException on too many iterations |
|
144 | + */ |
|
145 | + public function getNextRunDate( $currentTime = 'now', $nth = 0, $allowCurrentDate = false ) { |
|
146 | + return $this->getRunDate( $currentTime, $nth, false, $allowCurrentDate ); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Get a previous run date relative to the current date or a specific date |
|
151 | + * |
|
152 | + * @param string|DateTime $currentTime (optional) Relative calculation date |
|
153 | + * @param int $nth (optional) Number of matches to skip before returning |
|
154 | + * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
155 | + * current date if it matches the cron expression |
|
156 | + * |
|
157 | + * @return DateTime |
|
158 | + * @throws RuntimeException on too many iterations |
|
159 | + * @see CronExpression::getNextRunDate |
|
160 | + */ |
|
161 | + public function getPreviousRunDate( $currentTime = 'now', $nth = 0, $allowCurrentDate = false ) { |
|
162 | + return $this->getRunDate( $currentTime, $nth, true, $allowCurrentDate ); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Get multiple run dates starting at the current date or a specific date |
|
167 | + * |
|
168 | + * @param int $total Set the total number of dates to calculate |
|
169 | + * @param string|DateTime $currentTime (optional) Relative calculation date |
|
170 | + * @param bool $invert (optional) Set to TRUE to retrieve previous dates |
|
171 | + * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
172 | + * current date if it matches the cron expression |
|
173 | + * |
|
174 | + * @return array Returns an array of run dates |
|
175 | + */ |
|
176 | + public function getMultipleRunDates( $total, $currentTime = 'now', $invert = false, $allowCurrentDate = false ) { |
|
177 | + $matches = array(); |
|
178 | + for ( $i = 0; $i < max( 0, $total ); $i++ ) { |
|
179 | + $matches[] = $this->getRunDate( $currentTime, $i, $invert, $allowCurrentDate ); |
|
180 | + } |
|
181 | + |
|
182 | + return $matches; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Get all or part of the CRON expression |
|
187 | + * |
|
188 | + * @param string $part (optional) Specify the part to retrieve or NULL to |
|
189 | + * get the full cron schedule string. |
|
190 | + * |
|
191 | + * @return string|null Returns the CRON expression, a part of the |
|
192 | + * CRON expression, or NULL if the part was specified but not found |
|
193 | + */ |
|
194 | + public function getExpression( $part = null ) { |
|
195 | + if ( null === $part ) { |
|
196 | + return implode( ' ', $this->cronParts ); |
|
197 | + } elseif ( array_key_exists( $part, $this->cronParts ) ) { |
|
198 | + return $this->cronParts[ $part ]; |
|
199 | + } |
|
200 | + |
|
201 | + return null; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Helper method to output the full expression. |
|
206 | + * |
|
207 | + * @return string Full CRON expression |
|
208 | + */ |
|
209 | + public function __toString() { |
|
210 | + return $this->getExpression(); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Determine if the cron is due to run based on the current date or a |
|
215 | + * specific date. This method assumes that the current number of |
|
216 | + * seconds are irrelevant, and should be called once per minute. |
|
217 | + * |
|
218 | + * @param string|DateTime $currentTime (optional) Relative calculation date |
|
219 | + * |
|
220 | + * @return bool Returns TRUE if the cron is due to run or FALSE if not |
|
221 | + */ |
|
222 | + public function isDue( $currentTime = 'now' ) { |
|
223 | + if ( 'now' === $currentTime ) { |
|
224 | + $currentDate = date( 'Y-m-d H:i' ); |
|
225 | + $currentTime = strtotime( $currentDate ); |
|
226 | + } elseif ( $currentTime instanceof DateTime ) { |
|
227 | + $currentDate = $currentTime->format( 'Y-m-d H:i' ); |
|
228 | + $currentTime = strtotime( $currentDate ); |
|
229 | + } else { |
|
230 | + $currentTime = new DateTime( $currentTime ); |
|
231 | + $currentTime->setTime( $currentTime->format( 'H' ), $currentTime->format( 'i' ), 0 ); |
|
232 | + $currentDate = $currentTime->format( 'Y-m-d H:i' ); |
|
233 | + $currentTime = (int) ( $currentTime->getTimestamp() ); |
|
234 | + } |
|
235 | + |
|
236 | + return $this->getNextRunDate( $currentDate, 0, true )->getTimestamp() == $currentTime; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Get the next or previous run date of the expression relative to a date |
|
241 | + * |
|
242 | + * @param string|DateTime $currentTime (optional) Relative calculation date |
|
243 | + * @param int $nth (optional) Number of matches to skip before returning |
|
244 | + * @param bool $invert (optional) Set to TRUE to go backwards in time |
|
245 | + * @param bool $allowCurrentDate (optional) Set to TRUE to return the |
|
246 | + * current date if it matches the cron expression |
|
247 | + * |
|
248 | + * @return DateTime |
|
249 | + * @throws RuntimeException on too many iterations |
|
250 | + */ |
|
251 | + protected function getRunDate( $currentTime = null, $nth = 0, $invert = false, $allowCurrentDate = false ) { |
|
252 | + if ( $currentTime instanceof DateTime ) { |
|
253 | + $currentDate = $currentTime; |
|
254 | + } else { |
|
255 | + $currentDate = new DateTime( $currentTime ? $currentTime : 'now' ); |
|
256 | + $currentDate->setTimezone( new DateTimeZone( date_default_timezone_get() ) ); |
|
257 | + } |
|
258 | + |
|
259 | + $currentDate->setTime( $currentDate->format( 'H' ), $currentDate->format( 'i' ), 0 ); |
|
260 | + $nextRun = clone $currentDate; |
|
261 | + $nth = (int) $nth; |
|
262 | + |
|
263 | + // Set a hard limit to bail on an impossible date |
|
264 | + for ( $i = 0; $i < 1000; $i++ ) { |
|
265 | + |
|
266 | + foreach ( self::$order as $position ) { |
|
267 | + $part = $this->getExpression( $position ); |
|
268 | + if ( null === $part ) { |
|
269 | + continue; |
|
270 | + } |
|
271 | + |
|
272 | + $satisfied = false; |
|
273 | + // Get the field object used to validate this part |
|
274 | + $field = $this->fieldFactory->getField( $position ); |
|
275 | + // Check if this is singular or a list |
|
276 | + if ( strpos( $part, ',' ) === false ) { |
|
277 | + $satisfied = $field->isSatisfiedBy( $nextRun, $part ); |
|
278 | + } else { |
|
279 | + foreach ( array_map( 'trim', explode( ',', $part ) ) as $listPart ) { |
|
280 | + if ( $field->isSatisfiedBy( $nextRun, $listPart ) ) { |
|
281 | + $satisfied = true; |
|
282 | + break; |
|
283 | + } |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + // If the field is not satisfied, then start over |
|
288 | + if ( ! $satisfied ) { |
|
289 | + $field->increment( $nextRun, $invert ); |
|
290 | + continue 2; |
|
291 | + } |
|
292 | + } |
|
293 | + |
|
294 | + // Skip this match if needed |
|
295 | + if ( ( ! $allowCurrentDate && $nextRun == $currentDate ) || --$nth > -1 ) { |
|
296 | + $this->fieldFactory->getField( 0 )->increment( $nextRun, $invert ); |
|
297 | + continue; |
|
298 | + } |
|
299 | + |
|
300 | + return $nextRun; |
|
301 | + } |
|
302 | + |
|
303 | + // @codeCoverageIgnoreStart |
|
304 | + throw new RuntimeException( 'Impossible CRON expression' ); |
|
305 | + // @codeCoverageIgnoreEnd |
|
306 | + } |
|
307 | 307 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @var array Order in which to test of cron parts |
37 | 37 | */ |
38 | - private static $order = array( self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE ); |
|
38 | + private static $order = array(self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE); |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Factory method to create a new CronExpression. |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return CronExpression |
56 | 56 | */ |
57 | - public static function factory( $expression, CronExpression_FieldFactory $fieldFactory = null ) { |
|
57 | + public static function factory($expression, CronExpression_FieldFactory $fieldFactory = null) { |
|
58 | 58 | $mappings = array( |
59 | 59 | '@yearly' => '0 0 1 1 *', |
60 | 60 | '@annually' => '0 0 1 1 *', |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | '@hourly' => '0 * * * *', |
65 | 65 | ); |
66 | 66 | |
67 | - if ( isset( $mappings[ $expression ] ) ) { |
|
68 | - $expression = $mappings[ $expression ]; |
|
67 | + if (isset($mappings[$expression])) { |
|
68 | + $expression = $mappings[$expression]; |
|
69 | 69 | } |
70 | 70 | |
71 | - return new self( $expression, $fieldFactory ? $fieldFactory : new CronExpression_FieldFactory() ); |
|
71 | + return new self($expression, $fieldFactory ? $fieldFactory : new CronExpression_FieldFactory()); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | * @param string $expression CRON expression (e.g. '8 * * * *') |
78 | 78 | * @param CronExpression_FieldFactory $fieldFactory Factory to create cron fields |
79 | 79 | */ |
80 | - public function __construct( $expression, CronExpression_FieldFactory $fieldFactory ) { |
|
80 | + public function __construct($expression, CronExpression_FieldFactory $fieldFactory) { |
|
81 | 81 | $this->fieldFactory = $fieldFactory; |
82 | - $this->setExpression( $expression ); |
|
82 | + $this->setExpression($expression); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -90,16 +90,16 @@ discard block |
||
90 | 90 | * @return CronExpression |
91 | 91 | * @throws InvalidArgumentException if not a valid CRON expression |
92 | 92 | */ |
93 | - public function setExpression( $value ) { |
|
94 | - $this->cronParts = preg_split( '/\s/', $value, -1, PREG_SPLIT_NO_EMPTY ); |
|
95 | - if ( count( $this->cronParts ) < 5 ) { |
|
93 | + public function setExpression($value) { |
|
94 | + $this->cronParts = preg_split('/\s/', $value, -1, PREG_SPLIT_NO_EMPTY); |
|
95 | + if (count($this->cronParts) < 5) { |
|
96 | 96 | throw new InvalidArgumentException( |
97 | - $value . ' is not a valid CRON expression' |
|
97 | + $value.' is not a valid CRON expression' |
|
98 | 98 | ); |
99 | 99 | } |
100 | 100 | |
101 | - foreach ( $this->cronParts as $position => $part ) { |
|
102 | - $this->setPart( $position, $part ); |
|
101 | + foreach ($this->cronParts as $position => $part) { |
|
102 | + $this->setPart($position, $part); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return $this; |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | * @return CronExpression |
115 | 115 | * @throws InvalidArgumentException if the value is not valid for the part |
116 | 116 | */ |
117 | - public function setPart( $position, $value ) { |
|
118 | - if ( ! $this->fieldFactory->getField( $position )->validate( $value ) ) { |
|
117 | + public function setPart($position, $value) { |
|
118 | + if ( ! $this->fieldFactory->getField($position)->validate($value)) { |
|
119 | 119 | throw new InvalidArgumentException( |
120 | - 'Invalid CRON field value ' . $value . ' as position ' . $position |
|
120 | + 'Invalid CRON field value '.$value.' as position '.$position |
|
121 | 121 | ); |
122 | 122 | } |
123 | 123 | |
124 | - $this->cronParts[ $position ] = $value; |
|
124 | + $this->cronParts[$position] = $value; |
|
125 | 125 | |
126 | 126 | return $this; |
127 | 127 | } |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | * @return DateTime |
143 | 143 | * @throws RuntimeException on too many iterations |
144 | 144 | */ |
145 | - public function getNextRunDate( $currentTime = 'now', $nth = 0, $allowCurrentDate = false ) { |
|
146 | - return $this->getRunDate( $currentTime, $nth, false, $allowCurrentDate ); |
|
145 | + public function getNextRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false) { |
|
146 | + return $this->getRunDate($currentTime, $nth, false, $allowCurrentDate); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @throws RuntimeException on too many iterations |
159 | 159 | * @see CronExpression::getNextRunDate |
160 | 160 | */ |
161 | - public function getPreviousRunDate( $currentTime = 'now', $nth = 0, $allowCurrentDate = false ) { |
|
162 | - return $this->getRunDate( $currentTime, $nth, true, $allowCurrentDate ); |
|
161 | + public function getPreviousRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false) { |
|
162 | + return $this->getRunDate($currentTime, $nth, true, $allowCurrentDate); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -173,10 +173,10 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return array Returns an array of run dates |
175 | 175 | */ |
176 | - public function getMultipleRunDates( $total, $currentTime = 'now', $invert = false, $allowCurrentDate = false ) { |
|
176 | + public function getMultipleRunDates($total, $currentTime = 'now', $invert = false, $allowCurrentDate = false) { |
|
177 | 177 | $matches = array(); |
178 | - for ( $i = 0; $i < max( 0, $total ); $i++ ) { |
|
179 | - $matches[] = $this->getRunDate( $currentTime, $i, $invert, $allowCurrentDate ); |
|
178 | + for ($i = 0; $i < max(0, $total); $i++) { |
|
179 | + $matches[] = $this->getRunDate($currentTime, $i, $invert, $allowCurrentDate); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | return $matches; |
@@ -191,11 +191,11 @@ discard block |
||
191 | 191 | * @return string|null Returns the CRON expression, a part of the |
192 | 192 | * CRON expression, or NULL if the part was specified but not found |
193 | 193 | */ |
194 | - public function getExpression( $part = null ) { |
|
195 | - if ( null === $part ) { |
|
196 | - return implode( ' ', $this->cronParts ); |
|
197 | - } elseif ( array_key_exists( $part, $this->cronParts ) ) { |
|
198 | - return $this->cronParts[ $part ]; |
|
194 | + public function getExpression($part = null) { |
|
195 | + if (null === $part) { |
|
196 | + return implode(' ', $this->cronParts); |
|
197 | + } elseif (array_key_exists($part, $this->cronParts)) { |
|
198 | + return $this->cronParts[$part]; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | return null; |
@@ -219,21 +219,21 @@ discard block |
||
219 | 219 | * |
220 | 220 | * @return bool Returns TRUE if the cron is due to run or FALSE if not |
221 | 221 | */ |
222 | - public function isDue( $currentTime = 'now' ) { |
|
223 | - if ( 'now' === $currentTime ) { |
|
224 | - $currentDate = date( 'Y-m-d H:i' ); |
|
225 | - $currentTime = strtotime( $currentDate ); |
|
226 | - } elseif ( $currentTime instanceof DateTime ) { |
|
227 | - $currentDate = $currentTime->format( 'Y-m-d H:i' ); |
|
228 | - $currentTime = strtotime( $currentDate ); |
|
222 | + public function isDue($currentTime = 'now') { |
|
223 | + if ('now' === $currentTime) { |
|
224 | + $currentDate = date('Y-m-d H:i'); |
|
225 | + $currentTime = strtotime($currentDate); |
|
226 | + } elseif ($currentTime instanceof DateTime) { |
|
227 | + $currentDate = $currentTime->format('Y-m-d H:i'); |
|
228 | + $currentTime = strtotime($currentDate); |
|
229 | 229 | } else { |
230 | - $currentTime = new DateTime( $currentTime ); |
|
231 | - $currentTime->setTime( $currentTime->format( 'H' ), $currentTime->format( 'i' ), 0 ); |
|
232 | - $currentDate = $currentTime->format( 'Y-m-d H:i' ); |
|
233 | - $currentTime = (int) ( $currentTime->getTimestamp() ); |
|
230 | + $currentTime = new DateTime($currentTime); |
|
231 | + $currentTime->setTime($currentTime->format('H'), $currentTime->format('i'), 0); |
|
232 | + $currentDate = $currentTime->format('Y-m-d H:i'); |
|
233 | + $currentTime = (int) ($currentTime->getTimestamp()); |
|
234 | 234 | } |
235 | 235 | |
236 | - return $this->getNextRunDate( $currentDate, 0, true )->getTimestamp() == $currentTime; |
|
236 | + return $this->getNextRunDate($currentDate, 0, true)->getTimestamp() == $currentTime; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -248,36 +248,36 @@ discard block |
||
248 | 248 | * @return DateTime |
249 | 249 | * @throws RuntimeException on too many iterations |
250 | 250 | */ |
251 | - protected function getRunDate( $currentTime = null, $nth = 0, $invert = false, $allowCurrentDate = false ) { |
|
252 | - if ( $currentTime instanceof DateTime ) { |
|
251 | + protected function getRunDate($currentTime = null, $nth = 0, $invert = false, $allowCurrentDate = false) { |
|
252 | + if ($currentTime instanceof DateTime) { |
|
253 | 253 | $currentDate = $currentTime; |
254 | 254 | } else { |
255 | - $currentDate = new DateTime( $currentTime ? $currentTime : 'now' ); |
|
256 | - $currentDate->setTimezone( new DateTimeZone( date_default_timezone_get() ) ); |
|
255 | + $currentDate = new DateTime($currentTime ? $currentTime : 'now'); |
|
256 | + $currentDate->setTimezone(new DateTimeZone(date_default_timezone_get())); |
|
257 | 257 | } |
258 | 258 | |
259 | - $currentDate->setTime( $currentDate->format( 'H' ), $currentDate->format( 'i' ), 0 ); |
|
259 | + $currentDate->setTime($currentDate->format('H'), $currentDate->format('i'), 0); |
|
260 | 260 | $nextRun = clone $currentDate; |
261 | 261 | $nth = (int) $nth; |
262 | 262 | |
263 | 263 | // Set a hard limit to bail on an impossible date |
264 | - for ( $i = 0; $i < 1000; $i++ ) { |
|
264 | + for ($i = 0; $i < 1000; $i++) { |
|
265 | 265 | |
266 | - foreach ( self::$order as $position ) { |
|
267 | - $part = $this->getExpression( $position ); |
|
268 | - if ( null === $part ) { |
|
266 | + foreach (self::$order as $position) { |
|
267 | + $part = $this->getExpression($position); |
|
268 | + if (null === $part) { |
|
269 | 269 | continue; |
270 | 270 | } |
271 | 271 | |
272 | 272 | $satisfied = false; |
273 | 273 | // Get the field object used to validate this part |
274 | - $field = $this->fieldFactory->getField( $position ); |
|
274 | + $field = $this->fieldFactory->getField($position); |
|
275 | 275 | // Check if this is singular or a list |
276 | - if ( strpos( $part, ',' ) === false ) { |
|
277 | - $satisfied = $field->isSatisfiedBy( $nextRun, $part ); |
|
276 | + if (strpos($part, ',') === false) { |
|
277 | + $satisfied = $field->isSatisfiedBy($nextRun, $part); |
|
278 | 278 | } else { |
279 | - foreach ( array_map( 'trim', explode( ',', $part ) ) as $listPart ) { |
|
280 | - if ( $field->isSatisfiedBy( $nextRun, $listPart ) ) { |
|
279 | + foreach (array_map('trim', explode(',', $part)) as $listPart) { |
|
280 | + if ($field->isSatisfiedBy($nextRun, $listPart)) { |
|
281 | 281 | $satisfied = true; |
282 | 282 | break; |
283 | 283 | } |
@@ -285,15 +285,15 @@ discard block |
||
285 | 285 | } |
286 | 286 | |
287 | 287 | // If the field is not satisfied, then start over |
288 | - if ( ! $satisfied ) { |
|
289 | - $field->increment( $nextRun, $invert ); |
|
288 | + if ( ! $satisfied) { |
|
289 | + $field->increment($nextRun, $invert); |
|
290 | 290 | continue 2; |
291 | 291 | } |
292 | 292 | } |
293 | 293 | |
294 | 294 | // Skip this match if needed |
295 | - if ( ( ! $allowCurrentDate && $nextRun == $currentDate ) || --$nth > -1 ) { |
|
296 | - $this->fieldFactory->getField( 0 )->increment( $nextRun, $invert ); |
|
295 | + if (( ! $allowCurrentDate && $nextRun == $currentDate) || --$nth > -1) { |
|
296 | + $this->fieldFactory->getField(0)->increment($nextRun, $invert); |
|
297 | 297 | continue; |
298 | 298 | } |
299 | 299 | |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | } |
302 | 302 | |
303 | 303 | // @codeCoverageIgnoreStart |
304 | - throw new RuntimeException( 'Impossible CRON expression' ); |
|
304 | + throw new RuntimeException('Impossible CRON expression'); |
|
305 | 305 | // @codeCoverageIgnoreEnd |
306 | 306 | } |
307 | 307 | } |
@@ -28,40 +28,40 @@ |
||
28 | 28 | |
29 | 29 | if ( ! function_exists( 'action_scheduler_register_3_dot_5_dot_3' ) && function_exists( 'add_action' ) ) { // WRCS: DEFINED_VERSION. |
30 | 30 | |
31 | - if ( ! class_exists( 'ActionScheduler_Versions', false ) ) { |
|
32 | - require_once __DIR__ . '/classes/ActionScheduler_Versions.php'; |
|
33 | - add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 ); |
|
34 | - } |
|
31 | + if ( ! class_exists( 'ActionScheduler_Versions', false ) ) { |
|
32 | + require_once __DIR__ . '/classes/ActionScheduler_Versions.php'; |
|
33 | + add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 ); |
|
34 | + } |
|
35 | 35 | |
36 | - add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_5_dot_3', 0, 0 ); // WRCS: DEFINED_VERSION. |
|
36 | + add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_5_dot_3', 0, 0 ); // WRCS: DEFINED_VERSION. |
|
37 | 37 | |
38 | - /** |
|
39 | - * Registers this version of Action Scheduler. |
|
40 | - */ |
|
41 | - function action_scheduler_register_3_dot_5_dot_3() { |
|
42 | - // WRCS: DEFINED_VERSION. |
|
43 | - $versions = ActionScheduler_Versions::instance(); |
|
44 | - $versions->register( '3.5.3', 'action_scheduler_initialize_3_dot_5_dot_3' ); // WRCS: DEFINED_VERSION. |
|
45 | - } |
|
38 | + /** |
|
39 | + * Registers this version of Action Scheduler. |
|
40 | + */ |
|
41 | + function action_scheduler_register_3_dot_5_dot_3() { |
|
42 | + // WRCS: DEFINED_VERSION. |
|
43 | + $versions = ActionScheduler_Versions::instance(); |
|
44 | + $versions->register( '3.5.3', 'action_scheduler_initialize_3_dot_5_dot_3' ); // WRCS: DEFINED_VERSION. |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Initializes this version of Action Scheduler. |
|
49 | - */ |
|
50 | - function action_scheduler_initialize_3_dot_5_dot_3() { |
|
51 | - // WRCS: DEFINED_VERSION. |
|
52 | - // A final safety check is required even here, because historic versions of Action Scheduler |
|
53 | - // followed a different pattern (in some unusual cases, we could reach this point and the |
|
54 | - // ActionScheduler class is already defined—so we need to guard against that). |
|
55 | - if ( ! class_exists( 'ActionScheduler', false ) ) { |
|
56 | - require_once __DIR__ . '/classes/abstracts/ActionScheduler.php'; |
|
57 | - ActionScheduler::init( __FILE__ ); |
|
58 | - } |
|
59 | - } |
|
47 | + /** |
|
48 | + * Initializes this version of Action Scheduler. |
|
49 | + */ |
|
50 | + function action_scheduler_initialize_3_dot_5_dot_3() { |
|
51 | + // WRCS: DEFINED_VERSION. |
|
52 | + // A final safety check is required even here, because historic versions of Action Scheduler |
|
53 | + // followed a different pattern (in some unusual cases, we could reach this point and the |
|
54 | + // ActionScheduler class is already defined—so we need to guard against that). |
|
55 | + if ( ! class_exists( 'ActionScheduler', false ) ) { |
|
56 | + require_once __DIR__ . '/classes/abstracts/ActionScheduler.php'; |
|
57 | + ActionScheduler::init( __FILE__ ); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - // Support usage in themes - load this version if no plugin has loaded a version yet. |
|
62 | - if ( did_action( 'plugins_loaded' ) && ! doing_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler', false ) ) { |
|
63 | - action_scheduler_initialize_3_dot_5_dot_3(); // WRCS: DEFINED_VERSION. |
|
64 | - do_action( 'action_scheduler_pre_theme_init' ); |
|
65 | - ActionScheduler_Versions::initialize_latest_version(); |
|
66 | - } |
|
61 | + // Support usage in themes - load this version if no plugin has loaded a version yet. |
|
62 | + if ( did_action( 'plugins_loaded' ) && ! doing_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler', false ) ) { |
|
63 | + action_scheduler_initialize_3_dot_5_dot_3(); // WRCS: DEFINED_VERSION. |
|
64 | + do_action( 'action_scheduler_pre_theme_init' ); |
|
65 | + ActionScheduler_Versions::initialize_latest_version(); |
|
66 | + } |
|
67 | 67 | } |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | * @package ActionScheduler |
27 | 27 | */ |
28 | 28 | |
29 | -if ( ! function_exists( 'action_scheduler_register_3_dot_5_dot_3' ) && function_exists( 'add_action' ) ) { // WRCS: DEFINED_VERSION. |
|
29 | +if ( ! function_exists('action_scheduler_register_3_dot_5_dot_3') && function_exists('add_action')) { // WRCS: DEFINED_VERSION. |
|
30 | 30 | |
31 | - if ( ! class_exists( 'ActionScheduler_Versions', false ) ) { |
|
32 | - require_once __DIR__ . '/classes/ActionScheduler_Versions.php'; |
|
33 | - add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 ); |
|
31 | + if ( ! class_exists('ActionScheduler_Versions', false)) { |
|
32 | + require_once __DIR__.'/classes/ActionScheduler_Versions.php'; |
|
33 | + add_action('plugins_loaded', array('ActionScheduler_Versions', 'initialize_latest_version'), 1, 0); |
|
34 | 34 | } |
35 | 35 | |
36 | - add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_5_dot_3', 0, 0 ); // WRCS: DEFINED_VERSION. |
|
36 | + add_action('plugins_loaded', 'action_scheduler_register_3_dot_5_dot_3', 0, 0); // WRCS: DEFINED_VERSION. |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Registers this version of Action Scheduler. |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | function action_scheduler_register_3_dot_5_dot_3() { |
42 | 42 | // WRCS: DEFINED_VERSION. |
43 | 43 | $versions = ActionScheduler_Versions::instance(); |
44 | - $versions->register( '3.5.3', 'action_scheduler_initialize_3_dot_5_dot_3' ); // WRCS: DEFINED_VERSION. |
|
44 | + $versions->register('3.5.3', 'action_scheduler_initialize_3_dot_5_dot_3'); // WRCS: DEFINED_VERSION. |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -52,16 +52,16 @@ discard block |
||
52 | 52 | // A final safety check is required even here, because historic versions of Action Scheduler |
53 | 53 | // followed a different pattern (in some unusual cases, we could reach this point and the |
54 | 54 | // ActionScheduler class is already defined—so we need to guard against that). |
55 | - if ( ! class_exists( 'ActionScheduler', false ) ) { |
|
56 | - require_once __DIR__ . '/classes/abstracts/ActionScheduler.php'; |
|
57 | - ActionScheduler::init( __FILE__ ); |
|
55 | + if ( ! class_exists('ActionScheduler', false)) { |
|
56 | + require_once __DIR__.'/classes/abstracts/ActionScheduler.php'; |
|
57 | + ActionScheduler::init(__FILE__); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | 61 | // Support usage in themes - load this version if no plugin has loaded a version yet. |
62 | - if ( did_action( 'plugins_loaded' ) && ! doing_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler', false ) ) { |
|
62 | + if (did_action('plugins_loaded') && ! doing_action('plugins_loaded') && ! class_exists('ActionScheduler', false)) { |
|
63 | 63 | action_scheduler_initialize_3_dot_5_dot_3(); // WRCS: DEFINED_VERSION. |
64 | - do_action( 'action_scheduler_pre_theme_init' ); |
|
64 | + do_action('action_scheduler_pre_theme_init'); |
|
65 | 65 | ActionScheduler_Versions::initialize_latest_version(); |
66 | 66 | } |
67 | 67 | } |
@@ -32,27 +32,27 @@ discard block |
||
32 | 32 | use Wordlift\Post\Post_Adapter; |
33 | 33 | |
34 | 34 | // If this file is called directly, abort. |
35 | -if ( ! defined( 'WPINC' ) ) { |
|
35 | +if ( ! defined('WPINC')) { |
|
36 | 36 | die; |
37 | 37 | } |
38 | 38 | |
39 | -define( 'WORDLIFT_VERSION', '3.40.2' ); |
|
39 | +define('WORDLIFT_VERSION', '3.40.2'); |
|
40 | 40 | |
41 | -require_once __DIR__ . '/modules/common/load.php'; |
|
42 | -require_once __DIR__ . '/modules/include-exclude/load.php'; |
|
41 | +require_once __DIR__.'/modules/common/load.php'; |
|
42 | +require_once __DIR__.'/modules/include-exclude/load.php'; |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * Filter to disable WLP on any request, defaults to true. |
46 | 46 | * |
47 | 47 | * @since 3.33.6 |
48 | 48 | */ |
49 | -if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
|
49 | +if ( ! apply_filters('wl_is_enabled', true)) { |
|
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
53 | -require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
|
53 | +require_once plugin_dir_path(__FILE__).'vendor/autoload.php'; |
|
54 | 54 | // Action Scheduler. |
55 | -require_once plugin_dir_path( __FILE__ ) . '/ext/action-scheduler/action-scheduler.php'; |
|
55 | +require_once plugin_dir_path(__FILE__).'/ext/action-scheduler/action-scheduler.php'; |
|
56 | 56 | |
57 | 57 | /* |
58 | 58 | * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http. |
@@ -62,15 +62,15 @@ discard block |
||
62 | 62 | wordlift_plugin_autoload_register(); |
63 | 63 | |
64 | 64 | // Include WordLift constants. |
65 | -require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php'; |
|
65 | +require_once plugin_dir_path(__FILE__).'wordlift-constants.php'; |
|
66 | 66 | |
67 | 67 | // Load modules. |
68 | -require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php'; |
|
68 | +require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php'; |
|
69 | 69 | |
70 | -require_once plugin_dir_path( __FILE__ ) . 'deprecations.php'; |
|
70 | +require_once plugin_dir_path(__FILE__).'deprecations.php'; |
|
71 | 71 | |
72 | 72 | // Load early to enable/disable features. |
73 | -require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php'; |
|
73 | +require_once plugin_dir_path(__FILE__).'wordlift/features/index.php'; |
|
74 | 74 | |
75 | 75 | /** |
76 | 76 | * The code that runs during plugin activation. |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | */ |
79 | 79 | function activate_wordlift() { |
80 | 80 | |
81 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
81 | + $log = Wordlift_Log_Service::get_logger('activate_wordlift'); |
|
82 | 82 | |
83 | - $log->info( 'Activating WordLift...' ); |
|
83 | + $log->info('Activating WordLift...'); |
|
84 | 84 | |
85 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
85 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
86 | 86 | Wordlift_Activator::activate(); |
87 | 87 | |
88 | 88 | /** |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | */ |
103 | 103 | Top_Entities::activate(); |
104 | 104 | |
105 | - if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
106 | - wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
105 | + if ( ! wp_next_scheduled('wl_daily_cron')) { |
|
106 | + wp_schedule_event(time(), 'daily', 'wl_daily_cron'); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | function deactivate_wordlift() { |
116 | 116 | |
117 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
117 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
118 | 118 | Wordlift_Deactivator::deactivate(); |
119 | 119 | Wordlift_Http_Api::deactivate(); |
120 | 120 | Ttl_Cache_Cleaner::deactivate(); |
@@ -130,18 +130,18 @@ discard block |
||
130 | 130 | Key_Validation_Notice::remove_notification_flag(); |
131 | 131 | flush_rewrite_rules(); |
132 | 132 | |
133 | - wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
133 | + wp_clear_scheduled_hook('wl_daily_cron'); |
|
134 | 134 | |
135 | 135 | } |
136 | 136 | |
137 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
138 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
137 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
138 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
139 | 139 | |
140 | 140 | /** |
141 | 141 | * The core plugin class that is used to define internationalization, |
142 | 142 | * admin-specific hooks, and public-facing site hooks. |
143 | 143 | */ |
144 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
144 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
145 | 145 | |
146 | 146 | /** |
147 | 147 | * Begins execution of the plugin. |
@@ -161,12 +161,12 @@ discard block |
||
161 | 161 | * @return bool |
162 | 162 | * @since 3.27.6 |
163 | 163 | */ |
164 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
165 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
166 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
167 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
164 | + if (apply_filters('wl_feature__enable__widgets', true)) { |
|
165 | + add_action('widgets_init', 'wl_register_chord_widget'); |
|
166 | + add_action('widgets_init', 'wl_register_geo_widget'); |
|
167 | + add_action('widgets_init', 'wl_register_timeline_widget'); |
|
168 | 168 | } |
169 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
169 | + add_filter('widget_text', 'do_shortcode'); |
|
170 | 170 | |
171 | 171 | /** |
172 | 172 | * Filter: wl_feature__enable__analysis |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | * @return bool |
177 | 177 | * @since 3.27.6 |
178 | 178 | */ |
179 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
180 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
179 | + if (apply_filters('wl_feature__enable__analysis', true)) { |
|
180 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action'); |
|
181 | 181 | } else { |
182 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
182 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action'); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | $plugin = new Wordlift(); |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | |
197 | 197 | add_action( |
198 | 198 | 'plugins_loaded', |
199 | - function () { |
|
199 | + function() { |
|
200 | 200 | // All features from registry should be initialized here. |
201 | 201 | $features_registry = Features_Registry::get_instance(); |
202 | 202 | $features_registry->initialize_all_features(); |
@@ -207,27 +207,27 @@ discard block |
||
207 | 207 | add_action( |
208 | 208 | 'plugins_loaded', |
209 | 209 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
210 | - function () use ( $plugin ) { |
|
210 | + function() use ($plugin) { |
|
211 | 211 | |
212 | 212 | new Wordlift_Products_Navigator_Shortcode_REST(); |
213 | 213 | |
214 | 214 | // Register the Dataset module, requires `$api_service`. |
215 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
216 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
215 | + require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php'; |
|
216 | + require_once plugin_dir_path(__FILE__).'wordlift/shipping-data/index.php'; |
|
217 | 217 | |
218 | 218 | /* |
219 | 219 | * Require the Entity annotation cleanup module. |
220 | 220 | * |
221 | 221 | * @since 3.34.6 |
222 | 222 | */ |
223 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
223 | + require_once plugin_dir_path(__FILE__).'wordlift/cleanup/index.php'; |
|
224 | 224 | |
225 | 225 | /* |
226 | 226 | * Import LOD entities. |
227 | 227 | * |
228 | 228 | * @since 3.35.0 |
229 | 229 | */ |
230 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
230 | + require_once plugin_dir_path(__FILE__).'wordlift/lod-import/index.php'; |
|
231 | 231 | |
232 | 232 | } |
233 | 233 | ); |
@@ -245,23 +245,23 @@ discard block |
||
245 | 245 | function wordlift_plugin_autoload_register() { |
246 | 246 | |
247 | 247 | spl_autoload_register( |
248 | - function ( $class_name ) { |
|
248 | + function($class_name) { |
|
249 | 249 | |
250 | 250 | // Bail out if these are not our classes. |
251 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
251 | + if (0 !== strpos($class_name, 'Wordlift\\')) { |
|
252 | 252 | return false; |
253 | 253 | } |
254 | 254 | |
255 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
255 | + $class_name_lc = strtolower(str_replace('_', '-', $class_name)); |
|
256 | 256 | |
257 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
257 | + preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches); |
|
258 | 258 | |
259 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
260 | - $file = 'class-' . $matches[2] . '.php'; |
|
259 | + $path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]); |
|
260 | + $file = 'class-'.$matches[2].'.php'; |
|
261 | 261 | |
262 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
262 | + $full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file; |
|
263 | 263 | |
264 | - if ( ! file_exists( $full_path ) ) { |
|
264 | + if ( ! file_exists($full_path)) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | |
274 | 274 | } |
275 | 275 | |
276 | -function wl_block_categories( $categories ) { |
|
276 | +function wl_block_categories($categories) { |
|
277 | 277 | return array_merge( |
278 | 278 | $categories, |
279 | 279 | array( |
280 | 280 | array( |
281 | 281 | 'slug' => 'wordlift', |
282 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
282 | + 'title' => __('WordLift', 'wordlift'), |
|
283 | 283 | ), |
284 | 284 | ) |
285 | 285 | ); |
@@ -289,23 +289,23 @@ discard block |
||
289 | 289 | * This function is created temporarily to handle the legacy library, |
290 | 290 | * this has to be removed when removing the legacy fields from the ui. |
291 | 291 | */ |
292 | -function wl_enqueue_leaflet( $in_footer = false ) { |
|
292 | +function wl_enqueue_leaflet($in_footer = false) { |
|
293 | 293 | // Leaflet. |
294 | - wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
295 | - wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
294 | + wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0'); |
|
295 | + wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer); |
|
296 | 296 | } |
297 | 297 | |
298 | -add_filter( 'block_categories', 'wl_block_categories', 10 ); |
|
298 | +add_filter('block_categories', 'wl_block_categories', 10); |
|
299 | 299 | |
300 | 300 | // Temporary fix for a typo in WooCommerce Extension. |
301 | 301 | add_filter( |
302 | 302 | 'wl_feature__enable__dataset', |
303 | - function ( $value ) { |
|
304 | - return apply_filters( 'wl_features__enable__dataset', $value ); |
|
303 | + function($value) { |
|
304 | + return apply_filters('wl_features__enable__dataset', $value); |
|
305 | 305 | } |
306 | 306 | ); |
307 | 307 | |
308 | -require_once __DIR__ . '/modules/food-kg/load.php'; |
|
309 | -require_once __DIR__ . '/modules/acf4so/load.php'; |
|
310 | -require_once __DIR__ . '/modules/pods/load.php'; |
|
311 | -require_once __DIR__ . '/modules/include-exclude-push-config/load.php'; |
|
308 | +require_once __DIR__.'/modules/food-kg/load.php'; |
|
309 | +require_once __DIR__.'/modules/acf4so/load.php'; |
|
310 | +require_once __DIR__.'/modules/pods/load.php'; |
|
311 | +require_once __DIR__.'/modules/include-exclude-push-config/load.php'; |