Example #1
0
 public static function parse($conf, $inputs)
 {
     $confPath = \Path::instance()->currentProject('etc.conf.@' . $conf . '.conf.xml');
     if (!file_exists($confPath)) {
         return false;
     }
     $dom = new \DOMDocument("1.0", "utf-8");
     $dom->load($confPath);
     $xpath = new \DOMXPath($dom);
     $xpath->registerNamespace('bong', 'http://lab.zigmoyd.net/xmlns/bong');
     $fieldNodes = $xpath->query("//bong:form/bong:field");
     $form = new Form();
     foreach ($fieldNodes as $fieldNode) {
         $field = null;
         $name = self::__attrValue($fieldNode, "name");
         $default = self::__attrValue($fieldNode, "default");
         if ($name) {
             $field = new Field($name);
             $required = self::__attrValue($fieldNode, "required", 'false');
             if ($required == 'true') {
                 $field->setRequiredFlag(true);
             }
             if (isset($inputs[$name])) {
                 $field->setValue(strlen($inputs[$name]) > 0 ? $inputs[$name] : ($default ? $default : ''));
             }
             $ruleNodes = $xpath->query("bong:criteria", $fieldNode);
             foreach ($ruleNodes as $ruleNode) {
                 $ruleName = self::__attrValue($ruleNode, 'name');
                 if ($ruleName) {
                     $arg = self::__attrValue($ruleNode, 'value');
                     $error = self::__attrValue($ruleNode, 'msg');
                     $rule = new RuleSet($ruleName, $error, $arg);
                     $field->addRuleSet($rule);
                 }
             }
         }
         $form->addField($field);
     }
     return $form;
 }