ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\MetaData\Paths\Factory Class Reference
+ Inheritance diagram for ILIAS\MetaData\Paths\Factory:
+ Collaboration diagram for ILIAS\MetaData\Paths\Factory:

Public Member Functions

 __construct (StructureSetInterface $structure)
 
 fromString (string $string)
 
 toElement (BaseElementInterface $to, bool $leads_to_exactly_one=false)
 Returns absolute path from root to the given element. More...
 
 betweenElements (BaseElementInterface $from, BaseElementInterface $to, bool $leads_to_exactly_one=false)
 Returns relative path between two given elements. More...
 
 custom ()
 
 fromString (string $string)
 
 toElement (BaseElementInterface $to, bool $leads_to_exactly_one=false)
 Returns absolute path from root to the given element. More...
 
 betweenElements (BaseElementInterface $from, BaseElementInterface $to, bool $leads_to_exactly_one=false)
 Returns relative path between two given elements. More...
 
 custom ()
 

Protected Member Functions

 setModesFromString (BuilderInterface $builder, string $string)
 
 addStepFromString (BuilderInterface $builder, string $string)
 
 addElementAsStep (BuilderInterface $builder, BaseElementInterface $element, bool $leads_to_exactly_one, bool $add_as_first)
 

Protected Attributes

StructureSetInterface $structure
 

Detailed Description

Definition at line 29 of file Factory.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\MetaData\Paths\Factory::__construct ( StructureSetInterface  $structure)

Definition at line 33 of file Factory.php.

34 {
35 $this->structure = $structure;
36 }
StructureSetInterface $structure
Definition: Factory.php:31

References ILIAS\MetaData\Paths\Factory\$structure.

Member Function Documentation

◆ addElementAsStep()

ILIAS\MetaData\Paths\Factory::addElementAsStep ( BuilderInterface  $builder,
BaseElementInterface  $element,
bool  $leads_to_exactly_one,
bool  $add_as_first 
)
protected

Definition at line 174 of file Factory.php.

180 $builder = $builder->withNextStep(
181 $element->getDefinition()->name(),
182 $add_as_first
183 );
184
185 if ($element instanceof StructureElement) {
186 return $builder;
187 }
188 if ($leads_to_exactly_one) {
189 $id = $element->getMDID();
190 $id = is_int($id) ? (string) $id : $id->value;
191 $builder = $builder->withAdditionalFilterAtCurrentStep(
192 FilterType::MDID,
193 $id
194 );
195 }
196
197 return $builder;
198 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getDefinition()
Defining properties of the metadata element.
withAdditionalFilterAtCurrentStep(FilterType $type, string ... $values)
Adds a filter to the current step, restricting what elements are included in it:
withNextStep(string $name, bool $add_as_first=false)
Add the next step to the path.

◆ addStepFromString()

ILIAS\MetaData\Paths\Factory::addStepFromString ( BuilderInterface  $builder,
string  $string 
)
protected

Definition at line 72 of file Factory.php.

76 $exploded = explode(Token::FILTER_SEPARATOR->value, strtolower($string));
77 $name = StepToken::tryFrom($exploded[0]) ?? $exploded[0];
78 if ($name === StepToken::SUPER) {
79 $builder = $builder->withNextStepToSuperElement(false);
80 } else {
81 $builder = $builder->withNextStep($name, false);
82 }
83 $exploded = array_slice($exploded, 1);
84 foreach ($exploded as $filter_string) {
85 $exploded_filter = explode(
87 strtolower($filter_string)
88 );
89 $type = FilterType::tryFrom($exploded_filter[0]);
90 $exploded_filter = array_slice($exploded_filter, 1);
91 if (!is_null($type)) {
92 $builder = $builder = $builder->withAdditionalFilterAtCurrentStep(
93 $type,
94 ...$exploded_filter
95 );
96 continue;
97 }
98 throw new \ilMDPathException(
99 'Cannot create path, invalid filter type.'
100 );
101 }
102 return $builder;
103 }
withNextStepToSuperElement(bool $add_as_first=false)
Add going to the super element as the next step to the path.

References ILIAS\MetaData\Paths\BuilderInterface\withNextStepToSuperElement().

Referenced by ILIAS\MetaData\Paths\Factory\fromString().

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

◆ betweenElements()

ILIAS\MetaData\Paths\Factory::betweenElements ( BaseElementInterface  $from,
BaseElementInterface  $to,
bool  $leads_to_exactly_one = false 
)

Returns relative path between two given elements.

If leads_to_exactly one is set true, it tries to add mdid filters where possible such that the path only leads to that specific element and not also others of the same type and position.

Implements ILIAS\MetaData\Paths\FactoryInterface.

Definition at line 132 of file Factory.php.

136 : PathInterface {
137 $to_and_supers = [];
138 while ($to) {
139 array_unshift($to_and_supers, $to);
140 $to = $to->getSuperElement();
141 }
142
143 $builder = $this
144 ->custom()
145 ->withRelative(true)
146 ->withLeadsToExactlyOneElement($leads_to_exactly_one);
147
148 while (!in_array($from, $to_and_supers, true)) {
149 $builder = $builder->withNextStepToSuperElement();
150 $from = $from->getSuperElement();
151 if (!isset($from)) {
152 throw new \ilMDPathException(
153 'Cannot build path between elements from disjunct sets.'
154 );
155 }
156 }
157
158 $to_and_supers = array_slice(
159 $to_and_supers,
160 array_search($from, $to_and_supers, true) + 1
161 );
162 foreach ($to_and_supers as $element) {
163 $builder = $this->addElementAsStep(
164 $builder,
165 $element,
166 $leads_to_exactly_one,
167 false
168 );
169 }
170
171 return $builder->getWithoutValidation();
172 }
addElementAsStep(BuilderInterface $builder, BaseElementInterface $element, bool $leads_to_exactly_one, bool $add_as_first)
Definition: Factory.php:174

References ILIAS\MetaData\Elements\Base\BaseElementInterface\getSuperElement().

+ Here is the call graph for this function:

◆ custom()

ILIAS\MetaData\Paths\Factory::custom ( )

Implements ILIAS\MetaData\Paths\FactoryInterface.

Definition at line 200 of file Factory.php.

201 {
202 return new Builder($this->structure);
203 }

Referenced by ILIAS\MetaData\Paths\Factory\fromString().

+ Here is the caller graph for this function:

◆ fromString()

ILIAS\MetaData\Paths\Factory::fromString ( string  $string)

Implements ILIAS\MetaData\Paths\FactoryInterface.

Definition at line 38 of file Factory.php.

38 : PathInterface
39 {
40 $exploded = explode(Token::SEPARATOR->value, strtolower($string));
41 $builder = $this->setModesFromString($this->custom(), $exploded[0]);
42 $exploded = array_slice($exploded, 1);
43 foreach ($exploded as $step_string) {
44 $builder = $this->addStepFromString($builder, $step_string);
45 }
46 return $builder->get();
47 }
setModesFromString(BuilderInterface $builder, string $string)
Definition: Factory.php:49
addStepFromString(BuilderInterface $builder, string $string)
Definition: Factory.php:72

References ILIAS\MetaData\Paths\Factory\addStepFromString(), ILIAS\MetaData\Paths\Factory\custom(), and ILIAS\MetaData\Paths\Factory\setModesFromString().

+ Here is the call graph for this function:

◆ setModesFromString()

ILIAS\MetaData\Paths\Factory::setModesFromString ( BuilderInterface  $builder,
string  $string 
)
protected

Definition at line 49 of file Factory.php.

53 $pattern = '/^(' . strtolower(Token::LEADS_TO_EXACTLY_ONE->value) .
54 ')?(' . strtolower(Token::START_AT_ROOT->value) . '|' .
55 strtolower(Token::START_AT_CURRENT->value) . ')$/';
56 if (!preg_match($pattern, $string, $matches)) {
57 throw new \ilMDPathException(
58 'Cannot create path, invalid modes in input string: ' . $string
59 );
60 }
61 if (!empty($matches[1])) {
62 $builder = $builder->withLeadsToExactlyOneElement(true);
63 }
64 if ($matches[2] === Token::START_AT_ROOT->value) {
65 $builder = $builder->withRelative(false);
66 } else {
67 $builder = $builder->withRelative(true);
68 }
69 return $builder;
70 }
withRelative(bool $is_relative)
Relative paths start at some otherwise determined element, absolute paths start at root.
withLeadsToExactlyOneElement(bool $leads_to_one)
Building a path that is flagged to lead to exactly one element, but does not actually do so can throw...

Referenced by ILIAS\MetaData\Paths\Factory\fromString().

+ Here is the caller graph for this function:

◆ toElement()

ILIAS\MetaData\Paths\Factory::toElement ( BaseElementInterface  $to,
bool  $leads_to_exactly_one = false 
)

Returns absolute path from root to the given element.

If leads_to_exactly one is set true, it will add mdid filters where possible such that the path only leads to that specific element and not also others of the same type and position.

Implements ILIAS\MetaData\Paths\FactoryInterface.

Definition at line 105 of file Factory.php.

108 : PathInterface {
109 $builder = $this
110 ->custom()
111 ->withRelative(false)
112 ->withLeadsToExactlyOneElement($leads_to_exactly_one);
113
114 while (!$to->isRoot()) {
115 $builder = $this->addElementAsStep(
116 $builder,
117 $to,
118 $leads_to_exactly_one,
119 true
120 );
121 $to = $to->getSuperElement();
122 if (!isset($to)) {
123 throw new \ilMDPathException(
124 'Cannot build path from element without root.'
125 );
126 }
127 }
128
129 return $builder->getWithoutValidation();
130 }

References ILIAS\MetaData\Elements\Base\BaseElementInterface\getSuperElement().

+ Here is the call graph for this function:

Field Documentation

◆ $structure

StructureSetInterface ILIAS\MetaData\Paths\Factory::$structure
protected

Definition at line 31 of file Factory.php.

Referenced by ILIAS\MetaData\Paths\Factory\__construct().


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