ILIAS  release_8 Revision v8.23
ilCtrlArrayClassPath Class Reference

Class ilCtrlArrayClassPath. More...

+ Inheritance diagram for ilCtrlArrayClassPath:
+ Collaboration diagram for ilCtrlArrayClassPath:

Public Member Functions

 __construct (ilCtrlStructureInterface $structure, ilCtrlContextInterface $context, array $target_classes)
 ilCtrlArrayClassPath Constructor More...
 
- Public Member Functions inherited from ilCtrlAbstractPath
 __construct (ilCtrlStructureInterface $structure)
 ilCtrlAbstractPath Constructor More...
 
 getCidPath ()
 
 getCurrentCid ()
 
 getNextCid (string $current_class)
 
 getCidPaths (int $order=SORT_DESC)
 
 getCidArray (int $order=SORT_DESC)
 
 getBaseClass ()
 
 getException ()
 

Private Member Functions

 getCidPathByArray (array $target_classes)
 Generates a cid path from the given class array. More...
 

Private Attributes

ilCtrlContextInterface $context
 

Additional Inherited Members

- Data Fields inherited from ilCtrlPathInterface
const CID_PATH_SEPARATOR = ':'
 
- Protected Member Functions inherited from 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 target. More...
 
 isClassChildOf (string $child_class, string $parent_class)
 Returns whether the given target class is a child of the other given class. More...
 
 isClassParentOf (string $parent_class, string $child_class)
 Returns whether the given target class is a parent of the other given class. More...
 
 appendCid (string $cid, string $path=null)
 Helper function to add CIDs to a given path. More...
 
- Protected Attributes inherited from ilCtrlAbstractPath
ilCtrlStructureInterface $structure
 
ilCtrlException $exception = null
 
string $cid_path = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCtrlArrayClassPath::__construct ( ilCtrlStructureInterface  $structure,
ilCtrlContextInterface  $context,
array  $target_classes 
)

ilCtrlArrayClassPath Constructor

Parameters
ilCtrlStructureInterface$structure
ilCtrlContextInterface$context
string[]$target_classes

Definition at line 26 of file class.ilCtrlArrayClassPath.php.

References $context, ilCtrlAbstractPath\$exception, ILIAS\GlobalScreen\Provider\__construct(), and getCidPathByArray().

27  {
28  parent::__construct($structure);
29 
30  $this->context = $context;
31 
32  try {
33  $this->cid_path = $this->getCidPathByArray($target_classes);
34  } catch (ilCtrlException $exception) {
35  $this->exception = $exception;
36  }
37  }
ilCtrl exceptions
__construct(Container $dic, ilPlugin $plugin)
ilCtrlContextInterface $context
getCidPathByArray(array $target_classes)
Generates a cid path from the given class array.
+ Here is the call graph for this function:

Member Function Documentation

◆ getCidPathByArray()

ilCtrlArrayClassPath::getCidPathByArray ( array  $target_classes)
private

Generates a cid path from the given class array.

If the given class array does not contain a valid path an according exception will be thrown.

Parameters
string[]$target_classes
Returns
string
Exceptions
ilCtrlExceptionif classes within the classes array are not related.

Definition at line 50 of file class.ilCtrlArrayClassPath.php.

References ilCtrlAbstractPath\$cid_path, ilCtrlAbstractPath\appendCid(), ilCtrlAbstractPath\getPathToRelatedClassInContext(), and ilCtrlAbstractPath\isClassParentOf().

Referenced by __construct().

50  : string
51  {
52  // abort if the provided targets are empty.
53  if (empty($target_classes)) {
54  throw new ilCtrlException(__METHOD__ . " must be provided with a list of classes.");
55  }
56 
57  // loop through each provided class in descending order
58  // and check if they are all related to one another and
59  // convert them to a cid path.
60  $cid_path = $previous_class = null;
61  foreach ($target_classes as $current_class) {
62  $current_cid = $this->structure->getClassCidByName($current_class);
63 
64  // abort if the current class cannot be found.
65  if (null === $current_cid) {
66  throw new ilCtrlException("Class '$current_class' was not found in the control structure, try `composer du` to read artifacts.");
67  }
68 
69  // abort if the current and previous classes are
70  // not related.
71  if (null !== $previous_class && !$this->isClassParentOf($previous_class, $current_class)) {
72  throw new ilCtrlException("Class '$current_class' is not a child of '$previous_class'.");
73  }
74 
75  $cid_path = $this->appendCid($current_cid, $cid_path);
76  $previous_class = $current_class;
77  }
78 
79  // if the first provided class is a baseclass the
80  // created cid path can be returned.
81  $first_array_class = $target_classes[array_key_first($target_classes)];
82  if ($this->structure->isBaseClass($first_array_class)) {
83  return $cid_path;
84  }
85 
86  // check if the first command class is related to one
87  // of the current context.
88  $related_class_path = $this->getPathToRelatedClassInContext($this->context, $first_array_class);
89  if (null === $related_class_path) {
90  throw new ilCtrlException("Class '$first_array_class' is not a baseclass and the current context doesn't have one either.");
91  }
92 
93  return $this->appendCid($cid_path, $related_class_path);
94  }
isClassParentOf(string $parent_class, string $child_class)
Returns whether the given target class is a parent of the other given class.
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.
ilCtrl exceptions
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $context

ilCtrlContextInterface ilCtrlArrayClassPath::$context
private

Definition at line 17 of file class.ilCtrlArrayClassPath.php.

Referenced by __construct().


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