Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Crawler.php

function Crawler::discoverNamespace

Throws

\InvalidArgumentException

1 call to Crawler::discoverNamespace()
Crawler::createDOMXPath in vendor/symfony/dom-crawler/Crawler.php

File

vendor/symfony/dom-crawler/Crawler.php, line 1146

Class

Crawler
Crawler eases navigation of a list of \DOMNode objects.

Namespace

Symfony\Component\DomCrawler

Code

private function discoverNamespace(\DOMXPath $domxpath, string $prefix) : ?string {
    if (\array_key_exists($prefix, $this->namespaces)) {
        return $this->namespaces[$prefix];
    }
    if ($this->cachedNamespaces
        ->offsetExists($prefix)) {
        return $this->cachedNamespaces[$prefix];
    }
    // ask for one namespace, otherwise we'd get a collection with an item for each node
    $namespaces = $domxpath->query(\sprintf('(//namespace::*[name()="%s"])[last()]', $this->defaultNamespacePrefix === $prefix ? '' : $prefix));
    return $this->cachedNamespaces[$prefix] = ($node = $namespaces->item(0)) ? $node->nodeValue : null;
}
RSS feed
Powered by Drupal