/** * Perform the query on Document * * @param string $expression CSS selector or XPath query * @param Document $document Document to query * @param string $type The type of $expression * @return NodeList */ public static function execute($expression, Document $document, $type = self::TYPE_XPATH) { // Expression check if ($type === static::TYPE_CSS) { $expression = static::cssToXpath($expression); } $xpath = new DOMXPath($document->getDomDocument()); $xpathNamespaces = $document->getXpathNamespaces(); foreach ($xpathNamespaces as $prefix => $namespaceUri) { $xpath->registerNamespace($prefix, $namespaceUri); } if ($xpathPhpfunctions = $document->getXpathPhpFunctions()) { $xpath->registerNamespace('php', 'http://php.net/xpath'); $xpathPhpfunctions === true ? $xpath->registerPHPFunctions() : $xpath->registerPHPFunctions($xpathPhpfunctions); } $nodeList = $xpath->queryWithErrorException($expression); return new NodeList($nodeList); }