private function getOptionsFromElement(Element $element) { if (!$element->hasChildren()) { return true; } $result = []; foreach ($element as $child) { if ($child instanceof Text) { return $child->getText(); } if ($child instanceof Element) { $result[$child->getName()] = $this->getOptionsFromElement($child); } } return $result; }
public static function fromFile($path, $encoding = null, $html = false) { if ($html) { return HtmlElement::fromFile($path, $encoding); } return Element::fromFile($path, $encoding); }
/** * @param resource $parser * @param string $text */ protected function handleText($parser, $text) { $text = trim($text); if (empty($text)) { return; } if (!$this->currentElement) { $this->throwException("Unexpected text, expected element"); } $textClass = static::$textClassName; $this->currentElement->appendChild(new $textClass($text)); }
public function matches(Element $element) { if ($this->name && $this->name !== '*' && $element->getName() !== $this->name) { return false; } if ($this->id && (!$element->hasId() || $element->getId() !== $this->id)) { return false; } if (!empty($this->classes)) { foreach ($this->classes as $class) { if (!$element->hasClass($class)) { return false; } } } if (!empty($attributes)) { foreach ($attributes as $name => $value) { if (!$element->hasAttribute($name)) { return false; } if ($value !== null && $element->getAttribute($name) !== $value) { return false; } } } if (!empty($this->pseudos)) { foreach ($this->pseudos as $name => $value) { if (!array_key_exists($name, self::$registeredPseudos)) { throw new Exception("Failed to resolve selector: Pseudo {$name} doesnt exist"); } $idx = $element->getIndex(); if (!call_user_func(self::$registeredPseudos[$name], $value, $element, $idx)) { return false; } } } return true; }
public function format(DomFormatter $formatter = null, $level = null) { $formatter = $formatter ? $formatter : new Formatter(); return parent::format($formatter, $level); }