Beispiel #1
0
 /**
  * @plugin ebi.Flow
  * @param \Exception $exception
  */
 public function flow_exception(\Exception $exception)
 {
     if (!$exception instanceof \ebi\Exceptions) {
         $exception = ['' => $exception];
     }
     if (strpos(strtolower((new \ebi\Env())->get('HTTP_ACCEPT')), 'application/json') !== false) {
         $message = [];
         foreach ($exception as $g => $e) {
             $em = ['message' => $e->getMessage(), 'type' => basename(str_replace("\\", '/', get_class($e)))];
             if (!empty($g)) {
                 $em['group'] = $g;
             }
             $message[] = $em;
         }
         \ebi\HttpHeader::send('Content-Type', 'application/json');
         print \ebi\Json::encode(['error' => $message]);
     } else {
         $xml = new \ebi\Xml('error');
         foreach ($exception as $g => $e) {
             $message = new \ebi\Xml('message', $e->getMessage());
             $type = basename(str_replace("\\", '/', get_class($e)));
             if (!empty($g)) {
                 $message->add('group', $g);
             }
             $message->add('type', $type);
             $xml->add($message);
         }
         \ebi\HttpHeader::send('Content-Type', 'application/xml');
         /**
          * @param string $encoding XML宣言のencoding
          */
         print $xml->get(\ebi\Conf::get('encoding'));
     }
 }
Beispiel #2
0
<?php

$x = new \ebi\Xml("test");
$x->value("abc");
eq("abc", $x->value());
$x->add("def");
eq("abcdef", $x->value());
$x->add(new \ebi\Xml("b", "123"));
eq("abcdef<b>123</b>", $x->value());
Beispiel #3
0
<?php

$xml = new \ebi\Xml("test");
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 \ebi\Xml("b", "123")));
$xml = new \ebi\Xml("test");
$xml->escape(false);
eq("<abc>123</abc>", $xml->value("<abc>123</abc>", false));
$xml = new \ebi\Xml("test");
$add = new \ebi\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 \ebi\Xml("test");
$add = new \ebi\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());
Beispiel #4
0
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));
// is
$x = new \ebi\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"));
//set
$x = new \ebi\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("<aaa>", $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);
Beispiel #5
0
eq('<abc><aaa>hoge</aaa><ccc>123</ccc></abc>', $self->get());
$n = explode('\\', get_class($obj));
$n = array_pop($n);
$obj1 = clone $obj;
$obj2 = clone $obj;
$obj3 = clone $obj;
$obj2->ccc(456);
$obj3->ccc(789);
$arr = array($obj1, $obj2, $obj3);
$self = new \ebi\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());
$obj = new \ebi\Request();
$obj->rm_vars();
$obj->vars('aaa', 'hoge');
$obj->vars('ccc', 123);
$self = new \ebi\Xml('abc', $obj);
eq('<abc><aaa>hoge</aaa><ccc>123</ccc></abc>', $self->get());
$src = "<tag><abc><def var='123'><ghi selected>hoge</ghi></def></abc></tag>";
$tag = \ebi\Xml::extract($src, 'tag');
eq("hoge", $tag->find_get("abc/def/ghi")->value());
eq("123", $tag->find_get("abc/def")->in_attr('var'));
eq("selected", $tag->find_get("abc/def/ghi")->in_attr('selected'));
eq("<def var='123'><ghi selected>hoge</ghi></def>", $tag->find_get("abc/def")->plain());
try {
    $tag->find_get("abc/def/xyz");
    fail();
} catch (\ebi\exception\NotFoundException $e) {
}
$src = <<<'PRE'
<tag>
<abc>
Beispiel #6
0
<?php

$x = new \ebi\Xml("test", 123);
eq("<test>123</test>", $x->get());
$x = new \ebi\Xml("test", new \ebi\Xml("hoge", "AAA"));
eq("<test><hoge>AAA</hoge></test>", $x->get());
$x = new \ebi\Xml("test");
eq("<test />", $x->get());
$x = new \ebi\Xml("test");
$x->close_empty(false);
eq("<test></test>", $x->get());
$x = new \ebi\Xml("test");
$x->attr("abc", 123);
$x->attr("def", 456);
eq('<test abc="123" def="456" />', $x->get());