updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -31,7 +31,9 @@ abstract class AbstractField implements FieldInterface
*/
protected $rangeEnd;
/**
* Constructor
*/
public function __construct()
{
$this->fullRange = range($this->rangeStart, $this->rangeEnd);
@@ -204,12 +206,18 @@ abstract class AbstractField implements FieldInterface
return $values;
}
/**
* Convert literal
*
* @param string $value
* @return string
*/
protected function convertLiterals($value)
{
if (count($this->literals)) {
$key = array_search($value, $this->literals);
if ($key !== false) {
return $key;
return (string) $key;
}
}

View File

@@ -4,6 +4,7 @@ namespace Cron;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
use Exception;
use InvalidArgumentException;
@@ -62,7 +63,7 @@ class CronExpression
* `@weekly` - Run once a week, midnight on Sun - 0 0 * * 0
* `@daily` - Run once a day, midnight - 0 0 * * *
* `@hourly` - Run once an hour, first minute - 0 * * * *
* @param FieldFactory $fieldFactory Field factory to use
* @param FieldFactory|null $fieldFactory Field factory to use
*
* @return CronExpression
*/
@@ -107,9 +108,9 @@ class CronExpression
* Parse a CRON expression
*
* @param string $expression CRON expression (e.g. '8 * * * *')
* @param FieldFactory $fieldFactory Factory to create cron fields
* @param FieldFactory|null $fieldFactory Factory to create cron fields
*/
public function __construct($expression, FieldFactory $fieldFactory)
public function __construct($expression, FieldFactory $fieldFactory = null)
{
$this->fieldFactory = $fieldFactory;
$this->setExpression($expression);
@@ -178,16 +179,17 @@ class CronExpression
/**
* Get a next run date relative to the current date or a specific date
*
* @param string|\DateTime $currentTime Relative calculation date
* @param int $nth Number of matches to skip before returning a
* matching next run date. 0, the default, will return the current
* date and time if the next run date falls on the current date and
* time. Setting this value to 1 will skip the first match and go to
* the second match. Setting this value to 2 will skip the first 2
* matches and so on.
* @param bool $allowCurrentDate Set to TRUE to return the current date if
* it matches the cron expression.
* @param null|string $timeZone TimeZone to use instead of the system default
* @param string|\DateTimeInterface $currentTime Relative calculation date
* @param int $nth Number of matches to skip before returning a
* matching next run date. 0, the default, will return the
* current date and time if the next run date falls on the
* current date and time. Setting this value to 1 will
* skip the first match and go to the second match.
* Setting this value to 2 will skip the first 2
* matches and so on.
* @param bool $allowCurrentDate Set to TRUE to return the current date if
* it matches the cron expression.
* @param null|string $timeZone TimeZone to use instead of the system default
*
* @return \DateTime
* @throws \RuntimeException on too many iterations
@@ -200,11 +202,11 @@ class CronExpression
/**
* Get a previous run date relative to the current date or a specific date
*
* @param string|\DateTime $currentTime Relative calculation date
* @param int $nth Number of matches to skip before returning
* @param bool $allowCurrentDate Set to TRUE to return the
* current date if it matches the cron expression
* @param null|string $timeZone TimeZone to use instead of the system default
* @param string|\DateTimeInterface $currentTime Relative calculation date
* @param int $nth Number of matches to skip before returning
* @param bool $allowCurrentDate Set to TRUE to return the
* current date if it matches the cron expression
* @param null|string $timeZone TimeZone to use instead of the system default
*
* @return \DateTime
* @throws \RuntimeException on too many iterations
@@ -218,14 +220,14 @@ class CronExpression
/**
* Get multiple run dates starting at the current date or a specific date
*
* @param int $total Set the total number of dates to calculate
* @param string|\DateTime $currentTime Relative calculation date
* @param bool $invert Set to TRUE to retrieve previous dates
* @param bool $allowCurrentDate Set to TRUE to return the
* current date if it matches the cron expression
* @param null|string $timeZone TimeZone to use instead of the system default
* @param int $total Set the total number of dates to calculate
* @param string|\DateTimeInterface $currentTime Relative calculation date
* @param bool $invert Set to TRUE to retrieve previous dates
* @param bool $allowCurrentDate Set to TRUE to return the
* current date if it matches the cron expression
* @param null|string $timeZone TimeZone to use instead of the system default
*
* @return array Returns an array of run dates
* @return \DateTime[] Returns an array of run dates
*/
public function getMultipleRunDates($total, $currentTime = 'now', $invert = false, $allowCurrentDate = false, $timeZone = null)
{
@@ -276,8 +278,8 @@ class CronExpression
* specific date. This method assumes that the current number of
* seconds are irrelevant, and should be called once per minute.
*
* @param string|\DateTime $currentTime Relative calculation date
* @param null|string $timeZone TimeZone to use instead of the system default
* @param string|\DateTimeInterface $currentTime Relative calculation date
* @param null|string $timeZone TimeZone to use instead of the system default
*
* @return bool Returns TRUE if the cron is due to run or FALSE if not
*/
@@ -309,12 +311,12 @@ class CronExpression
/**
* Get the next or previous run date of the expression relative to a date
*
* @param string|\DateTime $currentTime Relative calculation date
* @param int $nth Number of matches to skip before returning
* @param bool $invert Set to TRUE to go backwards in time
* @param bool $allowCurrentDate Set to TRUE to return the
* current date if it matches the cron expression
* @param string|null $timeZone TimeZone to use instead of the system default
* @param string|\DateTimeInterface $currentTime Relative calculation date
* @param int $nth Number of matches to skip before returning
* @param bool $invert Set to TRUE to go backwards in time
* @param bool $allowCurrentDate Set to TRUE to return the
* current date if it matches the cron expression
* @param string|null $timeZone TimeZone to use instead of the system default
*
* @return \DateTime
* @throws \RuntimeException on too many iterations
@@ -391,8 +393,8 @@ class CronExpression
/**
* Workout what timeZone should be used.
*
* @param string|\DateTime $currentTime Relative calculation date
* @param string|null $timeZone TimeZone to use instead of the system default
* @param string|\DateTimeInterface $currentTime Relative calculation date
* @param string|null $timeZone TimeZone to use instead of the system default
*
* @return string
*/
@@ -402,7 +404,7 @@ class CronExpression
return $timeZone;
}
if ($currentTime instanceOf Datetime) {
if ($currentTime instanceOf DateTimeInterface) {
return $currentTime->getTimeZone()->getName();
}

View File

@@ -3,6 +3,7 @@
namespace Cron;
use DateTime;
use DateTimeInterface;
/**
* Day of month field. Allows: * , / - ? L W
@@ -24,7 +25,14 @@ use DateTime;
*/
class DayOfMonthField extends AbstractField
{
/**
* @inheritDoc
*/
protected $rangeStart = 1;
/**
* @inheritDoc
*/
protected $rangeEnd = 31;
/**
@@ -59,7 +67,10 @@ class DayOfMonthField extends AbstractField
}
}
public function isSatisfiedBy(DateTime $date, $value)
/**
* @inheritDoc
*/
public function isSatisfiedBy(DateTimeInterface $date, $value)
{
// ? states that the field value is to be skipped
if ($value == '?') {
@@ -88,14 +99,17 @@ class DayOfMonthField extends AbstractField
return $this->isSatisfied($date->format('d'), $value);
}
public function increment(DateTime $date, $invert = false)
/**
* @inheritDoc
*
* @param \DateTime|\DateTimeImmutable &$date
*/
public function increment(DateTimeInterface &$date, $invert = false)
{
if ($invert) {
$date->modify('previous day');
$date->setTime(23, 59);
$date = $date->modify('previous day')->setTime(23, 59);
} else {
$date->modify('next day');
$date->setTime(0, 0);
$date = $date->modify('next day')->setTime(0, 0);
}
return $this;

View File

@@ -3,9 +3,9 @@
namespace Cron;
use DateTime;
use DateTimeInterface;
use InvalidArgumentException;
/**
* Day of week field. Allows: * / , - ? L #
*
@@ -21,20 +21,41 @@ use InvalidArgumentException;
*/
class DayOfWeekField extends AbstractField
{
/**
* @inheritDoc
*/
protected $rangeStart = 0;
/**
* @inheritDoc
*/
protected $rangeEnd = 7;
/**
* @var array Weekday range
*/
protected $nthRange;
/**
* @inheritDoc
*/
protected $literals = [1 => 'MON', 2 => 'TUE', 3 => 'WED', 4 => 'THU', 5 => 'FRI', 6 => 'SAT', 7 => 'SUN'];
/**
* Constructor
*/
public function __construct()
{
$this->nthRange = range(1, 5);
parent::__construct();
}
public function isSatisfiedBy(DateTime $date, $value)
/**
* @inheritDoc
*
* @param \DateTime|\DateTimeImmutable $date
*/
public function isSatisfiedBy(DateTimeInterface $date, $value)
{
if ($value == '?') {
return true;
@@ -49,9 +70,11 @@ class DayOfWeekField extends AbstractField
// Find out if this is the last specific weekday of the month
if (strpos($value, 'L')) {
$weekday = str_replace('7', '0', substr($value, 0, strpos($value, 'L')));
$weekday = (int) $this->convertLiterals(substr($value, 0, strpos($value, 'L')));
$weekday %= 7;
$tdate = clone $date;
$tdate->setDate($currentYear, $currentMonth, $lastDayOfMonth);
$tdate = $tdate->setDate($currentYear, $currentMonth, $lastDayOfMonth);
while ($tdate->format('w') != $weekday) {
$tdateClone = new DateTime();
$tdate = $tdateClone
@@ -94,7 +117,7 @@ class DayOfWeekField extends AbstractField
}
$tdate = clone $date;
$tdate->setDate($currentYear, $currentMonth, 1);
$tdate = $tdate->setDate($currentYear, $currentMonth, 1);
$dayCount = 0;
$currentDay = 1;
while ($currentDay < $lastDayOfMonth + 1) {
@@ -103,7 +126,7 @@ class DayOfWeekField extends AbstractField
break;
}
}
$tdate->setDate($currentYear, $currentMonth, ++$currentDay);
$tdate = $tdate->setDate($currentYear, $currentMonth, ++$currentDay);
}
return $date->format('j') == $currentDay;
@@ -127,14 +150,17 @@ class DayOfWeekField extends AbstractField
return $this->isSatisfied($fieldValue, $value);
}
public function increment(DateTime $date, $invert = false)
/**
* @inheritDoc
*
* @param \DateTime|\DateTimeImmutable &$date
*/
public function increment(DateTimeInterface &$date, $invert = false)
{
if ($invert) {
$date->modify('-1 day');
$date->setTime(23, 59, 0);
$date = $date->modify('-1 day')->setTime(23, 59, 0);
} else {
$date->modify('+1 day');
$date->setTime(0, 0, 0);
$date = $date->modify('+1 day')->setTime(0, 0, 0);
}
return $this;

View File

@@ -44,7 +44,7 @@ class FieldFactory
break;
default:
throw new InvalidArgumentException(
$position . ' is not a valid position'
($position + 1) . ' is not a valid position'
);
}
}

View File

@@ -1,7 +1,8 @@
<?php
namespace Cron;
use DateTime;
use DateTimeInterface;
/**
* CRON field interface
@@ -11,23 +12,23 @@ interface FieldInterface
/**
* Check if the respective value of a DateTime field satisfies a CRON exp
*
* @param DateTime $date DateTime object to check
* @param string $value CRON expression to test against
* @param DateTimeInterface $date DateTime object to check
* @param string $value CRON expression to test against
*
* @return bool Returns TRUE if satisfied, FALSE otherwise
*/
public function isSatisfiedBy(DateTime $date, $value);
public function isSatisfiedBy(DateTimeInterface $date, $value);
/**
* When a CRON expression is not satisfied, this method is used to increment
* or decrement a DateTime object by the unit of the cron field
*
* @param DateTime $date DateTime object to change
* @param bool $invert (optional) Set to TRUE to decrement
* @param DateTimeInterface &$date DateTime object to change
* @param bool $invert (optional) Set to TRUE to decrement
*
* @return FieldInterface
*/
public function increment(DateTime $date, $invert = false);
public function increment(DateTimeInterface &$date, $invert = false);
/**
* Validates a CRON expression for a given field

View File

@@ -1,39 +1,55 @@
<?php
namespace Cron;
use DateTime;
use DateTimeZone;
use DateTimeInterface;
use DateTimeZone;
/**
* Hours field. Allows: * , / -
*/
class HoursField extends AbstractField
{
/**
* @inheritDoc
*/
protected $rangeStart = 0;
/**
* @inheritDoc
*/
protected $rangeEnd = 23;
public function isSatisfiedBy(DateTime $date, $value)
/**
* @inheritDoc
*/
public function isSatisfiedBy(DateTimeInterface $date, $value)
{
if ($value == '?') {
return true;
}
return $this->isSatisfied($date->format('H'), $value);
}
public function increment(DateTime $date, $invert = false, $parts = null)
/**
* {@inheritDoc}
*
* @param \DateTime|\DateTimeImmutable &$date
* @param string|null $parts
*/
public function increment(DateTimeInterface &$date, $invert = false, $parts = null)
{
// Change timezone to UTC temporarily. This will
// allow us to go back or forwards and hour even
// if DST will be changed between the hours.
if (is_null($parts) || $parts == '*') {
$timezone = $date->getTimezone();
$date->setTimezone(new DateTimeZone('UTC'));
if ($invert) {
$date->modify('-1 hour');
} else {
$date->modify('+1 hour');
}
$date->setTimezone($timezone);
$date = $date->setTimezone(new DateTimeZone('UTC'));
$date = $date->modify(($invert ? '-' : '+') . '1 hour');
$date = $date->setTimezone($timezone);
$date->setTime($date->format('H'), $invert ? 59 : 0);
$date = $date->setTime($date->format('H'), $invert ? 59 : 0);
return $this;
}
@@ -57,11 +73,11 @@ class HoursField extends AbstractField
$hour = $hours[$position];
if ((!$invert && $date->format('H') >= $hour) || ($invert && $date->format('H') <= $hour)) {
$date->modify(($invert ? '-' : '+') . '1 day');
$date->setTime($invert ? 23 : 0, $invert ? 59 : 0);
$date = $date->modify(($invert ? '-' : '+') . '1 day');
$date = $date->setTime($invert ? 23 : 0, $invert ? 59 : 0);
}
else {
$date->setTime($hour, $invert ? 59 : 0);
$date = $date->setTime($hour, $invert ? 59 : 0);
}
return $this;

View File

@@ -2,30 +2,45 @@
namespace Cron;
use DateTime;
use DateTimeInterface;
/**
* Minutes field. Allows: * , / -
*/
class MinutesField extends AbstractField
{
/**
* @inheritDoc
*/
protected $rangeStart = 0;
/**
* @inheritDoc
*/
protected $rangeEnd = 59;
public function isSatisfiedBy(DateTime $date, $value)
/**
* @inheritDoc
*/
public function isSatisfiedBy(DateTimeInterface $date, $value)
{
if ($value == '?') {
return true;
}
return $this->isSatisfied($date->format('i'), $value);
}
public function increment(DateTime $date, $invert = false, $parts = null)
/**
* {@inheritDoc}
*
* @param \DateTime|\DateTimeImmutable &$date
* @param string|null $parts
*/
public function increment(DateTimeInterface &$date, $invert = false, $parts = null)
{
if (is_null($parts)) {
if ($invert) {
$date->modify('-1 minute');
} else {
$date->modify('+1 minute');
}
$date = $date->modify(($invert ? '-' : '+') . '1 minute');
return $this;
}
@@ -48,11 +63,11 @@ class MinutesField extends AbstractField
}
if ((!$invert && $current_minute >= $minutes[$position]) || ($invert && $current_minute <= $minutes[$position])) {
$date->modify(($invert ? '-' : '+') . '1 hour');
$date->setTime($date->format('H'), $invert ? 59 : 0);
$date = $date->modify(($invert ? '-' : '+') . '1 hour');
$date = $date->setTime($date->format('H'), $invert ? 59 : 0);
}
else {
$date->setTime($date->format('H'), $minutes[$position]);
$date = $date->setTime($date->format('H'), $minutes[$position]);
}
return $this;

View File

@@ -2,33 +2,54 @@
namespace Cron;
use DateTime;
use DateTimeInterface;
/**
* Month field. Allows: * , / -
*/
class MonthField extends AbstractField
{
/**
* @inheritDoc
*/
protected $rangeStart = 1;
/**
* @inheritDoc
*/
protected $rangeEnd = 12;
/**
* @inheritDoc
*/
protected $literals = [1 => 'JAN', 2 => 'FEB', 3 => 'MAR', 4 => 'APR', 5 => 'MAY', 6 => 'JUN', 7 => 'JUL',
8 => 'AUG', 9 => 'SEP', 10 => 'OCT', 11 => 'NOV', 12 => 'DEC'];
public function isSatisfiedBy(DateTime $date, $value)
/**
* @inheritDoc
*/
public function isSatisfiedBy(DateTimeInterface $date, $value)
{
if ($value == '?') {
return true;
}
$value = $this->convertLiterals($value);
return $this->isSatisfied($date->format('m'), $value);
}
public function increment(DateTime $date, $invert = false)
/**
* @inheritDoc
*
* @param \DateTime|\DateTimeImmutable &$date
*/
public function increment(DateTimeInterface &$date, $invert = false)
{
if ($invert) {
$date->modify('last day of previous month');
$date->setTime(23, 59);
$date = $date->modify('last day of previous month')->setTime(23, 59);
} else {
$date->modify('first day of next month');
$date->setTime(0, 0);
$date = $date->modify('first day of next month')->setTime(0, 0);
}
return $this;