Created
September 27, 2014 08:58
-
-
Save florinutz/f8d62cd7267ee81f5893 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function getFrequencySection() | |
{ | |
$builder = new TreeBuilder(); | |
$node = $builder->root('frequencies'); | |
return $node | |
->cannotBeEmpty() | |
->requiresAtLeastOneElement() | |
->prototype('array') | |
->beforeNormalization() | |
->ifString() | |
->then(function($v){ return [ 'interval' => $v ]; }) | |
->end() | |
->isRequired() | |
->addDefaultsIfNotSet() | |
->children() | |
->scalarNode('interval') | |
->validate() | |
->ifTrue(function($v) { return !$this->intervalStringIsValid($v); }) | |
->thenInvalid("Invalid DateInterval string detected: %s. Check http://php.net/manual/en/dateinterval.createfromdatestring.php#refsect1-dateinterval.createfromdatestring-examples") | |
->end() | |
->isRequired() | |
->cannotBeEmpty() | |
->defaultValue('P1D') | |
->end() | |
->integerNode('times') | |
->info('Number of times to repeat this interval') | |
->defaultValue(1) | |
->end() | |
->scalarNode('rand_start') | |
->defaultValue(0) | |
->validate() | |
->ifTrue(function($v) { return !$this->intervalStringIsValid($v); }) | |
->thenInvalid("Invalid DateInterval string detected: %s. Check http://php.net/manual/en/dateinterval.createfromdatestring.php#refsect1-dateinterval.createfromdatestring-examples") | |
->end() | |
->end() | |
->scalarNode('rand_end') | |
->defaultValue(0) | |
->validate() | |
->ifTrue(function($v) { return !$this->intervalStringIsValid($v); }) | |
->thenInvalid("Invalid DateInterval string detected: %s. Check http://php.net/manual/en/dateinterval.createfromdatestring.php#refsect1-dateinterval.createfromdatestring-examples") | |
->end() | |
->end() | |
->end() | |
->end() | |
; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment