Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Recurr/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,29 @@ class Rule

/** @var array */
protected $exDates = array();

/** @var array */
protected $properties = [
'FREQ',
'DTSTART',
'DTEND',
'UNTIL',
'UNTIL',
'COUNT',
'INTERVAL',
'BYSECOND',
'BYMINUTE',
'BYHOUR',
'BYDAY',
'BYMONTHDAY',
'BYYEARDAY',
'BYWEEKNO',
'BYMONTH',
'BYSETPOS',
'WKST',
'RDATE',
'EXDATE'
];

/**
* Construct a new Rule.
Expand Down Expand Up @@ -431,6 +454,18 @@ public function loadFromArray($parts)
if (isset($parts['EXDATE'])) {
$this->setExDates(explode(',', $parts['EXDATE']));
}

// UNKNOWN PROPERTIES
$invalidProperties = array_values(array_diff(array_keys($parts), $this->properties));

if($invalidProperties) {
$msg = array_pop($invalidProperties);

if ($invalidProperties)
$msg = implode(', ', $invalidProperties).', and '.$msg;

throw new InvalidRRule('Unknown RRULE property: '.$msg);
}

return $this;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Recurr/Test/RuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,14 @@ public function testBadWeekStart()
{
$this->rule->setWeekStart('monday');
}

/**
* @expectedException \Recurr\Exception\InvalidRRule
*/
public function testUnknownPropertyFromStringThrowsException()
{
$this->rule->loadFromString('FREQ=MONTHLY;BYDAY=-1FR;COUNT=10;SKIP=2');
}

/**
* @dataProvider exampleRruleProvider
Expand Down