本文整理汇总了PHP中Expression::addPart方法的典型用法代码示例。如果您正苦于以下问题:PHP Expression::addPart方法的具体用法?PHP Expression::addPart怎么用?PHP Expression::addPart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression::addPart方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Parses expression given in literal form, builds an Expression object and returns it.
*
* @param string $string
* @return Expression
* @throws \InvalidArgumentException
*/
public static function create($string)
{
$months = implode('|', array_keys(self::$_synonyms[self::MONTH]));
$daysOfWeek = implode('|', array_keys(self::$_synonyms[self::DAY_OF_WEEK]));
$shorthands = implode('|', array_keys(self::$_shorthands));
$pattern = "/\n (?:^\n (?P<minute>[\\d\\*\\/\\,\\-\\%]+)\n \\s\n (?P<hour>[\\d\\*\\/\\,\\-\\%]+)\n \\s\n (?P<dayOfMonth>[\\d\\*\\/\\,\\-\\%]+)\n \\s\n (?P<month>[\\d\\*\\/\\,\\-\\%]+|{$months})\n \\s\n (?P<dayOfWeek>[\\d\\*\\/\\,\\-\\%]+|{$daysOfWeek})\n \$) | (?:^\n (?P<shorthand>{$shorthands})\n \$)\n \$/ix";
if (preg_match($pattern, $string, $matches)) {
if (isset($matches['shorthand']) && $matches['shorthand']) {
return self::create(self::$_shorthands[$matches['shorthand']]);
}
$expression = new Expression();
foreach (array('minute', 'hour', 'dayOfMonth', 'month', 'dayOfWeek') as $part) {
// Expand lists
$matches[$part] = explode(',', $matches[$part]);
// Separate range and step
foreach ($matches[$part] as $timeUnit) {
$shards = explode('/', $timeUnit);
// Do we have a range (or asterisk) *and* a step?
if (count($shards) > 1) {
// Do we have an asterisk?
if ($shards[0] == '*') {
$expression->addPart($part, array('scalar' => '*', 'step' => $shards[1]));
// OK, clearly we have a range
} else {
$rangeLimits = explode('-', $shards[0]);
$expression->addPart($part, array('min' => $rangeLimits[0], 'max' => $rangeLimits[1], 'step' => $shards[1]));
}
// OK, we have just a range
} else {
$rangeLimits = explode('-', $shards[0]);
// Do we have a range *or* a number?
if (count($rangeLimits) > 1) {
$expression->addPart($part, array('min' => $rangeLimits[0], 'max' => $rangeLimits[1]));
// OK, we have just a number
} else {
$expression->addPart($part, $rangeLimits[0]);
}
}
}
}
return $expression;
}
throw new \InvalidArgumentException(sprintf('Expression "%s" is not supported', $string));
}