Exemplo n.º 1
0
 public function xml()
 {
     $bool = false;
     $result = new \org\rhaco\Xml('content');
     foreach ($this->props() as $name => $value) {
         if (!empty($value)) {
             $bool = true;
             switch ($name) {
                 case 'type':
                 case 'mode':
                     $result->attr($name, $value);
                     break;
                 case 'lang':
                 case 'base':
                     $result->attr('xml:' . $name, $value);
                     break;
                 case 'value':
                     $result->value($this->{$name}());
                     break;
             }
         }
     }
     if (!$bool) {
         throw new \org\rhaco\net\xml\atom\NotfoundException();
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * @module org.rhaco.Flow
  * @param mixed $obj
  */
 public function flow_exception_output($obj, \Exception $exception)
 {
     \org\rhaco\Log::disable_display();
     $xml = new \org\rhaco\Xml('error');
     if ($exception instanceof \org\rhaco\Exceptions) {
         foreach (\org\rhaco\Exceptions::gets() as $g => $e) {
             $message = new \org\rhaco\Xml('message', $e->getMessage());
             $message->add('group', $g);
             $message->add('type', basename(str_replace("\\", '/', get_class($e))));
             $xml->add($message);
         }
     } else {
         $message = new \org\rhaco\Xml('message', $exception->getMessage());
         $message->add('group', 'exceptions');
         $message->add('type', basename(str_replace("\\", '/', get_class($exception))));
         $xml->add($message);
     }
     $xml->output();
 }
Exemplo n.º 3
0
 public function xml()
 {
     $bool = false;
     $result = new \org\rhaco\Xml('link');
     foreach ($this->props() as $name => $value) {
         if (!empty($value)) {
             $bool = true;
             switch ($name) {
                 case 'href':
                 case 'rel':
                 case 'type':
                     $result->attr($name, $value);
                     break;
             }
         }
     }
     if (!$bool) {
         throw new \org\rhaco\net\xml\atom\NotfoundException();
     }
     return $result;
 }
Exemplo n.º 4
0
 public function xml()
 {
     $bool = false;
     $result = new \org\rhaco\Xml('author');
     foreach ($this->props() as $name => $value) {
         if (!empty($value)) {
             $bool = true;
             switch ($name) {
                 case 'name':
                 case 'url':
                 case 'email':
                     $result->add(new \org\rhaco\Xml($name, $value));
                     break;
             }
         }
     }
     if (!$bool) {
         throw new \org\rhaco\net\xml\atom\NotfoundException();
     }
     return $result;
 }
Exemplo n.º 5
0
 public function xml()
 {
     $bool = false;
     $result = new \org\rhaco\Xml('entry');
     foreach ($this->props() as $name => $value) {
         if (!empty($value)) {
             $bool = true;
             switch ($name) {
                 case 'xmlns':
                     $result->attr('xmlns', $value);
                     break;
                 case 'id':
                 case 'title':
                     $result->add(new \org\rhaco\Xml($name, $value));
                     break;
                 case 'published':
                 case 'updated':
                 case 'issued':
                     $result->add(new \org\rhaco\Xml($name, \org\rhaco\lang\Date::format_atom($value)));
                     break;
                 default:
                     if (is_array($value)) {
                         foreach ($value as $v) {
                             try {
                                 $result->add($v instanceof \org\rhaco\net\xml\atom\Object ? $v->xml() : (string) $v);
                             } catch (\org\rhaco\net\xml\atom\NotfoundException $e) {
                             }
                         }
                     } else {
                         if (is_object($value)) {
                             try {
                                 $result->add($value instanceof \org\rhaco\net\xml\atom\Object ? $value->xml() : $value);
                             } catch (\org\rhaco\net\xml\atom\NotfoundException $e) {
                             }
                         } else {
                             $result->add(new \org\rhaco\Xml($name, $value));
                             break;
                         }
                     }
             }
         }
     }
     if (!$bool) {
         throw new \org\rhaco\net\xml\atom\NotfoundException();
     }
     return $result;
 }
Exemplo n.º 6
0
eq(array("abc" => 123, "def" => 456, "ghi" => 789), iterator_to_array($x));
$x->rm_attr("def");
eq(array("abc" => 123, "ghi" => 789), iterator_to_array($x));
$x->attr("def", 456);
eq(array("abc" => 123, "ghi" => 789, "def" => 456), iterator_to_array($x));
$x->rm_attr("abc", "ghi");
eq(array("def" => 456), iterator_to_array($x));
$x = new \org\rhaco\Xml("test");
eq(false, $x->is_attr("abc"));
$x->attr("abc", 123);
eq(true, $x->is_attr("abc"));
$x->attr("abc", null);
eq(true, $x->is_attr("abc"));
$x->rm_attr("abc");
eq(false, $x->is_attr("abc"));
$x = new \org\rhaco\Xml("test");
$x->escape(true);
$x->attr("abc", 123);
eq(123, $x->in_attr("abc"));
$x->attr("Abc", 456);
eq(456, $x->in_attr("abc"));
$x->attr("DEf", 555);
eq(555, $x->in_attr("def"));
eq(456, $x->in_attr("abc"));
$x->attr("Abc", "<aaa>");
eq("&lt;aaa&gt;", $x->in_attr("abc"));
$x->attr("Abc", true);
eq("true", $x->in_attr("abc"));
$x->attr("Abc", false);
eq("false", $x->in_attr("abc"));
$x->attr("Abc", null);
Exemplo n.º 7
0
 /**
  * 出力する
  * @param array $map
  */
 public function output($map_array)
 {
     $args = func_get_args();
     $pathinfo = preg_replace("/(.*?)\\?.*/", "\\1", isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : null);
     /**
      * ハンドリングマップ配列を取得する
      * @return array
      */
     $map = $this->has_object_module('flow_map_loader') ? call_user_func_array(array($this, 'object_module'), array_merge(array('flow_map_loader'), $args)) : $map_array;
     if (is_string($map) && preg_match('/^[\\w\\.]+$/', $map)) {
         $map = array('patterns' => array('' => array('action' => $map)));
     }
     $apps = $urls = array();
     $idx = $pkg_id = 0;
     $put_block = null;
     if (isset($map['patterns']) && is_array($map['patterns'])) {
         $exp_patterns = array();
         foreach ($map['patterns'] as $k => $v) {
             if (is_int($k) || isset($map['patterns'][$k]['patterns'])) {
                 if (!empty($map['patterns'][$k])) {
                     $maps = $map['patterns'][$k];
                     unset($map['patterns'][$k]);
                     if (!isset($maps['patterns']) || !is_array($maps['patterns'])) {
                         throw new \InvalidArgumentException('patterns not found');
                     }
                     $maps_url = is_int($k) ? null : $k . '/';
                     $maps_nam = isset($maps['name']) ? $maps['name'] : null;
                     $maps_act = isset($maps['action']) ? $maps['action'] : null;
                     $maps_med = isset($maps['media_path']) ? $maps['media_path'] : null;
                     $maps_tem = isset($maps['template_path']) ? $maps['template_path'] : null;
                     $maps_err = isset($maps['error_template']) ? $maps['error_template'] : null;
                     $maps_sup = isset($maps['template_super']) ? $maps['template_super'] : null;
                     $maps_mod = isset($maps['modules']) && !empty($maps['modules']) ? is_array($maps['modules']) ? $maps['modules'] : array($maps['modules']) : array();
                     $maps_arg = isset($maps['args']) && !empty($maps['args']) ? is_array($maps['args']) ? $maps['args'] : array($maps['args']) : array();
                     foreach ($maps['patterns'] as $u => $m) {
                         if (!empty($maps_act) && isset($m['action'])) {
                             $m['action'] = $maps_act . '::' . $m['action'];
                         }
                         if (!empty($maps_nam)) {
                             $m['name'] = $maps_nam . (isset($m['name']) && !empty($m['name']) ? '/' . $m['name'] : '');
                         }
                         if (!empty($maps_med)) {
                             $m['media_path'] = $maps_med;
                         }
                         if (!empty($maps_tem)) {
                             $m['template_path'] = $maps_tem;
                         }
                         if (!empty($maps_err)) {
                             $m['error_template'] = $maps_err;
                         }
                         if (!empty($maps_sup)) {
                             $m['template_super'] = $maps_sup;
                         }
                         if (!empty($maps_mod)) {
                             $m['modules'] = array_merge($maps_mod, isset($m['modules']) ? is_array($m['modules']) ? $m['modules'] : array($m['modules']) : array());
                         }
                         if (!empty($maps_arg)) {
                             $m['args'] = array_merge($maps_arg, isset($m['args']) ? is_array($m['args']) ? $m['args'] : array($m['args']) : array());
                         }
                         $exp_patterns[$maps_url . $u] = $m;
                     }
                 }
             } else {
                 $exp_patterns[$k] = $v;
             }
         }
         $map['patterns'] = $exp_patterns;
         foreach ($map['patterns'] as $k => $v) {
             if (preg_match('/^(.*)\\$(.+)$/', $k, $m)) {
                 list($k, $v['name']) = array(trim($m[1]), trim($m[2]));
             }
             if (substr($k, 0, 1) == '/') {
                 $k = substr($k, 1);
             }
             if (substr($k, -1) == '/') {
                 $k = substr($k, 0, -1);
             }
             if (is_string($v)) {
                 $v = array('class' => $v);
             }
             if (!isset($v['name'])) {
                 $v['name'] = $k;
             }
             if (isset($v['action'])) {
                 if (strpos($v['action'], '::') !== false) {
                     list($v['class'], $v['method']) = explode('::', $v['action']);
                 } else {
                     $v['class'] = $v['action'];
                 }
                 unset($v['action']);
             }
             if (isset($v['class']) && !isset($v['method'])) {
                 try {
                     $pkg_id++;
                     $n = isset($v['name']) ? $v['name'] : $v['class'];
                     $r = new \ReflectionClass(str_replace('.', "\\", $v['class']));
                     $suffix = isset($v['suffix']) ? $v['suffix'] : '';
                     $automaps = $methodmaps = array();
                     foreach ($r->getMethods() as $m) {
                         if ($m->isPublic() && !$m->isStatic() && substr($m->getName(), 0, 1) != '_') {
                             $automap = (bool) preg_match('/@automap[\\s]*/', $m->getDocComment());
                             if (empty($automaps) || $automap) {
                                 $url = $k . ($m->getName() == 'index' ? '' : ($k == '' ? '' : '/') . $m->getName()) . str_repeat('/(.+)', $m->getNumberOfRequiredParameters());
                                 $auto_anon = array();
                                 if ($automap) {
                                     if (preg_match('/@automap\\s.*@(\\[.*\\])/', $m->getDocComment(), $a)) {
                                         if (preg_match_all('/([\\"\']).+?\\1/', $a[1], $dm)) {
                                             foreach ($dm[0] as $dv) {
                                                 $a[1] = str_replace($dv, str_replace(array('[', ']'), array('#{#', '#}#'), $dv), $a[1]);
                                             }
                                         }
                                         $auto_anon = @eval('return ' . str_replace(array('[', ']', '#{#', '#}#'), array('array(', ')', '[', ']'), $a[1]) . ';');
                                         if (!is_array($auto_anon)) {
                                             throw new \InvalidArgumentException($r->getName() . '::' . $m->getName() . ' automap annotation error');
                                         }
                                     }
                                 }
                                 for ($i = 0; $i <= $m->getNumberOfParameters() - $m->getNumberOfRequiredParameters(); $i++) {
                                     $p = is_dir(substr($r->getFilename(), 0, -4)) ? substr($r->getFilename(), 0, -4) : dirname($r->getFilename());
                                     $mapvar = array_merge($v, array('name' => $n . '/' . $m->getName(), 'class' => $v['class'], 'method' => $m->getName(), 'num' => $i, '@' => $p, 'pkg_id' => $pkg_id));
                                     if ($automap) {
                                         if (!empty($auto_anon)) {
                                             $mapvar = array_merge($mapvar, $auto_anon);
                                             if (empty($suffix) && isset($mapvar['suffix'])) {
                                                 $suffix = $mapvar['suffix'];
                                             }
                                         }
                                         $automaps[$url . $suffix] = $mapvar;
                                     } else {
                                         $methodmaps[$url . $suffix] = $mapvar;
                                     }
                                     $url .= '/(.+)';
                                 }
                             }
                         }
                     }
                     $apps = array_merge($apps, empty($automaps) ? $methodmaps : $automaps);
                     unset($automaps, $methodmaps);
                 } catch (\ReflectionException $e) {
                     throw new \InvalidArgumentException($v['class'] . ' not found');
                 }
             } else {
                 $apps[(string) $k] = $v;
             }
         }
         list($url, $surl) = array($this->branch_url, str_replace('http://', 'https://', $this->branch_url));
         $map_secure = isset($map['secure']) && $map['secure'] === true;
         $conf_secure = \org\rhaco\Conf::get('secure', true) === true;
         foreach ($apps as $u => $m) {
             $m['secure'] = $conf_secure && (isset($m['secure']) && $m['secure'] === true || !isset($m['secure']) && $map_secure);
             $cnt = 0;
             $fu = \org\rhaco\net\Path::absolute($m['secure'] ? $surl : $url, empty($u) ? '' : substr(preg_replace_callback("/([^\\\\])(\\(.*?[^\\\\]\\))/", function ($n) {
                 return $n[1] . '%s';
             }, ' ' . $u, -1, $cnt), 1));
             foreach (array('template_path', 'media_path') as $k) {
                 if (isset($map[$k]) || isset($m[$k])) {
                     $m[$k] = \org\rhaco\net\Path::slash(isset($map[$k]) ? $map[$k] : '', null, true) . (isset($m[$k]) ? $m[$k] : '');
                 }
             }
             $apps[$u] = array_merge($m, array('url' => $u, 'format' => $fu, 'num' => $cnt, 'pattern' => str_replace(array("\\\\", "\\.", '_ESC_'), array('_ESC_', '.', "\\"), $fu)));
         }
         if (self::$get_maps) {
             self::$output_maps[basename($this->entry_file())] = $apps;
             self::$get_maps = false;
             return;
         }
         foreach (array_keys($apps) as $k => $u) {
             $urls[$u] = strlen(preg_replace("/[\\W]/", '', $u));
         }
         arsort($urls);
         krsort($urls);
         if (preg_match("/^\\/" . str_replace("/", "\\/", $this->package_media_url) . "\\/(\\d+)\\/(.+)\$/", $pathinfo, $m) && sizeof($urls) >= $m[1]) {
             for (reset($urls), $i = 0; $i < $m[1]; $i++) {
                 next($urls);
             }
             $v = $apps[key($urls)];
             if (isset($v['@'])) {
                 \org\rhaco\net\http\File::attach($v['@'] . '/resources/media/' . $m[2]);
             }
             \org\rhaco\net\http\Header::send_status(404);
             exit;
         }
         foreach ($urls as $k => $null) {
             if (preg_match("/^" . (empty($k) ? '' : "\\/") . str_replace(array("\\/", '/', '@#S'), array('@#S', "\\/", "\\/"), $k) . '[\\/]{0,1}$/', $pathinfo, $p)) {
                 if (isset($apps[$k]['mode']) && !empty($apps[$k]['mode'])) {
                     $mode = \org\rhaco\Conf::appmode();
                     $mode_alias = \org\rhaco\Conf::get('mode');
                     $bool = false;
                     foreach (explode(',', $apps[$k]['mode']) as $m) {
                         foreach (substr(trim($m), 0, 1) == '@' && isset($mode_alias[substr(trim($m), 1)]) ? explode(',', $mode_alias[substr(trim($m), 1)]) : array($m) as $me) {
                             if ($mode == trim($me)) {
                                 $bool = true;
                                 break;
                             }
                         }
                     }
                     if (!$bool) {
                         break;
                     }
                 }
                 array_shift($p);
                 $obj = $modules = array();
                 $current_url = \org\rhaco\Request::current_url();
                 if (isset($apps[$k]['secure']) && $apps[$k]['secure'] === true && \org\rhaco\Conf::get('secure', true) !== false) {
                     $this->template->secure(true);
                     if (substr($current_url, 0, 5) === 'http:' && (!isset($_SERVER['HTTP_X_FORWARDED_HOST']) || isset($_SERVER['HTTP_X_FORWARDED_PORT']) && $_SERVER['HTTP_X_FORWARDED_PORT'] != 443 || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] != 'https')) {
                         header('Location: ' . preg_replace("/^.+(:\\/\\/.+)\$/", "https\\1", $current_url));
                         exit;
                     }
                 }
                 if (isset($apps[$k]['redirect'])) {
                     header('Location: ' . \org\rhaco\net\Path::absolute($this->branch_url, $apps[$k]['redirect']));
                     exit;
                 }
                 if (isset($map['modules'])) {
                     foreach (is_array($map['modules']) ? $map['modules'] : array($map['modules']) as $m) {
                         $modules[] = $this->str_reflection($m);
                     }
                 }
                 if (isset($apps[$k]['modules'])) {
                     foreach (is_array($apps[$k]['modules']) ? $apps[$k]['modules'] : array($apps[$k]['modules']) as $m) {
                         $modules[] = $this->str_reflection($m);
                     }
                 }
                 try {
                     foreach ($modules as $m) {
                         $this->set_object_module($m);
                     }
                     if (isset($apps[$k]['class'])) {
                         if (!class_exists(str_replace('.', "\\", $apps[$k]['class']))) {
                             throw new \InvalidArgumentException($apps[$k]['class'] . ' not found');
                         }
                         $obj = $this->str_reflection($apps[$k]['class']);
                         $func_exception = null;
                         if ($obj instanceof \org\rhaco\Object) {
                             foreach ($modules as $m) {
                                 $obj->set_object_module($m);
                             }
                         }
                         if ($obj instanceof \org\rhaco\flow\FlowInterface) {
                             $obj->set_select_map_name($apps[$k]['name']);
                             $obj->set_maps($apps);
                             $obj->set_args(isset($apps[$k]['args']) && is_array($apps[$k]['args']) ? $apps[$k]['args'] : array());
                             $ext_modules = $obj->get_template_modules();
                             if (!empty($ext_modules)) {
                                 if (!is_array($ext_modules)) {
                                     $ext_modules = array($ext_modules);
                                 }
                                 foreach ($ext_modules as $o) {
                                     $this->template->set_object_module($o);
                                 }
                             }
                             $obj->before();
                             $put_block = $obj->get_block();
                         }
                         try {
                             $result = call_user_func_array(array($obj, $apps[$k]['method']), $p);
                             if ($result !== null) {
                                 $obj = $result;
                             }
                         } catch (\Exception $e) {
                             $func_exception = $e;
                         }
                         if ($obj instanceof \org\rhaco\flow\FlowInterface) {
                             $obj->after();
                             $put_block = $obj->get_block();
                         }
                         if ($func_exception instanceof \Exception) {
                             throw $func_exception;
                         }
                     }
                     if (isset($apps[$k]['post_after']) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST' && !\org\rhaco\Exceptions::has()) {
                         $this->after_redirect($apps[$k]['post_after'], $apps[$k], $apps, $obj);
                     }
                     if (isset($apps[$k]['after']) && !\org\rhaco\Exceptions::has()) {
                         $this->after_redirect($apps[$k]['after'], $apps[$k], $apps, $obj);
                     }
                     if (isset($apps[$k]['template'])) {
                         $this->print_template($this->template_path, $apps[$k]['template'], $this->media_url, $put_block, $obj, $apps, $k);
                     } else {
                         if (isset($apps[$k]['@']) && is_file($t = $apps[$k]['@'] . '/resources/templates/' . $apps[$k]['method'] . '.html')) {
                             $this->print_template(dirname($t) . '/', basename($t), $this->branch_url . $this->package_media_url . '/' . $idx, $put_block, $obj, $apps, $k, false);
                         } else {
                             if ($this->has_object_module('flow_output')) {
                                 /**
                                  * 結果出力
                                  * @param mixed $obj
                                  */
                                 $this->object_module('flow_output', $obj);
                             } else {
                                 \org\rhaco\Exceptions::throw_over();
                                 $xml = new \org\rhaco\Xml('result', $obj);
                                 $xml->output();
                             }
                         }
                     }
                     exit;
                 } catch (\Exception $e) {
                     if (($level = \org\rhaco\Conf::get('exception_log_level')) !== null && in_array($level, array('error', 'warn', 'info', 'debug'))) {
                         $es = $e instanceof \org\rhaco\Exceptions ? \org\rhaco\Exceptions::gets() : array($e);
                         $ignore = \org\rhaco\Conf::get('exception_log_ignore');
                         foreach ($es as $ev) {
                             $in = true;
                             if (!empty($ignore)) {
                                 foreach (is_array($ignore) ? $ignore : array($ignore) as $p) {
                                     if (($in = !preg_match('/' . str_replace('/', '\\/', $p) . '/', (string) $ev)) === false) {
                                         break;
                                     }
                                 }
                             }
                             if ($in) {
                                 \org\rhaco\Log::$level($ev);
                             }
                         }
                     }
                     if ($this->has_object_module('flow_handle_exception')) {
                         $this->object_module('flow_handle_exception', $e);
                     }
                     if (!$e instanceof \org\rhaco\Exceptions) {
                         \org\rhaco\Exceptions::add($e);
                     }
                     if (isset($apps[$k]['error_status'])) {
                         \org\rhaco\net\http\Header::send_status($apps[$k]['error_status']);
                     } else {
                         if (isset($map['error_status'])) {
                             \org\rhaco\net\http\Header::send_status($map['error_status']);
                         }
                     }
                     if ($this->has_object_module('flow_exception_output')) {
                         /**
                          * 例外発生時の出力
                          * @param mixed $obj actionで返却された値
                          * @param Exception $e 発生した例外
                          */
                         $this->object_module('flow_exception_output', $obj, $e);
                         exit;
                     } else {
                         if (isset($apps[$k]['error_redirect'])) {
                             $this->redirect($apps, $apps[$k]['error_redirect']);
                         } else {
                             if (isset($map['error_redirect'])) {
                                 $this->redirect($apps, $map['error_redirect']);
                             } else {
                                 if (isset($apps[$k]['error_template'])) {
                                     $this->print_template($this->template_path, $apps[$k]['error_template'], $this->media_url, $put_block, $obj, $apps, $k);
                                 } else {
                                     if (isset($map['error_template'])) {
                                         $this->print_template($this->template_path, $map['error_template'], $this->media_url, $put_block, $obj, $apps, $k);
                                     } else {
                                         if (isset($apps[$k]['@']) && is_file($t = $apps[$k]['@'] . '/resources/templates/error.html')) {
                                             $this->print_template(dirname($t) . '/', basename($t), $this->branch_url . $this->package_media_url . '/' . $idx, $put_block, $obj, $apps, $k, false);
                                         } else {
                                             if (isset($apps[$k]['template']) || isset($apps[$k]['@']) && is_file($apps[$k]['@'] . '/resources/templates/' . $apps[$k]['method'] . '.html')) {
                                                 if (!isset($map['error_status'])) {
                                                     \org\rhaco\net\http\Header::send_status(500);
                                                 }
                                                 exit;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $xml = new \org\rhaco\Xml('error');
                     foreach (\org\rhaco\Exceptions::gets() as $g => $e) {
                         $class_name = get_class($e);
                         $message = new \org\rhaco\Xml('message', $e->getMessage());
                         $message->add('group', $g);
                         $message->add('type', basename(str_replace("\\", '/', $class_name)));
                         $xml->add($message);
                     }
                     $xml->output();
                 }
             }
             $idx++;
         }
     }
     if (isset($map['nomatch_redirect'])) {
         $this->redirect($apps, $map['nomatch_redirect']);
     }
     if (($level = \org\rhaco\Conf::get('notfound_log_level')) !== null && in_array($level, array('error', 'warn', 'info', 'debug'))) {
         \org\rhaco\Log::$level(\org\rhaco\Request::current_url() . ' (`' . $pathinfo . '`) bad request');
     }
     \org\rhaco\net\http\Header::send_status(404);
     exit;
 }
Exemplo n.º 8
0
eq("hoge", $xml->value("hoge"));
eq("true", $xml->value(true));
eq("false", $xml->value(false));
eq("<abc>1</abc><def>2</def><ghi>3</ghi>", $xml->value(array("abc" => 1, "def" => 2, "ghi" => 3)));
eq(null, $xml->value(''));
eq(1, $xml->value('1'));
eq(null, $xml->value(null));
$xml->escape(true);
eq("<abc>123</abc>", $xml->value("<abc>123</abc>"));
eq("<b>123</b>", $xml->value(new \org\rhaco\Xml("b", "123")));
$xml = new \org\rhaco\Xml("test");
$xml->escape(false);
eq("<abc>123</abc>", $xml->value("<abc>123</abc>", false));
$obj = new \org\rhaco\Request();
$obj->rm_vars();
$obj->vars('aaa', 'hoge');
$obj->vars('ccc', 123);
$xml = new \org\rhaco\Xml('abc', $obj);
eq('<abc><aaa>hoge</aaa><ccc>123</ccc></abc>', $xml->get());
$xml = new \org\rhaco\Xml("test");
$add = new \org\rhaco\Xml("addxml", "hoge");
$xml->add($add);
$xml->add($add->get());
$xml->add((string) $add);
eq('<test><addxml>hoge</addxml><![CDATA[<addxml>hoge</addxml>]]><![CDATA[<addxml>hoge</addxml>]]></test>', $xml->get());
$xml = new \org\rhaco\Xml("test");
$add = new \org\rhaco\Xml("addxml", "hoge");
$xml->add($add);
$xml->add($add->get());
$xml->add((string) $add);
eq('<test><addxml>hoge</addxml><![CDATA[<addxml>hoge</addxml>]]><![CDATA[<addxml>hoge</addxml>]]></test>', $xml->get());
Exemplo n.º 9
0
<?php

$obj = new \test\model\XmlModel();
$self = new \org\rhaco\Xml('abc', $obj);
eq('<abc><aaa>hoge</aaa><ccc>123</ccc></abc>', $self->get());
$e = explode('\\', get_class($obj));
$n = array_pop($e);
$obj1 = clone $obj;
$obj2 = clone $obj;
$obj3 = clone $obj;
$obj2->ccc(456);
$obj3->ccc(789);
$arr = array($obj1, $obj2, $obj3);
$self = new \org\rhaco\Xml('abc', $arr);
eq(sprintf('<abc>' . '<%s><aaa>hoge</aaa><ccc>123</ccc></%s>' . '<%s><aaa>hoge</aaa><ccc>456</ccc></%s>' . '<%s><aaa>hoge</aaa><ccc>789</ccc></%s>' . '</abc>', $n, $n, $n, $n, $n, $n), $self->get());
Exemplo n.º 10
0
$i = 0;
foreach ($x->in("def") as $d) {
    eq($r[$i], $d->value());
    $i++;
}
$x = new \org\rhaco\Xml("abc", "<def>123</def><abc>ABC</abc><def>456</def><abc>DEF</abc><abc>GHI</abc><def>789</def>");
$r = array(456, 789);
$i = 0;
foreach ($x->in("def", 1) as $d) {
    eq($r[$i], $d->value());
    $i++;
}
$x = new \org\rhaco\Xml("abc", "<def>123</def><abc>ABC</abc><def>456</def><abc>DEF</abc><abc>GHI</abc><def>789</def>");
$r = array(456);
$i = 0;
foreach ($x->in("def", 1, 1) as $d) {
    eq($r[$i], $d->value());
    $i++;
}
$x = new \org\rhaco\Xml("abc", "<def>123</def><abc>ABC</abc><def>456</def><abc>DEF</abc><abc>GHI</abc><def>789</def>");
$i = 0;
foreach ($x->in(array("def", "abc")) as $d) {
    $i++;
}
eq(6, $i);
$x = new \org\rhaco\Xml("abc", "<def>123</def><abc>ABC</abc><def>456</def><abc>DEF</abc><ghi>000</ghi><abc>GHI</abc><def>789</def>");
$i = 0;
foreach ($x->in(array("def", "abc")) as $d) {
    $i++;
}
eq(6, $i);
Exemplo n.º 11
0
 protected function __str__()
 {
     $result = new \org\rhaco\Xml('feed');
     $result->attr('xmlns', self::XMLNS);
     foreach ($this->ar_xmlns() as $ns => $url) {
         $result->attr('xmlns:' . $ns, $url);
     }
     foreach ($this->props() as $name => $value) {
         if (!empty($value)) {
             switch ($name) {
                 case 'title':
                 case 'subtitle':
                 case 'id':
                 case 'generator':
                     $result->add(new \org\rhaco\Xml($name, $value));
                     break;
                 case 'updated':
                     $result->add(new \org\rhaco\Xml($name, \org\rhaco\lang\Date::format_atom($value)));
                     break;
                 default:
                     if (is_array($value)) {
                         foreach ($value as $v) {
                             try {
                                 $result->add($v instanceof \org\rhaco\net\xml\atom\Object ? $v->xml() : $v);
                             } catch (\org\rhaco\net\xml\atom\NotfoundException $e) {
                             }
                         }
                     }
             }
         }
     }
     return $result->get();
 }
Exemplo n.º 12
0
<?php

$x = new \org\rhaco\Xml("test", 123);
eq("<test>123</test>", $x->get());
$x = new \org\rhaco\Xml("test", new \org\rhaco\Xml("hoge", "AAA"));
eq("<test><hoge>AAA</hoge></test>", $x->get());
$x = new \org\rhaco\Xml("test");
eq("<test />", $x->get());
$x = new \org\rhaco\Xml("test");
$x->close_empty(false);
eq("<test></test>", $x->get());
$x = new \org\rhaco\Xml("test");
$x->attr("abc", 123);
$x->attr("def", 456);
eq('<test abc="123" def="456" />', $x->get());
Exemplo n.º 13
0
<?php

$x = new \org\rhaco\Xml("test");
$x->value("abc");
eq("abc", $x->value());
$x->add("def");
eq("abcdef", $x->value());
$x->add(new \org\rhaco\Xml("b", "123"));
eq("abcdef<b>123</b>", $x->value());