コード例 #1
0
 /**
  * Return plugin result = $plugin->tok_NAME($param, $arg).
  * If callback mode is not TokPlugin::TOKCALL preprocess param and arg. Example:
  *
  * Convert param into vector and arg into map if plugin $name is configured with
  * TokPlugin::KV_BODY | TokPlugin::PARAM_CSLIST | TokPlugin::REQUIRE_BODY | TokPlugin::REQUIRE_PARAM 
  *
  * @throws rkphplib\Exception 'plugin parameter missing', 'invalid plugin parameter', 'plugin body missing', 'invalid plugin body'
  * @param string $name
  * @param string $param
  * @param string $arg (default = null = no argument)
  * @return string
  */
 private function _call_plugin($name, $param, $arg = null)
 {
     if ($this->_plugin[$name][1] & TokPlugin::TOKCALL) {
         return call_user_func(array($this->_plugin[$name][0], 'tokCall'), $name, $param, $arg);
     }
     $func = 'tok_' . $name;
     $pconf = $this->_plugin[$name][1];
     $plen = strlen($param);
     $alen = strlen($arg);
     if (!empty($this->_plugin["{$name}:{$param}"])) {
         $func = 'tok_' . $name . '_' . $param;
         $pconf = $this->_plugin["{$name}:{$param}"][1];
         $plen = 0;
     }
     if ($pconf & TokPlugin::REQUIRE_PARAM && $plen == 0) {
         throw new Exception('plugin parameter missing', "plugin={$name}");
     } else {
         if ($pconf & TokPlugin::NO_PARAM && $plen > 0) {
             throw new Exception('invalid plugin parameter', "plugin={$name} param={$param}");
         }
     }
     if ($pconf & TokPlugin::REQUIRE_BODY && $alen == 0) {
         throw new Exception('plugin body missing', "plugin={$name}");
     } else {
         if ($pconf & TokPlugin::NO_BODY && $alen > 0) {
             throw new Exception('invalid plugin body', "plugin={$name} arg={$arg}");
         }
     }
     if ($pconf & TokPlugin::PARAM_LIST || $pconf & TokPlugin::PARAM_CSLIST) {
         require_once __DIR__ . '/lib/split_str.php';
         $delim = $pconf & TokPlugin::PARAM_LIST ? ':' : ',';
         $param = lib\split_str($delim, $param);
     }
     if ($pconf & TokPlugin::KV_BODY) {
         require_once __DIR__ . '/lib/conf2kv.php';
         $arg = lib\conf2kv($arg);
     } else {
         if ($pconf & TokPlugin::JSON_BODY) {
             require_once __DIR__ . '/JSON.class.php';
             $arg = JSON::decode($arg);
         } else {
             if ($pconf & TokPlugin::CSLIST_BODY || $pconf & TokPlugin::LIST_BODY) {
                 require_once __DIR__ . '/lib/split_str.php';
                 $delim = $pconf & TokPlugin::CSLIST_BODY ? ',' : '|#|';
                 $arg = lib\split_str($delim, $arg);
             } else {
                 if ($pconf & TokPlugin::XML_BODY) {
                     require_once __DIR__ . '/XML.class.php';
                     $arg = XML::toJSON($arg);
                 }
             }
         }
     }
     $res = '';
     if ($pconf & TokPlugin::NO_PARAM) {
         $res = call_user_func(array($this->_plugin[$name][0], $func), $arg);
     } else {
         if ($pconf & TokPlugin::NO_BODY) {
             $res = call_user_func(array($this->_plugin[$name][0], $func), $param);
         } else {
             $res = call_user_func(array($this->_plugin[$name][0], $func), $param, $arg);
         }
     }
     return $res;
 }
コード例 #2
0
ファイル: todo.php プロジェクト: RolandKujundzic/rkphplib
$xml = <<<END
<?xml version="1.0" encoding="UTF-8"?>
<json2xml>
\t<names>a</names>
\t<names>b</names>
\t<names>c</names>
\t<id>a</id>
\t<id>b</id>
\t<id>c</id>
</json2xml>
END;
$xml2 = <<<END
<?xml version="1.0" encoding="UTF-8"?>
<json2xml>
  <Liste>
    <Liste>Roland</Liste>
    <Liste>Peter</Liste>
    <Liste>Mario</Liste>
  </Liste>
  <Liste2>
    <Liste2>A</Liste2>
    <Liste2>B</Liste2>
    <Liste2>C</Liste2>
  </Liste2>
</json2xml>
END;
print XML::fromJSON(XML::toJSON($xml)) . "\n\n";
print XML::fromJSON(XML::toJSON($xml2)) . "\n\n";
print XML::fromJSON('Hallo') . "\n";
print XML::fromJSON(['Hallo' => '', 'Welt' => '']) . "\n";
print XML::fromJSON(['Liste' => ['Roland', 'Peter', 'Mario'], 'Liste2' => ['A', 'B', 'C']]) . "\n";