FieldInterface.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. namespace Cron;
  4. use DateTimeInterface;
  5. /**
  6. * CRON field interface.
  7. */
  8. interface FieldInterface
  9. {
  10. /**
  11. * Check if the respective value of a DateTime field satisfies a CRON exp.
  12. *
  13. * @internal
  14. * @param DateTimeInterface $date DateTime object to check
  15. * @param string $value CRON expression to test against
  16. *
  17. * @return bool Returns TRUE if satisfied, FALSE otherwise
  18. */
  19. public function isSatisfiedBy(DateTimeInterface $date, $value, bool $invert): bool;
  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. * @internal
  25. * @param DateTimeInterface $date DateTime object to change
  26. * @param bool $invert (optional) Set to TRUE to decrement
  27. * @param string|null $parts (optional) Set parts to use
  28. *
  29. * @return FieldInterface
  30. */
  31. public function increment(DateTimeInterface &$date, $invert = false, $parts = null): FieldInterface;
  32. /**
  33. * Validates a CRON expression for a given field.
  34. *
  35. * @param string $value CRON expression value to validate
  36. *
  37. * @return bool Returns TRUE if valid, FALSE otherwise
  38. */
  39. public function validate(string $value): bool;
  40. }