38 $this->collectIdentifiedElements();
39 $this->processReferences();
50 public function findByElement(\DOMElement $element, $considerChildren =
false)
52 foreach ($this->subjects as $subject) {
54 $element === $subject->getElement()
75 function (
Subject $subject) use ($elementId) {
84 protected function collectIdentifiedElements()
87 $elements = $this->xPath->query(
'//*[@id]');
88 foreach ($elements as $element) {
89 $this->subjects[$element->getAttribute(
'id')] =
new Subject($element, $this->useNestingLimit);
97 protected function processReferences()
99 $useNodeName = $this->xPath->createNodeName(
'use');
100 foreach ($this->subjects as $subject) {
101 $useElements = $this->xPath->query(
102 $useNodeName .
'[@href or @xlink:href]',
103 $subject->getElement()
107 foreach ($useElements as $useElement) {
111 if ($useId ===
null || !isset($this->subjects[$useId])) {
114 $subject->addUse($this->subjects[$useId]);
115 $this->subjects[$useId]->addUsedIn($subject);
125 foreach ($this->subjects as $subject) {
127 if (in_array($subject->getElement(), $this->elementsToRemove)) {
136 if ($useId === $subject->getElementId()) {
138 } elseif ($subject->hasInfiniteLoop()) {
164 $this->elementsToRemove = array_merge(
165 $this->elementsToRemove,
An exception for terminatinating execution or to throw for unit testing.
__construct(XPath $xPath, $useNestingLimit)
determineInvalidSubjects()
Determines and tags infinite loops.
findByElement(\DOMElement $element, $considerChildren=false)
Resolves one subject by element.
getElementsToRemove()
Get all the elements that caused a nesting exception.
findByElementId($elementId)
Resolves subjects (plural!) by element id - in theory malformed DOM might have same ids assigned to d...
markSubjectAsInvalid(Subject $subject)
The Subject is invalid for some reason, therefore we should remove it and all it's child usages.
clearInternalAndGetAffectedElements()
Clear the internal arrays (to free up memory as they can get big) and return all the child usages DOM...
getElement()
Get the element that caused the exception.
static extractIdReferenceFromHref($href)
static isElementContainedIn(\DOMElement $needle, \DOMElement $haystack)
static getElementHref(\DOMElement $element)