JBZoo\SimpleTypes\Parser::checkRule PHP Method

checkRule() public method

public checkRule ( string $rule ) : string
$rule string
return string
    public function checkRule($rule)
    {
        $rule = $this->cleanRule($rule);
        if (!$rule) {
            return $this->_default;
        }
        if (array_key_exists($rule, $this->_rules)) {
            return $rule;
        }
        throw new Exception('Undefined rule: ' . $rule);
    }

Usage Example

Beispiel #1
0
 /**
  * @param string $newRule
  * @param bool   $getClone
  * @return $this
  * @throws \JBZoo\SimpleTypes\Exception
  */
 public function convert($newRule, $getClone = false)
 {
     if (!$newRule) {
         $newRule = $this->_rule;
     }
     $newRule = $this->_parser->checkRule($newRule);
     $obj = $getClone ? clone $this : $this;
     if ($newRule !== $obj->_rule) {
         $obj->_value = $obj->_customConvert($newRule, true);
         $obj->_rule = $newRule;
     }
     return $obj;
 }