ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
enshrined\svgSanitize\ElementReference\Subject Class Reference
+ Collaboration diagram for enshrined\svgSanitize\ElementReference\Subject:

Public Member Functions

 __construct (\DOMElement $element, $useNestingLimit)
 Subject constructor. More...
 
 getElement ()
 
 getElementId ()
 
 hasInfiniteLoop (array $subjects=[], $level=1)
 
 addUse (Subject $subject)
 
 addUsedIn (Subject $subject)
 
 countUse ($accumulated=false)
 
 countUsedIn ()
 
 clearInternalAndGetAffectedElements ()
 Clear the internal arrays (to free up memory as they can get big) and return all the child usages DOMElement's. More...
 

Protected Attributes

 $element
 
 $useCollection = []
 
 $usedInCollection = []
 
 $useNestingLimit
 

Detailed Description

Definition at line 4 of file Subject.php.

Constructor & Destructor Documentation

◆ __construct()

enshrined\svgSanitize\ElementReference\Subject::__construct ( \DOMElement  $element,
  $useNestingLimit 
)

Subject constructor.

Parameters
\DOMElement$element
int$useNestingLimit

Definition at line 32 of file Subject.php.

33 {
34 $this->element = $element;
35 $this->useNestingLimit = $useNestingLimit;
36 }

References enshrined\svgSanitize\ElementReference\Subject\$element, and enshrined\svgSanitize\ElementReference\Subject\$useNestingLimit.

Member Function Documentation

◆ addUse()

enshrined\svgSanitize\ElementReference\Subject::addUse ( Subject  $subject)
Parameters
Subject$subject

Definition at line 81 of file Subject.php.

82 {
83 if ($subject === $this) {
84 throw new \LogicException('Cannot add self usage', 1570713416);
85 }
86 $identifier = $subject->getElementId();
87 if (isset($this->useCollection[$identifier])) {
88 $this->useCollection[$identifier]->increment();
89 return;
90 }
91 $this->useCollection[$identifier] = new Usage($subject);
92 }

References enshrined\svgSanitize\ElementReference\Subject\getElementId().

+ Here is the call graph for this function:

◆ addUsedIn()

enshrined\svgSanitize\ElementReference\Subject::addUsedIn ( Subject  $subject)
Parameters
Subject$subject

Definition at line 97 of file Subject.php.

98 {
99 if ($subject === $this) {
100 throw new \LogicException('Cannot add self as usage', 1570713417);
101 }
102 $identifier = $subject->getElementId();
103 if (isset($this->usedInCollection[$identifier])) {
104 $this->usedInCollection[$identifier]->increment();
105 return;
106 }
107 $this->usedInCollection[$identifier] = new Usage($subject);
108 }

References enshrined\svgSanitize\ElementReference\Subject\getElementId().

+ Here is the call graph for this function:

◆ clearInternalAndGetAffectedElements()

enshrined\svgSanitize\ElementReference\Subject::clearInternalAndGetAffectedElements ( )

Clear the internal arrays (to free up memory as they can get big) and return all the child usages DOMElement's.

Returns
array

Definition at line 142 of file Subject.php.

143 {
144 $elements = array_map(function(Usage $usage) {
145 return $usage->getSubject()->getElement();
147
148 $this->usedInCollection = [];
149 $this->useCollection = [];
150
151 return $elements;
152 }

References enshrined\svgSanitize\ElementReference\Subject\$useCollection, enshrined\svgSanitize\ElementReference\Subject\getElement(), and enshrined\svgSanitize\ElementReference\Usage\getSubject().

Referenced by enshrined\svgSanitize\ElementReference\Resolver\markSubjectAsInvalid().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ countUse()

enshrined\svgSanitize\ElementReference\Subject::countUse (   $accumulated = false)
Parameters
bool$accumulated
Returns
int

Definition at line 114 of file Subject.php.

115 {
116 $count = 0;
117 foreach ($this->useCollection as $use) {
118 $useCount = $use->getSubject()->countUse();
119 $count += $use->getCount() * ($accumulated ? 1 + $useCount : max(1, $useCount));
120 }
121 return $count;
122 }

◆ countUsedIn()

enshrined\svgSanitize\ElementReference\Subject::countUsedIn ( )
Returns
int

Definition at line 127 of file Subject.php.

128 {
129 $count = 0;
130 foreach ($this->usedInCollection as $usedIn) {
131 $count += $usedIn->getCount() * max(1, $usedIn->getSubject()->countUsedIn());
132 }
133 return $count;
134 }

◆ getElement()

enshrined\svgSanitize\ElementReference\Subject::getElement ( )

◆ getElementId()

enshrined\svgSanitize\ElementReference\Subject::getElementId ( )
Returns
string

Definition at line 49 of file Subject.php.

50 {
51 return $this->element->getAttribute('id');
52 }

Referenced by enshrined\svgSanitize\ElementReference\Subject\addUse(), enshrined\svgSanitize\ElementReference\Subject\addUsedIn(), and enshrined\svgSanitize\ElementReference\Resolver\findByElementId().

+ Here is the caller graph for this function:

◆ hasInfiniteLoop()

enshrined\svgSanitize\ElementReference\Subject::hasInfiniteLoop ( array  $subjects = [],
  $level = 1 
)
Parameters
array$subjectsPreviously processed subjects
int$levelThe current level of nesting.
Returns
bool
Exceptions

enshrined\svgSanitize\Exceptions\NestingException

Definition at line 60 of file Subject.php.

61 {
62 if ($level > $this->useNestingLimit) {
63 throw new \enshrined\svgSanitize\Exceptions\NestingException('Nesting level too high, aborting', 1570713498, null, $this->getElement());
64 }
65
66 if (in_array($this, $subjects, true)) {
67 return true;
68 }
69 $subjects[] = $this;
70 foreach ($this->useCollection as $usage) {
71 if ($usage->getSubject()->hasInfiniteLoop($subjects, $level + 1)) {
72 return true;
73 }
74 }
75 return false;
76 }

References enshrined\svgSanitize\ElementReference\Subject\getElement().

+ Here is the call graph for this function:

Field Documentation

◆ $element

enshrined\svgSanitize\ElementReference\Subject::$element
protected

◆ $useCollection

enshrined\svgSanitize\ElementReference\Subject::$useCollection = []
protected

◆ $usedInCollection

enshrined\svgSanitize\ElementReference\Subject::$usedInCollection = []
protected

Definition at line 19 of file Subject.php.

◆ $useNestingLimit

enshrined\svgSanitize\ElementReference\Subject::$useNestingLimit
protected

The documentation for this class was generated from the following file: