Exemplo n.º 1
0
 /**
  * Load any constraints present for the widget
  *
  * @param DOMElement $element
  * @param One_Form_Widget_Abstract $widget
  */
 protected static function loadConstraints(DOMElement $element, One_Form_Widget_Abstract &$widget)
 {
     $xpath = new DOMXPath(self::$_dom);
     $constraints = $xpath->query('./constraints/constraint', $element);
     if ($constraints->length > 0) {
         for ($i = 0; $i < $constraints->length; $i++) {
             $child = $constraints->item($i);
             $type = 0;
             $rawType = $child->getAttribute('type');
             $hasRegExp = stristr($rawType, 'R') !== false ? true : false;
             for ($j = 0; $j < strlen($rawType); $j++) {
                 switch (strtoupper($rawType[$j])) {
                     case 'N':
                         $type += One_Form_Constraint::N;
                         break;
                     case 'E':
                         if (!$hasRegExp) {
                             $type += One_Form_Constraint::E;
                         }
                         break;
                     case 'L':
                         if (!$hasRegExp) {
                             $type += One_Form_Constraint::L;
                         }
                         break;
                     case 'G':
                         if (!$hasRegExp) {
                             $type += One_Form_Constraint::G;
                         }
                         break;
                     case 'M':
                         if (!$hasRegExp) {
                             $type += One_Form_Constraint::M;
                         }
                         break;
                     case 'C':
                         if (!$hasRegExp) {
                             $type += One_Form_Constraint::C;
                         }
                         break;
                     case 'R':
                         $type += One_Form_Constraint::R;
                         break;
                 }
             }
             $value = trim($child->nodeValue);
             $error = $child->getAttribute('error');
             $widget->addConstraint($type, $value, $error);
         }
     }
 }