Symfony\Component\DomCrawler\Crawler::parents PHP Method

parents() public method

Returns the parents nodes of the current selection.
public parents ( ) : Crawler
return Crawler A Crawler instance with the parents nodes of the current selection
    public function parents()
    {
        if (!$this->nodes) {
            throw new \InvalidArgumentException('The current node list is empty.');
        }
        $node = $this->getNode(0);
        $nodes = array();
        while ($node = $node->parentNode) {
            if (XML_ELEMENT_NODE === $node->nodeType) {
                $nodes[] = $node;
            }
        }
        return $this->createSubCrawler($nodes);
    }

Usage Example

コード例 #1
0
 /**
  * get itemprop given value && set the couple in Card
  * 
  * if isItemref is set to true, then only itemprop who have no direct itemscope parent in node will be recorded
  * 
  * @param Crawler $node
  * @param iCard $card
  * @param boolean $isItemref
  * @return boolean
  */
 private function setCardProperty(Crawler $node, CardInterface $card, $isItemref = false)
 {
     $property = $node->attr('itemprop');
     $nd = $node;
     if ($node->parents()->attr('itemscope') !== null) {
         return false;
     }
     if ($this->nestedScope($node, $card, $property, $isItemref)) {
         return true;
     }
     if ($this->manageRawProperty($node, $property, $card)) {
         return true;
     }
     if ($this->manageImgProperty($node, $property, $card)) {
         return true;
     }
     if ($this->manageLinkProperty($node, $property, $card)) {
         return true;
     }
     if ($this->manageNumericProperty($node, $property, $card)) {
         return true;
     }
     if ($isItemref) {
         while (count($nd)) {
             if ($nd->attr('itemscope') !== null) {
                 return true;
             }
             $nd = $nd->parents();
         }
     }
     $card->{$property} = trim($node->text());
 }
All Usage Examples Of Symfony\Component\DomCrawler\Crawler::parents