本文整理匯總了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();
}