You are here

final class DateRecurHelper in Recurring Dates Field 3.1.x

Same name and namespace in other branches
  1. 8.2 src/DateRecurHelper.php \Drupal\date_recur\DateRecurHelper
  2. 3.x src/DateRecurHelper.php \Drupal\date_recur\DateRecurHelper
  3. 3.0.x src/DateRecurHelper.php \Drupal\date_recur\DateRecurHelper

Helper for recurring rules.

Provides a helper for getting occurrences from a RRULE. The class can be iterated apon, producing occurrence objects beginning at the first occurrence.

This helper is a proxy to the default helper. It should be used if there is no preference of implementation.

Hierarchy

Expanded class hierarchy of DateRecurHelper

5 files declare their use of DateRecurHelper
DateRecurBasicWidget.php in src/Plugin/Field/FieldWidget/DateRecurBasicWidget.php
DateRecurItem.php in src/Plugin/Field/FieldType/DateRecurItem.php
DateRecurRruleConstraintValidator.php in src/Plugin/Validation/Constraint/DateRecurRruleConstraintValidator.php
DateRecurRruleUnitTest.php in tests/src/Unit/DateRecurRruleUnitTest.php
DateRecurRulePartConstraintValidator.php in src/Plugin/Validation/Constraint/DateRecurRulePartConstraintValidator.php

File

src/DateRecurHelper.php, line 20

Namespace

Drupal\date_recur
View source
final class DateRecurHelper implements DateRecurHelperInterface {

  /**
   * The date recur helper.
   *
   * @var \Drupal\date_recur\DateRecurHelperInterface
   */
  protected $dateRecurHelper;

  /**
   * DateRecurHelper constructor.
   *
   * @param \Drupal\date_recur\DateRecurHelperInterface $dateRecurHelper
   *   The date recur helper.
   */
  public function __construct(DateRecurHelperInterface $dateRecurHelper) {
    $this->dateRecurHelper = $dateRecurHelper;
  }

  /**
   * Create a instance of helper using system default.
   *
   * @param string $string
   *   The repeat rule.
   * @param \DateTimeInterface $dtStart
   *   The initial occurrence start date.
   * @param \DateTimeInterface|null $dtStartEnd
   *   The initial occurrence end date, or NULL to use start date.
   *
   * @return static
   *   A rule helper.
   *
   * @throws \Exception
   *   Throws various exceptions if string is invalid.
   */
  public static function create(string $string, \DateTimeInterface $dtStart, \DateTimeInterface $dtStartEnd = NULL) {

    // @todo Get the helper preference from Drupal module config.

    /** @var \Drupal\date_recur\DateRecurHelperInterface $dateRecurHelper */
    $dateRecurHelper = RlHelper::createInstance($string, $dtStart, $dtStartEnd);
    return new static($dateRecurHelper);
  }

  /**
   * {@inheritdoc}
   */
  public static function createInstance(string $string, \DateTimeInterface $dtStart, ?\DateTimeInterface $dtStartEnd = NULL) : DateRecurHelperInterface {
    throw new \LogicException('Create instance must not be called on this helper.');
  }

  /**
   * {@inheritdoc}
   */
  public function getRules() : array {
    $rules = $this->dateRecurHelper
      ->getRules();
    assert(is_array($rules));
    assert(Inspector::assertAllObjects($rules, DateRecurRuleInterface::class));
    return $rules;
  }

  /**
   * {@inheritdoc}
   */
  public function isInfinite() : bool {
    return $this->dateRecurHelper
      ->isInfinite();
  }

  /**
   * {@inheritdoc}
   */
  public function generateOccurrences(?\DateTimeInterface $rangeStart = NULL, ?\DateTimeInterface $rangeEnd = NULL) : \Generator {
    return $this->dateRecurHelper
      ->generateOccurrences($rangeStart, $rangeEnd);
  }

  /**
   * {@inheritdoc}
   */
  public function getOccurrences(\DateTimeInterface $rangeStart = NULL, ?\DateTimeInterface $rangeEnd = NULL, ?int $limit = NULL) : array {
    return $this->dateRecurHelper
      ->getOccurrences($rangeStart, $rangeEnd, $limit);
  }

  /**
   * {@inheritdoc}
   */
  public function getExcluded() : array {
    $exDates = $this->dateRecurHelper
      ->getExcluded();
    assert(Inspector::assertAllObjects($exDates, \DateTimeInterface::class));
    return $exDates;
  }

  /**
   * {@inheritdoc}
   */
  public function current() : DateRange {
    return $this->dateRecurHelper
      ->current();
  }

  /**
   * {@inheritdoc}
   */
  public function next() : void {
    $this->dateRecurHelper
      ->next();
  }

  /**
   * {@inheritdoc}
   */
  public function key() : ?int {
    return $this->dateRecurHelper
      ->key();
  }

  /**
   * {@inheritdoc}
   */
  public function valid() : bool {
    return $this->dateRecurHelper
      ->valid();
  }

  /**
   * {@inheritdoc}
   */
  public function rewind() : void {
    $this->dateRecurHelper
      ->rewind();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DateRecurHelper::$dateRecurHelper protected property The date recur helper.
DateRecurHelper::create public static function Create a instance of helper using system default.
DateRecurHelper::createInstance public static function Create a new instance. Overrides DateRecurHelperInterface::createInstance
DateRecurHelper::current public function
DateRecurHelper::generateOccurrences public function Calculates occurrences as a generator. Overrides DateRecurHelperInterface::generateOccurrences
DateRecurHelper::getExcluded public function Get excluded dates. Overrides DateRecurHelperInterface::getExcluded
DateRecurHelper::getOccurrences public function Get all occurrences. Overrides DateRecurHelperInterface::getOccurrences
DateRecurHelper::getRules public function Get the rules that comprise this helper. Overrides DateRecurHelperInterface::getRules
DateRecurHelper::isInfinite public function Determine whether this is infinite. Overrides DateRecurHelperInterface::isInfinite
DateRecurHelper::key public function
DateRecurHelper::next public function
DateRecurHelper::rewind public function
DateRecurHelper::valid public function
DateRecurHelper::__construct public function DateRecurHelper constructor.