ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCtrlStructure.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2020 Richard Klees, Extended GPL, see docs/LICENSE */
3
9{
13 protected $class_scripts;
14
18 protected $class_children;
19
20 public function __construct(array $class_scripts = [], array $class_children = [])
21 {
22 $this->class_scripts = [];
23 $this->class_children = [];
24 foreach ($class_scripts as $k => $v) {
25 $this->addClassScript($k, $v);
26 }
27 foreach ($class_children as $k => $vs) {
28 foreach ($vs as $v) {
29 $this->addClassChild($k, $v);
30 }
31 }
32 }
33
34 public function withClassScript(string $class, string $file_path) : \ilCtrlStructure
35 {
36 $clone = clone $this;
37 $clone->addClassScript($class, $file_path);
38 return $clone;
39 }
40
41 public function withClassChild(string $parent, string $child) : \ilCtrlStructure
42 {
43 $clone = clone $this;
44 $clone->addClassChild($parent, $child);
45 return $clone;
46 }
47
48 public function getClassScripts() : \Generator
49 {
50 foreach ($this->class_scripts as $k => $v) {
51 yield $k => $v;
52 }
53 }
54
55 public function getClassChildren() : \Generator
56 {
57 foreach ($this->class_children as $k => $v) {
58 yield $k => $v;
59 }
60 }
61
62 public function getClassScriptOf(string $class) : ?string
63 {
64 if (!isset($this->class_scripts[$class])) {
65 return null;
66 }
67 return $this->class_scripts[$class];
68 }
69
70 protected function addClassScript(string $class, string $file_path) : void
71 {
72 if ($class == "") {
73 throw new \InvalidArgumentException(
74 "Can't add class script for an empty class."
75 );
76 }
77
78 if (isset($this->class_scripts[$class]) && $this->class_scripts[$class] != $file_path) {
79 $e = new \RuntimeException(
80 "Can't add script '$file_path' for class '$class', a script for that class already exists."
81 );
82 $e->file_path = $file_path;
83 $e->class = $class;
84 throw $e;
85 }
86
87 $this->class_scripts[$class] = $file_path;
88 }
89
90 protected function addClassChild(string $parent, string $child) : void
91 {
92 if ($parent == "") {
93 throw new \InvalidArgumentException(
94 "Can't add class child for an empty parent."
95 );
96 }
97
98 if (!isset($this->class_children[$parent])) {
99 $this->class_children[$parent] = [];
100 }
101
102 if (!in_array($child, $this->class_children[$parent])) {
103 $this->class_children[$parent][] = $child;
104 }
105 }
106}
An exception for terminatinating execution or to throw for unit testing.
The CtrlStructure knows how GUIs call each other and where the code of the guis is located.
__construct(array $class_scripts=[], array $class_children=[])
addClassScript(string $class, string $file_path)
withClassChild(string $parent, string $child)
addClassChild(string $parent, string $child)
withClassScript(string $class, string $file_path)
getClassScriptOf(string $class)