ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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)
 Adds a filter to the current step, restricting what elements are included in it: More...
 
 get ()
 

Protected Member Functions

 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.

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

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

Member Function Documentation

◆ get()

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

Implements ILIAS\MetaData\Paths\BuilderInterface.

Definition at line 123 of file Builder.php.

References $path, ILIAS\MetaData\Paths\Builder\validatePathFromRoot(), and ILIAS\MetaData\Paths\Builder\withCurrentStepSaved().

123  : PathInterface
124  {
125  $clone = $this->withCurrentStepSaved();
126  $path = new Path(
127  $clone->is_relative,
128  $clone->leads_to_one,
129  ...$clone->steps
130  );
131 
132  if (!$path->isRelative()) {
133  $this->validatePathFromRoot($path);
134  }
135  return $path;
136  }
$path
Definition: ltiservices.php:32
validatePathFromRoot(PathInterface $path)
Definition: Builder.php:141
+ Here is the call graph for this function:

◆ validatePathFromRoot()

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

Definition at line 141 of file Builder.php.

References ILIAS\MetaData\Paths\PathInterface\steps(), ILIAS\MetaData\Paths\Steps\SUPER, and ILIAS\MetaData\Paths\PathInterface\toString().

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

141  : void
142  {
143  $element = $this->structure->getRoot();
144  foreach ($path->steps() as $step) {
145  $name = $step->name();
146  if ($name === StepToken::SUPER) {
147  $element = $element->getSuperElement();
148  } else {
149  $element = $element->getSubElement($name);
150  }
151  if (is_null($element)) {
152  $name = is_string($name) ? $name : $name->value;
153  throw new \ilMDPathException(
154  "In the path '" . $path->toString() . "', the step '" . $name . "' is invalid."
155  );
156  }
157  }
158  }
$path
Definition: ltiservices.php:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ withAdditionalFilterAtCurrentStep()

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

Adds a filter to the current step, restricting what elements are included in it:

  • mdid: Only elements with the corresponding ID.
  • data: Only elements that carry data which matches the filter's value.
  • index: The n-th element, beginning with 0. Non-numeric values are interpreted as referring to the last index. (Note that filters are applied in the order they are added, so the index applies to already filtered elements.)

Multiple values in the same filter are treated as OR, multiple filters at the same step are treated as AND.

Implements ILIAS\MetaData\Paths\BuilderInterface.

Definition at line 103 of file Builder.php.

106  : BuilderInterface {
107  if (!isset($this->current_step_name)) {
108  throw new \ilMDPathException(
109  'Cannot add filter because there is no current step.'
110  );
111  }
112  $clone = clone $this;
113  $clone->current_step_filters[] = new Filter(
114  $type,
115  ...$values
116  );
117  return $clone;
118  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ withCurrentStepSaved()

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

Definition at line 170 of file Builder.php.

Referenced by ILIAS\MetaData\Paths\Builder\get(), and ILIAS\MetaData\Paths\Builder\withNextStepFromName().

170  : Builder
171  {
172  $clone = clone $this;
173  if (!isset($clone->current_step_name)) {
174  return $clone;
175  }
176 
177  $new_step = new Step(
178  $clone->current_step_name,
179  ...$clone->current_step_filters
180  );
181  if ($clone->current_add_as_first) {
182  array_unshift($clone->steps, $new_step);
183  } else {
184  $clone->steps[] = $new_step;
185  }
186 
187  $clone->current_step_name = null;
188  $clone->current_step_filters = [];
189  $clone->current_add_as_first = false;
190 
191  return $clone;
192  }
+ Here is the caller graph for this function:

◆ 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.

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

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.

References ILIAS\MetaData\Paths\Builder\withNextStepFromName().

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:160
+ Here is the call graph for this function:

◆ withNextStepFromName()

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

Definition at line 160 of file Builder.php.

References ILIAS\MetaData\Paths\Builder\withCurrentStepSaved().

Referenced by ILIAS\MetaData\Paths\Builder\withNextStep(), ILIAS\MetaData\Paths\Builder\withNextStepFromStep(), and ILIAS\MetaData\Paths\Builder\withNextStepToSuperElement().

163  : BuilderInterface {
164  $clone = $this->withCurrentStepSaved();
165  $clone->current_step_name = $name;
166  $clone->current_add_as_first = $add_as_first;
167  return $clone;
168  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

References ILIAS\MetaData\Paths\Steps\StepInterface\filters(), ILIAS\MetaData\Paths\Steps\StepInterface\name(), and ILIAS\MetaData\Paths\Builder\withNextStepFromName().

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  }
withNextStepFromName(string|StepToken $name, bool $add_as_first=false)
Definition: Builder.php:160
+ 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.

References ILIAS\MetaData\Paths\Steps\SUPER, and ILIAS\MetaData\Paths\Builder\withNextStepFromName().

81  : BuilderInterface
82  {
83  return $this->withNextStepFromName(
85  $add_as_first
86  );
87  }
withNextStepFromName(string|StepToken $name, bool $add_as_first=false)
Definition: Builder.php:160
+ Here is the call graph for this function:

◆ 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.

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

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

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

◆ $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: