public static function parse(&$src) { $result = null; if (\org\rhaco\Xml::set($tag, $src, 'summary')) { $result = new self(); $result->type($tag->in_attr('type', 'text')); $result->lang($tag->in_attr('xml:lang')); $result->value($tag->value()); $src = str_replace($tag->plain(), '', $src); } return $result; }
public function after_template(\org\rhaco\lang\Str $obj) { $src = $obj->get(); \org\rhaco\Xml::set($tag, '<:>' . $src . '</:>'); foreach ($tag->in('form') as $form) { if ($form->in_attr('action') == '' || strpos($form->in_attr('action'), '$t.map_url') !== false) { $form->escape(false); $form->value(sprintf('<input type="hidden" name="csrftoken" value="%s" />', $this->no) . $form->value()); $src = str_replace($form->plain(), $form->get(), $src); } } $obj->set($src); }
public static function parse(&$src) { $result = array(); \org\rhaco\Xml::set($x, '<:>' . $src . '</:>'); foreach ($x->in('link') as $in) { $o = new self(); $o->href($in->in_attr('href')); $o->rel($in->in_attr('rel')); $o->type($in->in_attr('type')); $result[] = $o; $src = str_replace($in->plain(), '', $src); } return $result; }
/** * @module org.rhaco.Template * @param org.rhaco.lang.Str $obj */ public function before_template(\org\rhaco\lang\Str $obj) { $src = $obj->get(); if (strpos($src, 'rt:paginator') !== false) { while (Xml::set($tag, $src, 'rt:paginator')) { $param = '$' . $tag->in_attr('param', 'paginator'); $func = sprintf('<?php try{ ?><?php if(%s instanceof \\org\\rhaco\\Paginator){ ?>', $param); $func .= '<div class="pagination"><ul>'; $uniq = uniqid(''); $name = '$__pager__' . $uniq; $counter_var = '$__counter__' . $uniq; $href = $tag->in_attr('href', '?'); $stag = '<li%s>'; $etag = '</li>'; $navi = array_change_key_case(array_flip(explode(',', $tag->in_attr('navi', 'prev,next,first,last,counter')))); $counter = $tag->in_attr('counter', 10); $total = '$__pagertotal__' . $uniq; if (isset($navi['prev'])) { $func .= sprintf('<?php if(%s->is_prev()){ ?><li class="prev"><a href="%s{%s.query_prev()}" rel="prev"><?php }else{ ?><li class="prev disabled"><a><?php } ?>%s</a></li>', $param, $href, $param, '← Previous'); } if (isset($navi['first'])) { $func .= sprintf('<?php if(!%s->is_dynamic() && %s->is_first(%d)){ ?><li><a href="%s{%s.query(%s.first())}">{%s.first()}</a></li><li class="disabled"><a>...</a></li><?php } ?>', $param, $param, $counter, $href, $param, $param, $param); } if (isset($navi['counter'])) { $func .= sprintf('<?php if(!%s->is_dynamic()){ ?>', $param); $func .= sprintf('<?php %s = %s; if(!empty(%s)){ ?>', $total, $param, $total); $func .= sprintf('<?php for(%s=%s->which_first(%d);%s<=%s->which_last(%d);%s++){ ?>', $counter_var, $param, $counter, $counter_var, $param, $counter, $counter_var); $func .= sprintf('<?php if(%s == %s->current()){ ?>', $counter_var, $param); $func .= sprintf('<li class="active"><a>{%s}</a></li>', $counter_var); $func .= '<?php }else{ ?>'; $func .= sprintf('<li><a href="%s{%s.query(%s)}">{%s}</a></li>', $href, $param, $counter_var, $counter_var); $func .= '<?php } ?>'; $func .= '<?php } ?>'; $func .= '<?php } ?>'; $func .= '<?php } ?>'; } if (isset($navi['last'])) { $func .= sprintf('<?php if(!%s->is_dynamic() && %s->is_last(%d)){ ?><li class="disabled"><a>...</a></li><li><a href="%s{%s.query(%s.last())}">{%s.last()}</a></li><?php } ?>', $param, $param, $counter, $href, $param, $param, $param); } if (isset($navi['next'])) { $func .= sprintf('<?php if(%s->is_next()){ ?><li class="next"><a href="%s{%s.query_next()}" rel="next"><?php }else{ ?><li class="next disabled"><a><?php } ?>%s</a></li>', $param, $href, $param, 'Next →', $etag); } $func .= "<?php } ?><?php }catch(\\Exception \$e){} ?>"; $func .= '</ul></div>'; $src = str_replace($tag->plain(), $func, $src); } } $obj->set($src); }
/** * @module org.rhaco.Template * @param org.rhaco.lang.Str $obj */ public function before_template(\org\rhaco\lang\Str $obj) { $src = $obj->get(); if (strpos($src, 'rt:paginator') !== false) { while (Xml::set($tag, $src, 'rt:paginator')) { $param = '$' . $tag->in_attr('param', 'paginator'); $func = sprintf('<?php try{ ?><?php if(%s instanceof \\org\\rhaco\\Paginator){ ?>', $param); if ($tag->value() != '') { $func .= $tag->value(); } else { $uniq = uniqid(''); $name = '$__pager__' . $uniq; $counter_var = '$__counter__' . $uniq; $tagtype = $tag->in_attr('tag'); $href = $tag->in_attr('href', '?'); $stag = empty($tagtype) ? '' : '<' . $tagtype . ' class="%s">'; $etag = empty($tagtype) ? '' : '</' . $tagtype . '>'; $navi = array_change_key_case(array_flip(explode(',', $tag->in_attr('navi', 'prev,next,first,last,counter')))); $counter = $tag->in_attr('counter', 50); $total = '$__pagertotal__' . $uniq; if (isset($navi['prev'])) { $func .= sprintf('<?php if(%s->is_prev()){ ?>%s<a href="%s{%s.query_prev()}" rel="prev">%s</a>%s<?php } ?>', $param, sprintf($stag, 'prev'), $href, $param, 'prev', $etag); } if (isset($navi['first'])) { $func .= sprintf('<?php if(!%s->is_dynamic() && %s->is_first(%d)){ ?>%s<a href="%s{%s.query(%s.first())}">{%s.first()}</a>%s%s...%s<?php } ?>', $param, $param, $counter, sprintf($stag, 'first'), $href, $param, $param, $param, $etag, sprintf($stag, 'first_gt'), $etag); } if (isset($navi['counter'])) { $func .= sprintf('<?php if(!%s->is_dynamic()){ ?>', $param); $func .= sprintf('<?php %s = %s; if(!empty(%s)){ ?>', $total, $param, $total); $func .= sprintf('<?php for(%s=%s->which_first(%d);%s<=%s->which_last(%d);%s++){ ?>', $counter_var, $param, $counter, $counter_var, $param, $counter, $counter_var); $func .= sprintf('%s<?php if(%s == %s->current()){ ?><strong>{%s}</strong><?php }else{ ?><a href="%s{%s.query(%s)}">{%s}</a><?php } ?>%s', sprintf($stag, 'count'), $counter_var, $param, $counter_var, $href, $param, $counter_var, $counter_var, $etag); $func .= '<?php } ?>'; $func .= '<?php } ?>'; $func .= '<?php } ?>'; } if (isset($navi['last'])) { $func .= sprintf('<?php if(!%s->is_dynamic() && %s->is_last(%d)){ ?>%s...%s%s<a href="%s{%s.query(%s.last())}">{%s.last()}</a>%s<?php } ?>', $param, $param, $counter, sprintf($stag, 'last_lt'), $etag, sprintf($stag, 'last'), $href, $param, $param, $param, $etag); } if (isset($navi['next'])) { $func .= sprintf('<?php if(%s->is_next()){ ?>%s<a href="%s{%s.query_next()}" rel="next">%s</a>%s<?php } ?>', $param, sprintf($stag, 'next'), $href, $param, 'next', $etag); } } $func .= "<?php } ?><?php }catch(\\Exception \$e){} ?>"; $src = str_replace($tag->plain(), $func, $src); } } $obj->set($src); }
public static function parse(&$src) { $result = array(); \org\rhaco\Xml::set($x, '<:>' . $src . '</:>'); foreach ($x->in('author') as $in) { $src = str_replace($in->plain(), '', $src); $o = new self(); $o->name($in->f('name.value()')); $o->url($in->f('url.value()')); $o->email($in->f('email.value()')); if (!$o->is_url()) { $o->url($in->f('uri.value()')); } $result[] = $o; } return $result; }
private function replace($name, &$src) { if (strpos($src, $name) !== false) { while (Xml::set($tag, $src, $name)) { $param = $tag->in_attr('param'); $var = $tag->in_attr('var', 'rtinvalid_var' . uniqid('')); if (!isset($param[0]) || $param[0] !== '$') { $param = '"' . $param . '"'; } $value = $tag->value(); $tagtype = $tag->in_attr('tag'); $stag = empty($tagtype) ? '' : '<' . $tagtype . ' class="%s">'; $etag = empty($tagtype) ? '' : '</' . $tagtype . '>'; if (empty($value)) { $varnm = 'rtinvalid_varnm' . uniqid(''); $value = sprintf("<rt:loop param=\"%s\" var=\"%s\">\n" . "%s{\$%s.getMessage()}%s" . "</rt:loop>\n", $var, $varnm, sprintf($stag, $tag->in_attr('class', 'exception')), $varnm, $etag); } $src = str_replace($tag->plain(), sprintf("<?php if(\\org\\rhaco\\Exceptions::has(%s)){ ?>" . "<?php \$%s = \\org\\rhaco\\Exceptions::gets(%s); ?>" . preg_replace("/<rt\\:else[\\s]*.*?>/i", "<?php }else{ ?>", $value) . "<?php } ?>", $param, $var, $param), $src); } } }
/** * 文字列からAtomフィードを取得する * @param string $src * @return self */ public static function parse($src) { $args = func_get_args(); array_shift($args); if (\org\rhaco\Xml::set($tag, $src, 'feed') && $tag->in_attr('xmlns') == self::XMLNS) { $result = new self(); $value = $tag->value(); \org\rhaco\Xml::set($tag, '<:>' . $value . '</:>'); $result->id($tag->f('id.value()')); $result->title($tag->f('title.value()')); $result->subtitle($tag->f('subtitle.value()')); $result->updated($tag->f('updated.value()')); $result->generator($tag->f('generator.value()')); $value = $tag->value(); $result->entry = \org\rhaco\net\xml\atom\Entry::parse($value); $result->link = \org\rhaco\net\xml\atom\Link::parse($value); $result->author = \org\rhaco\net\xml\atom\Author::parse($value); return $result; } throw new \InvalidArgumentException('no atom'); }
public function valid() { if ($this->length > 0 && $this->offset + $this->length <= $this->count) { return false; } if (is_array($this->name)) { $tags = array(); foreach ($this->name as $name) { if (\org\rhaco\Xml::set($get_tag, $this->plain, $name)) { $tags[$get_tag->cur()] = $get_tag; } } if (empty($tags)) { return false; } ksort($tags, SORT_NUMERIC); foreach ($tags as $this->tag) { return true; } } return \org\rhaco\Xml::set($this->tag, $this->plain, $this->name); }
/** * テンプレートから内容を取得しセットする * * テンプレートサンプル * <mail> * <from address="*****@*****.**" name="tokushima" /> * <subject>メールのタイトル</subject> * <body> * メールの本文 * </body> * </mail> * * @param string $template_path テンプレートファイルパス * @param mixed{} $vars テンプレートへ渡す変数 * @return $this */ public function set_template($template_path, $vars = array()) { $resource_path = empty($this->resource_path) ? \org\rhaco\Conf::get('resource_path', \org\rhaco\io\File::resource_path('mail')) : $this->resource_path; $template_path = \org\rhaco\net\Path::absolute($resource_path, $template_path); if (!is_file($template_path)) { throw new \InvalidArgumentException($template_path . ' not found'); } if (\org\rhaco\Xml::set($xml, file_get_contents($template_path), 'mail')) { $from = $xml->f('from'); if ($from !== null) { $this->from($from->in_attr('address'), $from->in_attr('name')); } foreach ($xml->in('to') as $to) { $this->to($to->in_attr('address'), $to->in_attr('name')); } $return_path = $xml->f('return_path'); if ($return_path !== null) { $this->return_path($return_path->in_attr('address')); } $notification = $xml->f('notification'); if ($notification !== null) { $this->notification($notification->in_attr('address')); } $reply_to = $xml->f('reply_to'); if ($reply_to !== null) { $this->reply_to($reply_to->in_attr('address')); } $errors_to = $xml->f('errors_to'); if ($errors_to !== null) { $this->errors_to($errors_to->in_attr('address')); } $subject = trim(str_replace(array("\r\n", "\r", "\n"), '', $xml->f('subject.value()'))); $body = $xml->f('body.value()'); $template = new \org\rhaco\Template(); $template->cp($vars); $template->vars('t', new \org\rhaco\flow\module\Helper()); $this->subject($template->get($subject)); $this->message(\org\rhaco\lang\Text::plain("\n" . $template->get($body) . "\n")); $html = $xml->f('html'); if ($html !== null) { $html_path = \org\rhaco\net\Path::absolute($resource_path, $html->in_attr('src')); foreach ($html->in('media') as $media) { $file = \org\rhaco\net\Path::absolute($resource_path, $media->in_attr('src')); if (!is_file($file)) { throw new \InvalidArgumentException($media->in_attr('src') . ' invalid media'); } $this->media($media->in_attr('src'), file_get_contents($file)); } $template = new \org\rhaco\Template(); $template->cp($vars); $template->vars('t', new \org\rhaco\flow\module\Helper()); $this->html($template->read($html_path)); } foreach ($xml->in('attach') as $attach) { $file = \org\rhaco\net\Path::absolute($resource_path, $attach->in_attr('src')); if (!is_file($file)) { throw new \InvalidArgumentException($attach->in_attr('src') . ' invalid media'); } $this->attach($attach->in_attr('name', $attach->in_attr('src')), file_get_contents($file)); } return $this; } throw new \InvalidArgumentException($template_path . ' invalid data'); }
eq("123", $tag->f("abc.def.attr(var)")); eq("selected", $tag->f("abc.def.ghi.attr(selected)")); eq("<def var='123'><ghi selected>hoge</ghi></def>", $tag->f("abc.def.plain()")); eq(null, $tag->f("abc.def.xyz")); $src = <<<XML <tag> \t<abc> \t\t<def var="123"> \t\t\t<ghi selected>hoge</ghi> \t\t\t<ghi> \t\t\t\t<jkl>rails</jkl> \t\t\t</ghi> \t\t\t<ghi ab="true">django</ghi> \t\t</def> \t</abc> </tag> XML; \org\rhaco\Xml::set($tag, $src, "tag"); eq("django", $tag->f("abc.def.ghi[2].value()")); eq("rails", $tag->f("abc.def.ghi[1].jkl.value()")); eq("django", $tag->f("abc.def.ghi[2].value()")); $tag->f("abc.def.ghi[2].value()", "python"); eq("python", $tag->f("abc.def.ghi[2].value()")); eq("123", $tag->f("abc.def.attr(var)")); eq("true", $tag->f("abc.def.ghi[2].attr(ab)")); $tag->f("abc.def.ghi[2].attr(cd)", 456); eq("456", $tag->f("abc.def.ghi[2].attr(cd)")); eq('selected', $tag->f("abc.def.ghi[0].attr(selected)")); eq(null, $tag->f("abc.def.ghi[1].attr(selected)")); eq(array(), $tag->f("abc.def.in(xyz)")); eq(array(), $tag->f("abc.opq.in(xyz)"));
$b->do_post(url('test_index::upload_value')); if (!\org\rhaco\Xml::set($xml, $b->body(), 'result')) { throw new \LogicException('no result'); } eq('abcd', $xml->f('get_data1.value()')); $b->file_vars('upfile1', __FILE__); $b->do_post(url('test_index::upload_file')); \org\rhaco\Xml::set($xml, $b->body(), 'result'); eq(basename(__FILE__), $xml->f('original_name1.value()')); eq(filesize(__FILE__), (int) $xml->f('size1.value()')); eq('true', $xml->f('mv1.value()')); eq(filesize(__FILE__), (int) $xml->f('mv_size1.value()')); eq(file_get_contents(__FILE__), $xml->f('data1.value()')); $b->vars('value1', 'abcd'); $b->file_vars('upfile1', __FILE__); $b->vars('value2', 'efg'); $b->file_vars('upfile2', __FILE__); $b->do_post(url('test_index::upload_multi')); \org\rhaco\Xml::set($xml, $b->body(), 'result'); eq(basename(__FILE__), $xml->f('original_name1.value()')); eq(filesize(__FILE__), (int) $xml->f('size1.value()')); eq('true', $xml->f('mv1.value()')); eq(filesize(__FILE__), (int) $xml->f('mv_size1.value()')); eq(file_get_contents(__FILE__), $xml->f('data1.value()')); eq(basename(__FILE__), $xml->f('original_name2.value()')); eq(filesize(__FILE__), (int) $xml->f('size2.value()')); eq('true', $xml->f('mv2.value()')); eq(filesize(__FILE__), (int) $xml->f('mv_size2.value()')); eq(file_get_contents(__FILE__), $xml->f('data2.value()')); eq('abcd', $xml->f('get_data1.value()')); eq('efg', $xml->f('get_data2.value()'));
<?php $src = <<<PRE \t\t<aaa> \t\t<bbb id="DEF"></bbb> \t\t<ccc id="ABC"> \t\t<ddd id="XYZ">hoge</ddd> \t\t</ccc> \t\t</aaa> PRE; \org\rhaco\Xml::set($tag, $src); eq("ddd", $tag->id("XYZ")->name()); eq(null, $tag->id("xyz"));
/** * @module org.rhaco.Template */ public function before_template(\org\rhaco\lang\Str $obj) { $src = $obj->get(); if (\org\rhaco\Xml::set($tag, $src, 'body')) { foreach ($tag->in(array('pre', 'cli', 'tree')) as $b) { $plain = $b->plain(); $tag = strtolower($b->name()); $b->escape(false); $caption = $b->in_attr('caption'); $b->rm_attr('caption'); $style = $b->in_attr('style'); if ($tag == 'cli') { $b->name('pre'); $b->attr('style', 'background-color:#fff; color:#000; border-color:#000; padding:5px;' . $style); } else { if ($tag == 'tree') { $b->name('pre'); $b->attr('style', 'padding: 5px; line-height: 20px;' . $style); $b->attr('class', 'prettyprint lang-c'); } else { $b->attr('class', 'prettyprint'); } } if (empty($caption)) { $b->attr('style', 'margin-top: 20px; ' . $b->in_attr('style')); } $value = \org\rhaco\lang\Text::plain($b->value()); $value = preg_replace("/<(rt:.+?)>/ms", "<\\1>", $value); $value = str_replace(array('<php>', '</php>'), array('<?php', '?>'), $value); if (empty($value)) { $value = PHP_EOL; } if ($tag == 'tree') { $tree = array(); $len = 0; $v = ''; foreach (explode("\n", $value) as $k => $line) { if (preg_match("/^(\\s*)([\\.\\w\\{\\}\\[\\]\\(\\)]+)[:]{0,1}(.*)\$/", $line, $m)) { $tree[$k] = array(strlen(str_replace("\t", ' ', $m[1])), trim($m[2]), trim($m[3])); $tree[$k][3] = strlen($tree[$k][1]); if ($len < $tree[$k][3] + $tree[$k][0]) { $len = $tree[$k][3] + $tree[$k][0]; } } } if (!empty($caption)) { $v = $caption . PHP_EOL; } $v .= '.' . PHP_EOL; $last = sizeof($tree) - 1; foreach ($tree as $k => $t) { $v .= str_repeat('| ', $t[0]); $v .= $t[0] > 0 && isset($tree[$k + 1]) && $tree[$k + 1][0] < $t[0] || $k == $last ? '`' : '|'; $v .= '-- ' . $t[1] . str_repeat(' ', $len - $t[3] - $t[0] * 2 + 4) . (empty($t[2]) ? '' : ' .. ') . $t[2] . PHP_EOL; } $b->value($v); $plain = $b->get(); } else { $format = $b->in_attr('format'); $b->rm_attr('format'); if ($format == 'plain') { $plain = $b->get(); } else { $value = str_replace("\t", " ", $value); $value = str_replace(array("<", ">", "'", "\""), array("<", ">", "'", """), $value); $b->value($value); $plain = str_replace(array('$', '='), array('__RTD__', '__RTE__'), $b->get()); } if (!empty($caption)) { $plain = '<div style="margin-top:20px; color:#7a43b6; font-weight: bold;">' . $caption . '</div>' . $plain; } } $src = str_replace($b->plain(), $plain, $src); } } $obj->set($src); }
public static function parse(&$src) { $args = func_get_args(); array_shift($args); $result = array(); \org\rhaco\Xml::set($x, '<:>' . $src . '</:>'); foreach ($x->in('entry') as $in) { $o = new self(); $o->id($in->f('id.value()')); $o->title($in->f('title.value()')); $o->published($in->f('published.value()')); $o->updated($in->f('updated.value()')); $o->issued($in->f('issued.value()')); $value = $in->value(); $o->content = Content::parse($value); $o->summary = Summary::parse($value); $o->link = Link::parse($value); $o->author = Author::parse($value); $result[] = $o; $src = str_replace($in->plain(), '', $src); } return $result; }
<?php $b = new \testman\Browser(); $b->do_get(url('test_index::csrf')); eq(200, $b->status()); meq('<result>', $b->body()); $b->do_post(url('test_index::csrf')); eq(403, $b->status()); meq('<error>', $b->body()); $b->do_get(url('test_index::csrf')); eq(200, $b->status()); meq('<result>', $b->body()); $no = null; if (\org\rhaco\Xml::set($xml, $b->body(), 'csrftoken')) { $no = $xml->value(); } neq(null, $no); $b->vars('csrftoken', $no); $b->do_post(url('test_index::csrf')); eq(200, $b->status()); meq('<result>', $b->body()); $b->do_get(url('test_index::csrf_template')); eq(200, $b->status()); meq('<form><input type="hidden" name="csrftoken"', $b->body()); meq('<form method="post"><input type="hidden" name="csrftoken"', $b->body()); meq('<form method="get"><input type="hidden" name="csrftoken"', $b->body()); meq(sprintf('<form action="%s"><input type="hidden" name="csrftoken"', url('test_index::csrf')), $b->body()); meq('<form action="http://localhost"><input type="text" name="aaa" /></form>', $b->body());
<?php \org\rhaco\Xml::set($xml, '<asd><abc><def><aa>AA</aa><bb>BB</bb><cc>CC</cc></def></abc></asd>'); eq('<asd><abc><def><aa>AA</aa><bb>ZZ</bb><cc>CC</cc></def></abc></asd>', $xml->replace('def/bb', 'ZZ')->get()); eq('<asd><abc><def><aa>AA</aa><bb>BB</bb><cc>CC</cc></def></abc></asd>', $xml->get()); \org\rhaco\Xml::set($xml, '<asd><abc><def><aa>AA</aa><bb>BB</bb><cc>CC</cc></def></abc></asd>'); eq('<asd><abc><def>ZZ</def></abc></asd>', $xml->replace('def', 'ZZ')->get()); \org\rhaco\Xml::set($xml, '<asd><abc><def><aa>AA</aa><bb>BB</bb><cc>CC</cc><dd><aaa>AAA</aaa><bbb>BBB</bbb><ccc>CCC</ccc></dd></def></abc></asd>'); eq('<asd><abc><def><aa>AA</aa><bb>BB</bb><cc>CC</cc><dd><aaa>AAA</aaa><bbb>ZZZ</bbb><ccc>CCC</ccc></dd></def></abc></asd>', $xml->replace('def/dd/bbb', 'ZZZ')->get());
<?php $p = "<abc><def>111</def></abc>"; if (eq(true, \org\rhaco\Xml::set($x, $p))) { eq("abc", $x->name()); } $p = "<abc><def>111</def></abc>"; if (eq(true, \org\rhaco\Xml::set($x, $p, "def"))) { eq("def", $x->name()); eq(111, $x->value()); } $p = "aaaa"; eq(false, \org\rhaco\Xml::set($x, $p)); $p = "<abc>sss</abc>"; eq(false, \org\rhaco\Xml::set($x, $p, "def")); $p = "<abc>sss</a>"; if (eq(true, \org\rhaco\Xml::set($x, $p))) { eq("<abc />", $x->get()); } $p = "<abc>0</abc>"; if (eq(true, \org\rhaco\Xml::set($x, $p))) { eq("abc", $x->name()); eq("0", $x->value()); }
/** * @automap */ public function covered() { $target = $this->in_vars('target'); $filename = $this->in_vars('filename'); $source = file($filename); $modify_date = date('Y/m/d H:i:s', filemtime($filename)); $status = array(); $coverage_modify_date = null; $covered = 0; for ($i = 1; $i <= count($source); $i++) { $status[$i] = 'ignore'; } if (is_file($target) && \org\rhaco\Xml::set($xml, file_get_contents($target), 'coverage')) { foreach ($xml->in('file') as $file) { if ($file->in_attr('name') == $filename) { foreach (explode(',', $file->f('covered_lines.value()')) as $line) { if (isset($status[$line])) { $status[$line] = 'covered'; } } foreach (explode(',', $file->f('uncovered_lines.value()')) as $line) { if (isset($status[$line])) { $status[$line] = 'uncovered'; } } $coverage_modify_date = $file->in_attr('modify_date'); $covered = $file->in_attr('covered'); break; } } } $this->vars('source', $source); $this->vars('filename', basename($filename)); $this->vars('dir', dirname($filename)); $this->vars('status', $status); $this->vars('modify_date', $modify_date); $this->vars('coverage_modify_date', $coverage_modify_date); $this->vars('covered', $covered); }
private function rtif($src) { foreach (array('rt:if', 'rt:notif') as $k => $rttag) { if (strpos($src, $rttag) !== false) { $not = $k === 1 ? '!' : ''; while (\org\rhaco\Xml::set($tag, $src, $rttag)) { $tag->escape(false); if (!$tag->is_attr('param')) { throw new \LogicException('if'); } $arg1 = $this->variable_string($this->parse_plain_variable($tag->in_attr('param'))); if ($tag->is_attr('value')) { $arg2 = $this->parse_plain_variable($tag->in_attr('value')); if ($arg2 == 'true' || $arg2 == 'false' || preg_match('/^-?[0-9]+$/', (string) $arg2)) { $cond = sprintf('<?php if(%s(%s === %s || %s === "%s")){ ?>', $not, $arg1, $arg2, $arg1, $arg2); } else { if ($arg2 === '' || $arg2[0] != '$') { $arg2 = '"' . $arg2 . '"'; } $cond = sprintf('<?php if(%s(%s === %s)){ ?>', $not, $arg1, $arg2); } } else { $uniq = uniqid('$I'); $cond = sprintf('<?php try{ ' . ' %s=%s; ' . '}catch(\\Exception $e){ %s=null; } ?>' . '<?php if(%s(%s !== null && %s !== false && ( (!is_string(%s) && !is_array(%s)) || (is_string(%s) && %s !== "") || (is_array(%s) && !empty(%s)) ) )){ ?>', $uniq, $arg1, $uniq, $not, $uniq, $uniq, $uniq, $uniq, $uniq, $uniq, $uniq, $uniq); } $src = str_replace($tag->plain(), $this->php_exception_catch($cond . preg_replace('/<rt\\:else[\\s]*.*?>/i', '<?php }else{ ?>', $tag->value()) . '<?php } ?>'), $src); } } } return $src; }