本文整理汇总了PHP中DOMElement::query方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMElement::query方法的具体用法?PHP DOMElement::query怎么用?PHP DOMElement::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMElement
的用法示例。
在下文中一共展示了DOMElement::query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processVariant
private function processVariant(Variant $variant, \DOMElement $variantEl, array $resultClasses)
{
$errorEls = $variantEl->query('.//error');
if ($errorEls->length) {
$errors = [];
foreach ($errorEls as $errorEl) {
$error = new Error($errorEl->nodeValue, $errorEl->getAttribute('exception-class'), $errorEl->getAttribute('code'), $errorEl->getAttribute('file'), $errorEl->getAttribute('line'), '');
$errors[] = $error;
}
$variant->createErrorStack($errors);
return;
}
foreach ($variantEl->query('./iteration') as $iterationEl) {
$results = [];
foreach ($iterationEl->attributes as $attributeEl) {
$name = $attributeEl->name;
if (false === strpos($name, '-')) {
throw new \RuntimeException(sprintf('Expected attribute name to have a result key prefix, got "%s".', $name));
}
$prefix = substr($name, 0, strpos($name, '-'));
if (!isset($resultClasses[$prefix])) {
throw new \RuntimeException(sprintf('No result class was provided with key "%s" for attribute "%s"', $prefix, $name));
}
$suffix = substr($name, strpos($name, '-') + 1);
$results[$prefix][str_replace('-', '_', $suffix)] = $attributeEl->value;
}
$iteration = $variant->createIteration();
foreach ($results as $resultKey => $resultData) {
$iteration->setResult(call_user_func_array([$resultClasses[$resultKey], 'fromArray'], [$resultData]));
}
}
// TODO: Serialize statistics ..
$variant->computeStats();
}