本文整理汇总了PHP中Datasource::grab方法的典型用法代码示例。如果您正苦于以下问题:PHP Datasource::grab方法的具体用法?PHP Datasource::grab怎么用?PHP Datasource::grab使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datasource
的用法示例。
在下文中一共展示了Datasource::grab方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __executeDatasource
/**
* Executes a data source. Invalid XML is escaped (CDATA) but still
* cached. Prevents persistent cached XML from breaking pages.
*
* @param Datasource $datasource
* The current data source object
* @param int $file_age
* Cache file age (in seconds), passed by reference
*/
private function __executeDatasource($datasource, &$param_pool = array())
{
$result = $datasource->grab($param_pool);
$xml = is_object($result) ? $result->generate(true, 1) : $result;
// Parse DS XML to check for errors. If contains malformed XML such as
// an unescaped database error, the error is escaped in CDATA
$doc = new DOMDocument('1.0', 'utf-8');
libxml_use_internal_errors(true);
$doc->loadXML($xml);
$errors = libxml_get_errors();
libxml_clear_errors();
libxml_use_internal_errors(false);
// No error, just return the result
if (empty($errors)) {
return $result;
}
// There's an error, so $doc will be empty
// Use regex to get the root node
// If something's wrong, just push back the broken XML
if (!preg_match('/<([^ \\/>]+)/', $xml, $matches)) {
return $result;
}
$ret = new XMLElement($matches[1]);
// Set the invalid flag
$ret->setAttribute("xml-invalid", "true");
$errornode = new XMLElement("errors");
// Store the errors
foreach ($errors as $error) {
$item = new XMLElement("error", trim($error->message));
$item->setAttribute('line', $error->line);
$item->setAttribute('column', $error->column);
$errornode->appendChild($item);
}
$ret->appendChild($errornode);
// Return the XML
$ret->appendChild(new XMLElement('broken-xml', "<![CDATA[" . $xml . "]]>"));
return $ret;
}