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

Public Member Functions

 __construct (StructureSetInterface $structure)
 
 withRelative (bool $is_relative)
 Relative paths start at some otherwise determined element, absolute paths start at root. More...
 
 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 errors later on. More...
 
 withNextStep (string $name, bool $add_as_first=false)
 Add the next step to the path. More...
 
 withNextStepToSuperElement (bool $add_as_first=false)
 Add going to the super element as the next step to the path. More...
 
 withNextStepFromStep (StepInterface $next_step, bool $add_as_first=false)
 
 withAdditionalFilterAtCurrentStep (FilterType $type, string ... $values)
 
 get ()
 
 getWithoutValidation ()
 
 withRelative (bool $is_relative)
 Relative paths start at some otherwise determined element, absolute paths start at root. More...
 
 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 errors later on. More...
 
 withNextStep (string $name, bool $add_as_first=false)
 Add the next step to the path. More...
 
 withNextStepToSuperElement (bool $add_as_first=false)
 Add going to the super element as the next step to the path. More...
 
 withAdditionalFilterAtCurrentStep (FilterType $type, string ... $values)
 Adds a filter to the current step, restricting what elements are included in it: More...
 
 get ()
 
 withNextStepFromStep (StepInterface $next_step, bool $add_as_first=false)
 

Protected Member Functions

 getFinishedPath (bool $validate)
 
 validatePathFromRoot (PathInterface $path)
 
 withNextStepFromName (string|StepToken $name, bool $add_as_first=false)
 
 withCurrentStepSaved ()
 

Protected Attributes

StructureSetInterface $structure
 
array $steps = []
 
string StepToken null $current_step_name = null
 
array $current_step_filters = []
 
bool $current_add_as_first = false
 
bool $is_relative = false
 
bool $leads_to_one = false
 

Detailed Description

Definition at line 31 of file Builder.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 35 of file Builder.php.

36 {
37 $this->structure = $structure;
38 }
StructureSetInterface $structure
Definition: Builder.php:33

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

Member Function Documentation

◆ get()

ILIAS\MetaData\Paths\Builder::get ( )
Exceptions

ilMDPathException

Implements ILIAS\MetaData\Paths\BuilderInterface.

Definition at line 126 of file Builder.php.

126 : PathInterface
127 {
128 return $this->getFinishedPath(true);
129 }
getFinishedPath(bool $validate)
Definition: Builder.php:139

◆ getFinishedPath()

ILIAS\MetaData\Paths\Builder::getFinishedPath ( bool  $validate)
protected

Definition at line 139 of file Builder.php.

139 : PathInterface
140 {
141 $clone = $this->withCurrentStepSaved();
142 $path = new Path(
143 $clone->is_relative,
144 $clone->leads_to_one,
145 ...$clone->steps
146 );
147
148 if ($validate && !$path->isRelative()) {
150 }
151 return $path;
152 }
validatePathFromRoot(PathInterface $path)
Definition: Builder.php:157
$path
Definition: ltiservices.php:30

References $path.

◆ getWithoutValidation()

ILIAS\MetaData\Paths\Builder::getWithoutValidation ( )

Definition at line 134 of file Builder.php.

134 : PathInterface
135 {
136 return $this->getFinishedPath(false);
137 }

◆ validatePathFromRoot()

ILIAS\MetaData\Paths\Builder::validatePathFromRoot ( PathInterface  $path)
protected
Exceptions

ilMDPathException

Definition at line 157 of file Builder.php.

157 : void
158 {
159 $element = $this->structure->getRoot();
160 foreach ($path->steps() as $step) {
161 $name = $step->name();
162 if ($name === StepToken::SUPER) {
163 $element = $element->getSuperElement();
164 } else {
165 $element = $element->getSubElement($name);
166 }
167 if (is_null($element)) {
168 $name = is_string($name) ? $name : $name->value;
169 throw new \ilMDPathException(
170 "In the path '" . $path->toString() . "', the step '" . $name . "' is invalid."
171 );
172 }
173 }
174 }

References $path, and ILIAS\MetaData\Paths\Steps\SUPER.

◆ withAdditionalFilterAtCurrentStep()

ILIAS\MetaData\Paths\Builder::withAdditionalFilterAtCurrentStep ( FilterType  $type,
string ...  $values 
)
Exceptions

ilMDPathException

Implements ILIAS\MetaData\Paths\BuilderInterface.

Definition at line 106 of file Builder.php.

109 : BuilderInterface {
110 if (!isset($this->current_step_name)) {
111 throw new \ilMDPathException(
112 'Cannot add filter because there is no current step.'
113 );
114 }
115 $clone = clone $this;
116 $clone->current_step_filters[] = new Filter(
117 $type,
118 ...$values
119 );
120 return $clone;
121 }

◆ withCurrentStepSaved()

ILIAS\MetaData\Paths\Builder::withCurrentStepSaved ( )
protected

Definition at line 186 of file Builder.php.

186 : Builder
187 {
188 $clone = clone $this;
189 if (!isset($clone->current_step_name)) {
190 return $clone;
191 }
192
193 $new_step = new Step(
194 $clone->current_step_name,
195 ...$clone->current_step_filters
196 );
197 if ($clone->current_add_as_first) {
198 array_unshift($clone->steps, $new_step);
199 } else {
200 $clone->steps[] = $new_step;
201 }
202
203 $clone->current_step_name = null;
204 $clone->current_step_filters = [];
205 $clone->current_add_as_first = false;
206
207 return $clone;
208 }

◆ withLeadsToExactlyOneElement()

ILIAS\MetaData\Paths\Builder::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 errors later on.

If you set this flag, be sure to set filters correctly. Default is false.

Implements ILIAS\MetaData\Paths\BuilderInterface.

Definition at line 63 of file Builder.php.

65 : BuilderInterface {
66 $clone = clone $this;
67 $clone->leads_to_one = $leads_to_one;
68 return $clone;
69 }

◆ withNextStep()

ILIAS\MetaData\Paths\Builder::withNextStep ( string  $name,
bool  $add_as_first = false 
)

Add the next step to the path.

If add_as_first is set true, the step is added as the first and not the last step.

Implements ILIAS\MetaData\Paths\BuilderInterface.

Definition at line 71 of file Builder.php.

74 : BuilderInterface {
75 return $this->withNextStepFromName(
76 $name,
77 $add_as_first
78 );
79 }
withNextStepFromName(string|StepToken $name, bool $add_as_first=false)
Definition: Builder.php:176

◆ withNextStepFromName()

ILIAS\MetaData\Paths\Builder::withNextStepFromName ( string|StepToken  $name,
bool  $add_as_first = false 
)
protected

Definition at line 176 of file Builder.php.

179 : BuilderInterface {
180 $clone = $this->withCurrentStepSaved();
181 $clone->current_step_name = $name;
182 $clone->current_add_as_first = $add_as_first;
183 return $clone;
184 }

◆ withNextStepFromStep()

ILIAS\MetaData\Paths\Builder::withNextStepFromStep ( StepInterface  $next_step,
bool  $add_as_first = false 
)

Implements ILIAS\MetaData\Paths\BuilderInterface.

Definition at line 89 of file Builder.php.

92 : BuilderInterface {
93 $builder = $this->withNextStepFromName($next_step->name(), $add_as_first);
94 foreach ($next_step->filters() as $filter) {
95 $builder = $builder->withAdditionalFilterAtCurrentStep(
96 $filter->type(),
97 ...$filter->values()
98 );
99 }
100 return $builder;
101 }

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

+ Here is the call graph for this function:

◆ withNextStepToSuperElement()

ILIAS\MetaData\Paths\Builder::withNextStepToSuperElement ( bool  $add_as_first = false)

Add going to the super element as the next step to the path.

If add_to_front is set true, the step is added as the first and not the last step.

Implements ILIAS\MetaData\Paths\BuilderInterface.

Definition at line 81 of file Builder.php.

81 : BuilderInterface
82 {
83 return $this->withNextStepFromName(
85 $add_as_first
86 );
87 }

References ILIAS\MetaData\Paths\Steps\SUPER.

◆ withRelative()

ILIAS\MetaData\Paths\Builder::withRelative ( bool  $is_relative)

Relative paths start at some otherwise determined element, absolute paths start at root.

Default is false.

Implements ILIAS\MetaData\Paths\BuilderInterface.

Definition at line 56 of file Builder.php.

56 : BuilderInterface
57 {
58 $clone = clone $this;
59 $clone->is_relative = $is_relative;
60 return $clone;
61 }

References ILIAS\MetaData\Paths\Builder\$is_relative.

Field Documentation

◆ $current_add_as_first

bool ILIAS\MetaData\Paths\Builder::$current_add_as_first = false
protected

Definition at line 51 of file Builder.php.

◆ $current_step_filters

array ILIAS\MetaData\Paths\Builder::$current_step_filters = []
protected

Definition at line 50 of file Builder.php.

◆ $current_step_name

string StepToken null ILIAS\MetaData\Paths\Builder::$current_step_name = null
protected

Definition at line 45 of file Builder.php.

◆ $is_relative

bool ILIAS\MetaData\Paths\Builder::$is_relative = false
protected

Definition at line 53 of file Builder.php.

Referenced by ILIAS\MetaData\Paths\Builder\withRelative().

◆ $leads_to_one

bool ILIAS\MetaData\Paths\Builder::$leads_to_one = false
protected

Definition at line 54 of file Builder.php.

◆ $steps

array ILIAS\MetaData\Paths\Builder::$steps = []
protected

Definition at line 43 of file Builder.php.

◆ $structure

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

Definition at line 33 of file Builder.php.

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


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