| @@ 9-28 (lines=20) @@ | ||
| 6 | * Class CountTransformer |
|
| 7 | * @package Recurrence\RruleTransformer |
|
| 8 | */ |
|
| 9 | class CountTransformer implements TransformerInterface |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @param string $rRule |
|
| 13 | * @return integer |
|
| 14 | */ |
|
| 15 | public function transform($rRule) |
|
| 16 | { |
|
| 17 | if (preg_match('/COUNT=([0-9]+)/', $rRule, $matches)) { |
|
| 18 | return (int) $matches[1]; |
|
| 19 | } |
|
| 20 | ||
| 21 | // If there is an INTERVAL option but transformer was not able to get it, assume it was an invalid option |
|
| 22 | if (preg_match('/COUNT=/', $rRule, $matches)) { |
|
| 23 | throw new \InvalidArgumentException('RRULE invalid [COUNT] option'); |
|
| 24 | } |
|
| 25 | ||
| 26 | return null; |
|
| 27 | } |
|
| 28 | } |
|
| 29 | ||
| @@ 9-28 (lines=20) @@ | ||
| 6 | * Class IntervalTransformer |
|
| 7 | * @package Recurrence\RruleTransformer |
|
| 8 | */ |
|
| 9 | class IntervalTransformer implements TransformerInterface |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @param string $rRule |
|
| 13 | * @return integer |
|
| 14 | */ |
|
| 15 | public function transform($rRule) |
|
| 16 | { |
|
| 17 | if (preg_match('/INTERVAL=([0-9]+)/', $rRule, $matches)) { |
|
| 18 | return (int) $matches[1]; |
|
| 19 | } |
|
| 20 | ||
| 21 | // If there is an INTERVAL option but transformer was not able to get it, assume it was an invalid option |
|
| 22 | if (preg_match('/INTERVAL=/', $rRule, $matches)) { |
|
| 23 | throw new \InvalidArgumentException('RRULE invalid [INTERVAL] option'); |
|
| 24 | } |
|
| 25 | ||
| 26 | return null; |
|
| 27 | } |
|
| 28 | } |
|
| 29 | ||