Beispiel #1
0
 /**
  * @param array|XmlElement $errors
  * @param array|XmlElement $options
  * @param array|XmlElement $defaultErrors
  */
 public function __construct($errors = array(), $options = array(), $defaultErrors = array())
 {
     /**
      * Use xml object to set the errors
      * Otherwise use an array (Manually)
      */
     if ($errors instanceof XmlElement) {
         foreach ($errors->getChildren() as $child) {
             $this->addError($child->getName(), $child->getContent());
         }
     } else {
         if (true == is_array($errors)) {
             foreach ($errors as $type => $message) {
                 $this->addError($type, $message);
             }
         }
     }
     /**
      * Use xml object to set the options
      * of the validation
      * Otherwise use an array (Manually)
      */
     if ($options instanceof XmlElement) {
         foreach ($options->getAttributes() as $type => $value) {
             $this->addOption($type, $value);
         }
     } else {
         if (true == is_array($options)) {
             foreach ($options as $type => $value) {
                 $this->addOption($type, $value);
             }
         }
     }
     /**
      * Set default errors as fallback
      */
     if ($defaultErrors instanceof XmlElement) {
         foreach ($defaultErrors->getChildren() as $child) {
             $this->addError($child->getName(), $child->getContent(), true);
         }
     } else {
         if (true == is_array($defaultErrors)) {
             foreach ($defaultErrors as $type => $message) {
                 if ($message instanceof Error) {
                     $this->defaultErrors[] = $message;
                     continue;
                 }
                 $this->addError($type, $message, true);
             }
         }
     }
     /**
      * Prepeare the result and
      * parse the errors
      */
     $this->result = new Validation\Result($this->errors, $this->defaultErrors);
 }
Beispiel #2
0
 /**
  * Adds the attributes from the given config
  * to itself
  */
 private function setFormAttributesByConfig()
 {
     if ($this->config instanceof \Fewlines\Core\Xml\Tree\Element) {
         foreach ($this->config->getAttributes() as $name => $content) {
             switch (strtolower($name)) {
                 case 'name':
                     $this->setName($content);
                     break;
                 case 'method':
                     $this->setMethod($content);
                     break;
                 case 'target':
                     $this->setTarget($content);
                     break;
                 case 'accept-charset':
                     $this->setAcceptCharset($content);
                     break;
                 case 'novalidate':
                     $this->setNoValidate($content);
                     break;
                 case 'autocomplete':
                     $this->setAutoComplete($content);
                     break;
                 case 'action':
                     $this->setAction($content);
                     break;
                 case 'enctype':
                     $this->setEncType($content);
                     break;
                 default:
                     $this->addAttribute($name, $content);
                     break;
             }
         }
     }
 }
Beispiel #3
0
 /**
  * @param Element &$child
  */
 private function applyAttributeShortcuts(Element &$child)
 {
     foreach ($child->getAttributes() as $name => $value) {
         if (ShortcutHelper::containsShortcut($value)) {
             $child->addAttribute($name, ShortcutHelper::parse($value));
         }
     }
 }