ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCtrlArrayClassPath.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
32
41 {
43
44 $this->context = $context;
45
46 try {
47 $this->cid_path = $this->getCidPathByArray($target_classes);
48 } catch (ilCtrlException $exception) {
49 $this->exception = $exception;
50 }
51 }
52
64 private function getCidPathByArray(array $target_classes): string
65 {
66 // abort if the provided targets are empty.
67 if (empty($target_classes)) {
68 throw new ilCtrlException(__METHOD__ . " must be provided with a list of classes.");
69 }
70
71 // loop through each provided class in descending order
72 // and check if they are all related to one another and
73 // convert them to a cid path.
74 $cid_path = $previous_class = null;
75 foreach ($target_classes as $current_class) {
76 $current_cid = $this->structure->getClassCidByName($current_class);
77
78 // abort if the current class cannot be found.
79 if (null === $current_cid) {
80 throw new ilCtrlException("Class '$current_class' was not found in the control structure, try `composer du` to read artifacts.");
81 }
82
83 // abort if the current and previous classes are
84 // not related.
85 if (null !== $previous_class && !$this->isClassParentOf($previous_class, $current_class)) {
86 throw new ilCtrlException("Class '$current_class' is not a child of '$previous_class'.");
87 }
88
89 $cid_path = $this->appendCid($current_cid, $cid_path);
90 $previous_class = $current_class;
91 }
92
93 // if the first provided class is a baseclass the
94 // created cid path can be returned.
95 $first_array_class = $target_classes[array_key_first($target_classes)];
96 if ($this->structure->isBaseClass($first_array_class)) {
97 return $cid_path;
98 }
99
100 // check if the first command class is related to one
101 // of the current context.
102 $related_class_path = $this->getPathToRelatedClassInContext($this->context, $first_array_class);
103 if (null === $related_class_path) {
104 throw new ilCtrlException("Class '$first_array_class' is not a baseclass and the current context doesn't have one either.");
105 }
106
107 return $this->appendCid($cid_path, $related_class_path);
108 }
109}
Class ilCtrlAbstractPath.
getPathToRelatedClassInContext(ilCtrlContextInterface $context, string $target_class)
Returns the path to a class within the given contexts current path that has a relation to the given t...
appendCid(string $cid, ?string $path=null)
Helper function to add CIDs to a given path.
ilCtrlStructureInterface $structure
isClassParentOf(string $parent_class, string $child_class)
Returns whether the given target class is a parent of the other given class.
Class ilCtrlArrayClassPath.
__construct(ilCtrlStructureInterface $structure, ilCtrlContextInterface $context, array $target_classes)
ilCtrlArrayClassPath Constructor
getCidPathByArray(array $target_classes)
Generates a cid path from the given class array.
ilCtrlContextInterface $context
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc