ILIAS  trunk Revision v11.0_alpha-2658-ge2404539063
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 ()
 

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.

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

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

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.

References $id, ILIAS\MetaData\Elements\Base\BaseElementInterface\getDefinition(), ILIAS\MetaData\Elements\Base\BaseElementInterface\getMDID(), if, ILIAS\MetaData\Paths\BuilderInterface\withAdditionalFilterAtCurrentStep(), and ILIAS\MetaData\Paths\BuilderInterface\withNextStep().

Referenced by ILIAS\MetaData\Paths\Factory\betweenElements(), and ILIAS\MetaData\Paths\Factory\toElement().

179  : BuilderInterface {
180  $builder = $builder->withNextStep(
181  $element->getDefinition()->name(),
182  $add_as_first
183  );
184 
185  $id = $element->getMDID();
186  if ($element instanceof StructureElement) {
187  return $builder;
188  }
189  $id = is_int($id) ? (string) $id : $id->value;
190  if ($leads_to_exactly_one) {
191  $builder = $builder->withAdditionalFilterAtCurrentStep(
192  FilterType::MDID,
193  $id
194  );
195  }
196 
197  return $builder;
198  }
if(!file_exists('../ilias.ini.php'))
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addStepFromString()

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

Definition at line 72 of file Factory.php.

References ILIAS\MetaData\Paths\FILTER_VALUE_SEPARATOR, ILIAS\MetaData\Paths\Steps\SUPER, ILIAS\MetaData\Paths\BuilderInterface\withAdditionalFilterAtCurrentStep(), ILIAS\MetaData\Paths\BuilderInterface\withNextStep(), and ILIAS\MetaData\Paths\BuilderInterface\withNextStepToSuperElement().

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

75  : BuilderInterface {
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  }
+ 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.

References ILIAS\MetaData\Paths\Factory\addElementAsStep(), and ILIAS\MetaData\Elements\Base\BaseElementInterface\getSuperElement().

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->get();
172  }
addElementAsStep(BuilderInterface $builder, BaseElementInterface $element, bool $leads_to_exactly_one, bool $add_as_first)
Definition: Factory.php:174
+ 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.

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

200  : BuilderInterface
201  {
202  return new Builder($this->structure);
203  }
+ 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.

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

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  }
addStepFromString(BuilderInterface $builder, string $string)
Definition: Factory.php:72
setModesFromString(BuilderInterface $builder, string $string)
Definition: Factory.php:49
+ 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.

References ILIAS\MetaData\Paths\BuilderInterface\withLeadsToExactlyOneElement(), and ILIAS\MetaData\Paths\BuilderInterface\withRelative().

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

52  : BuilderInterface {
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  }
+ Here is the call graph for this function:
+ 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.

References ILIAS\MetaData\Paths\Factory\addElementAsStep(), ILIAS\MetaData\Elements\Base\BaseElementInterface\getSuperElement(), and ILIAS\MetaData\Elements\Base\BaseElementInterface\isRoot().

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->get();
130  }
addElementAsStep(BuilderInterface $builder, BaseElementInterface $element, bool $leads_to_exactly_one, bool $add_as_first)
Definition: Factory.php:174
+ 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: