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());