本文整理汇总了PHP中Xml::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Xml::create方法的具体用法?PHP Xml::create怎么用?PHP Xml::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Xml
的用法示例。
在下文中一共展示了Xml::create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGeneratesXml
public function testGeneratesXml()
{
$package = Package::create(self::$name)->setAuthor('VikiJel')->addExtension('com_test', self::$archive_src)->addLanguage(self::$ini_src)->addUpdateServer('http://example.com', 'testserver')->setScriptfile(self::$php_src);
$instance = Xml::create($package)->init();
$simple_xml = simplexml_load_string((string) $instance);
self::assertEquals('extension', (string) $simple_xml->getName());
self::assertEquals('2.5', (string) $simple_xml->attributes()->version);
self::assertEquals('upgrade', (string) $simple_xml->attributes()->method);
self::assertEquals('package', (string) $simple_xml->attributes()->type);
self::assertEquals('1.0.0', (string) $simple_xml->version);
self::assertEquals(self::$name, (string) $simple_xml->name);
self::assertEquals('package_test', (string) $simple_xml->packagename);
self::assertEquals(date('Y-m-d'), (string) $simple_xml->creationDate);
self::assertEquals('http://example.com', (string) $simple_xml->updateservers->server);
self::assertEquals('testserver', (string) $simple_xml->updateservers->server->attributes()->name);
self::assertEquals(1, (int) $simple_xml->updateservers->server->attributes()->priority);
self::assertEquals('extension', (string) $simple_xml->updateservers->server->attributes()->type);
self::assertEquals('com_test', (string) $simple_xml->files->file->attributes()->id);
self::assertEquals('some_file.zip', (string) $simple_xml->files->file);
self::assertEquals('en-GB.pkg_package_test.ini', (string) $simple_xml->languages->language);
self::assertEquals('en-GB', (string) $simple_xml->languages->language->attributes()->tag);
self::assertEquals('pkg_package_test.php', (string) $simple_xml->scriptfile);
self::assertContains('VikiJel', (string) $simple_xml->copyright);
self::assertContains(date('Y'), (string) $simple_xml->copyright);
self::assertContains('VikiJel', (string) $simple_xml->packager);
self::assertContains('vikijel', (string) $simple_xml->packagerurl);
}
示例2: ajax
/**
* Ajax输出
*
* @param $data 数据
* @param string $type 数据类型 text html xml json
*/
public function ajax($data, $type = "JSON")
{
$type = strtoupper($type);
switch ($type) {
case "HTML":
case "TEXT":
$_data = $data;
break;
case "XML":
//XML处理
header('Content-Type: application/xml');
$_data = Xml::create($data);
break;
default:
//JSON处理
header('Content-Type: application/json');
$_data = json_encode($data);
}
echo $_data;
exit;
}
示例3: xdrRetriveExternal
/**
* Fetches an external dataset.
*
* @param string $strURL The URL or directory of the file
* @param string $strType Declares the type of data (plain*, xml, bean, json)
* @param string $strMethod Loading method for the external resource: open*, get, post
* @return object|string
*/
private function xdrRetriveExternal($strURL, $strType = 'plain', $strMethod = 'open')
{
// TESTING: $this->probe('xdrRetriveExternal', 'Trying to load the external resource now: '.$strURL.'; Method: '.$strMethod.'; Type: '.$strType, 4);
$strData = null;
$strMethod = strtolower($strMethod);
switch ($strMethod) {
case 'get':
if (class_exists('\\REST\\Client')) {
$req = new \REST\Client($strURL);
$strData = $req->post();
} else {
// If the REST library is not present, simply use file_get_contents
$strData = file_get_contents($strURL);
}
break;
case 'post':
if (!class_exists('\\REST\\Client')) {
throw new Exception('Class REST\\Client not found. Please include the library from https://github.com/zeyon/rest');
}
$req = new \REST\Client($strURL);
$strData = $req->post();
break;
default:
$strData = is_readable(self::$basepath . $strURL) ? file_get_contents(self::$basepath . $strURL) : false;
break;
}
if (!$strData) {
return;
}
if ($strType == 'xml') {
return Xml::create($strData);
} elseif ($strType == 'bean') {
return Bean::create($strData);
} elseif ($strType == 'json') {
return json_decode($strData, 1);
} else {
return $strData;
}
}
示例4: ajax
/**
* Ajax输出
* @param $data 数据
* @param string $type 数据类型 text html xml json
*/
protected function ajax($data, $type = "JSON")
{
$type = strtoupper($type);
switch ($type) {
case "HTML":
case "TEXT":
$_data = $data;
break;
case "XML":
//XML处理
$_data = Xml::create($data, "root", "UTF-8");
break;
default:
//JSON处理
$_data = json_encode($data);
}
echo $_data;
exit;
}
示例5: xdr_external
/**
* Fetches an external dataset.
*
* @param string $strURL The URL or directory of the file
* @param string strType Declares the type of data (plain*, xml, bean, json)
* @param string $strMethod Loading method for the external resource: open*, get, post
* @return object|string
*/
private function xdr_external($strURL, $strType = 'plain', $strMethod = 'open')
{
// TESTING: $this->probe('xdr_external', 'Trying to load the external resource now: '.$strURL.'; Method: '.$strMethod.'; Type: '.$strType, 4);
$strData = null;
$strMethod = strtolower($strMethod);
switch ($strMethod) {
case 'get':
case 'post':
if (class_exists('\\REST\\Client')) {
$req = new \REST\Client($strURL);
$strData = $strMethod == 'get' ? $req->get() : $req->post();
}
break;
default:
$strData = is_readable(self::$basepath . $strURL) ? file_get_contents(self::$basepath . $strURL) : false;
break;
}
if (!$strData) {
return;
}
if ($strType == 'xml') {
return Xml::create($strData);
} elseif ($strType == 'bean') {
return Bean::create($strData);
} elseif ($strType == 'json') {
return json_decode($strData, 1);
} else {
return $strData;
}
}
示例6: buildHeaderMenu
public function buildHeaderMenu()
{
global $locale;
$html = '
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container" style="width: auto;">
<a class="brand" href="' . buildLink('clockings') . '" id="loader"><img src="assets/img/logo.png" alt="tymio" /></a>';
// Workaround with catching the exception but
// more pretty would be a function like API->isAuthenticated()
// instead of call complete authentication again (done in index.php)
try {
$authenticator = \APIFactory::getAuthenticator();
$user = $authenticator->authUser();
if ($user !== null) {
$email = strtolower($user->getEmail());
$html .= '<div class="nav-collapse">' . '<ul class="nav">' . $locale->replace($this->compileMenu(Xml::create(APP_DIR . ($user->isAdmin() ? 'menu-admin.xml' : 'menu.xml'), 1))) . '</ul>' . '</div>' . '<div id="login" style="background-image: url(\'https://secure.gravatar.com/avatar/' . md5($email) . '?s=28&d=mm\')">' . 'Logged in as ' . $user->getFQN() . '. <a class="btn btn-mini" href="' . buildLink('logout') . '"><i class="icon icon-off"></i> Logout</a>';
} else {
throw new Exception();
}
} catch (Exception $e) {
$html .= '<div id="login" class="loggedout">Not logged in <a class="btn btn-success btn-mini" href="' . buildLink('login') . '"><i class="icon icon-white icon-lock"></i> Login</a>';
}
$html .= '
</div>
<ul class="nav pull-right">
<li class="divider-vertical"></li>
</ul>
</div>
</div>
</div>';
return $html;
}