示例#1
0
文件: find.php 项目: tokushima/ebi
eq('XYZ', $x->find_get('abc/def/ghi', 1)->value());
$x = \ebi\Xml::anonymous("<asd><abc><def><ghi>ABC</ghi><ghi>XYZ</ghi></def></abc></asd>");
eq('XYZ', $x->find_get('abc/def/ghi', 1)->value());
$x = \ebi\Xml::anonymous("<asd><abc><def><jkl>aaa</jkl><ghi>ABC</ghi><jkl>bbb</jkl><ghi>XYZ</ghi></def></abc></asd>");
eq('XYZ', $x->find_get('abc/def/ghi', 1)->value());
$x = \ebi\Xml::anonymous("<asd><abc><def><jkl>aaa</jkl><ghi>ABC</ghi><jkl>bbb</jkl><ghi>XYZ</ghi></def></abc></asd>");
eq('bbb', $x->find_get('abc/def/jkl', 1)->value());
$x = \ebi\Xml::anonymous("<asd><abc><def><jkl>aaa</jkl><ghi>ABC</ghi><jkl>bbb</jkl><ghi>XYZ</ghi></def></abc></asd>");
eq('bbb', $x->find_get('abc/def/ghi|jkl', 2)->value());
$x = \ebi\Xml::anonymous("<xml><a><x>A</x></a><c><x>C</x></c><b><x>B</x></b></xml>");
eq('C', $x->find_get('b|c/x')->value());
$x = \ebi\Xml::anonymous("<xml> <a><b><e>NO1</e></b></a> <a><b><c>A</c></b></a> <a><b><c>B</c></b></a>  <a><b><c>C</c></b></a> </xml>");
eq('A', $x->find_get('a/b/c')->value());
$i = 0;
foreach ($x->find('a/b/c') as $f) {
    $i++;
}
eq(1, $i);
$x = \ebi\Xml::anonymous("<xml> <a><b><e>NO1</e></b></a> <a><b><c>A</c></b></a> <a><b><c>B</c></b></a>  <a><b><c>C</c></b></a> </xml>");
try {
    $x->find_get('a/b/c', 1)->value();
    fail();
} catch (\ebi\exception\NotFoundException $e) {
}
$x = \ebi\Xml::anonymous("<xml> <a><b><e>NO1</e><c>A</c><c>B</c><c>C</c></b></a> </xml>");
eq('C', $x->find_get('a/b/c', 2)->value());
$i = 0;
foreach ($x->find('a/b/c') as $f) {
    $i++;
}
eq(3, $i);
示例#2
0
 private function html_input($src)
 {
     foreach (\ebi\Xml::anonymous($src)->find('input|textarea|select') as $obj) {
         if ('' != ($originalName = $obj->in_attr('name', $obj->in_attr('id', '')))) {
             $obj->escape(false);
             $type = strtolower($obj->in_attr('type', 'text'));
             $name = $this->parse_plain_variable($this->form_variable_name($originalName));
             $tagname = strtolower($obj->name());
             $change = false;
             $uid = uniqid();
             if (substr($originalName, -2) !== '[]') {
                 if ($type == 'checkbox') {
                     if ($obj->in_attr('rt:multiple', 'true') === 'true') {
                         $obj->attr('name', $originalName . '[]');
                     }
                     $obj->rm_attr('rt:multiple');
                     $change = true;
                 } else {
                     if ($obj->is_attr('multiple') || $obj->in_attr('multiple') === 'multiple') {
                         $obj->attr('name', $originalName . '[]');
                         $obj->rm_attr('multiple');
                         $obj->attr('multiple', 'multiple');
                         $change = true;
                     }
                 }
             } else {
                 if ($obj->in_attr('name') !== $originalName) {
                     $obj->attr('name', $originalName);
                     $change = true;
                 }
             }
             if ($obj->is_attr('rt:param')) {
                 switch ($tagname) {
                     case 'select':
                         $value = sprintf('<rt:loop param="%s" var="%s" key="%s">' . (trim($obj->value()) == '' ? '<option value="{$%s}">{$%s}</option>' : $obj->value()) . '</rt:loop>', $obj->in_attr('rt:param'), $obj->in_attr('rt:var', 'loop_var' . $uid), $obj->in_attr('rt:key', 'loop_key' . $uid), $obj->in_attr('rt:key', 'loop_key' . $uid), $obj->in_attr('rt:var', 'loop_var' . $uid));
                         $obj->value($this->rtloop($value));
                         if ($obj->is_attr('rt:null')) {
                             $obj->value('<option value="">' . $obj->in_attr('rt:null') . '</option>' . $obj->value());
                         }
                 }
                 $obj->rm_attr('rt:param', 'rt:key', 'rt:var');
                 $change = true;
             }
             if ($tagname == 'input') {
                 if ($this->is_reference($obj)) {
                     if ($type == 'checkbox' || $type == 'radio') {
                         $value = $this->parse_plain_variable($obj->in_attr('value', 'true'));
                         $value = substr($value, 0, 1) != '$' ? sprintf("'%s'", $value) : $value;
                         $obj->rm_attr('checked');
                         $obj->plain_attr($this->check_selected($name, $value, 'checked'));
                     } else {
                         $obj->attr('value', $this->no_exception_str(sprintf('{$_t_.htmlencode(%s)}', preg_match("/^\\{\$(.+)\\}\$/", $originalName, $match) ? '{$$' . $match[1] . '}' : '{$' . $originalName . '}')));
                     }
                     $change = true;
                 }
             } else {
                 if ($tagname == 'textarea') {
                     if ($this->is_reference($obj)) {
                         $obj->value($this->no_exception_str(sprintf('{$_t_.htmlencode(%s)}', preg_match("/^{\$(.+)}\$/", $originalName, $match) ? '{$$' . $match[1] . '}' : '{$' . $originalName . '}')));
                         $obj->close_empty(false);
                         $change = true;
                     }
                 } else {
                     if ($tagname == 'select') {
                         if ($this->is_reference($obj) || $obj->is_attr('value')) {
                             $select = $obj->value();
                             $name = $this->parse_plain_variable($obj->in_attr('value', $name));
                             $obj->rm_attr('value');
                             foreach ($obj->find('option') as $option) {
                                 $option->escape(false);
                                 $value = $this->parse_plain_variable($option->in_attr('value'));
                                 if (empty($value) || $value[0] != '$') {
                                     $value = sprintf("'%s'", $value);
                                 }
                                 $option->rm_attr('selected');
                                 $option->plain_attr($this->check_selected($name, $value, 'selected'));
                                 $select = str_replace($option->plain(), $option->get(), $select);
                             }
                             $obj->value($select);
                             $obj->close_empty(false);
                             $change = true;
                         }
                     }
                 }
             }
             if ($change) {
                 $src = str_replace($obj->plain(), $obj->get(), $src);
             }
         }
     }
     return $src;
 }