RRule\RSet::addExRule PHP Method

addExRule() public method

In RFC 2445 but deprecated in RFC 5545
public addExRule ( mixed $rrule )
$rrule mixed an instance of RRuleInterface or something that can be transformed into a RRule (string or array)
    public function addExRule($rrule)
    {
        if (is_string($rrule) || is_array($rrule)) {
            $rrule = new RRule($rrule);
        } elseif (!$rrule instanceof RRuleInterface) {
            throw new \InvalidArgumentException('The rule must be a string, an array or implement RRuleInterface');
        }
        // cloning because I want to iterate it without being disturbed
        $this->exrules[] = clone $rrule;
        $this->clearCache();
        return $this;
    }

Usage Example

Example #1
0
 public function testGetter()
 {
     $rset = new RSet();
     $rset->addRRule(array('FREQ' => 'YEARLY', 'COUNT' => 2, 'BYDAY' => 'TU', 'DTSTART' => date_create('1997-09-02 09:00')));
     $rset->addRRule(new RRule(array('FREQ' => 'YEARLY', 'COUNT' => 1, 'BYDAY' => 'TH', 'DTSTART' => date_create('1997-09-02 09:00'))));
     $rset->addDate(date_create('1997-09-04 09:00'));
     $rset->addDate(date_create('1997-09-05 09:00'));
     $rset->addDate(date_create('1997-09-06 09:00'));
     $rset->addExRule(array('FREQ' => 'YEARLY', 'COUNT' => 3, 'BYDAY' => 'TH', 'DTSTART' => date_create('1997-09-02 09:00')));
     $this->assertInternalType('array', $rset->getRRules());
     $this->assertCount(2, $rset->getRRules());
     $this->assertInternalType('array', $rset->getExRules());
     $this->assertCount(1, $rset->getExRules());
     $this->assertInternalType('array', $rset->getDates());
     $this->assertCount(3, $rset->getDates());
     $this->assertInternalType('array', $rset->getExDates());
     $this->assertCount(0, $rset->getExDates());
 }