ILIAS  release_8 Revision v8.24
class.ilComponentInfo.php
Go to the documentation of this file.
1<?php
19declare(strict_types=1);
20
25{
26 // TODO: to be replaced with an enum for PHP 8.1...
27 public const TYPES = ["Modules", "Services"];
28 public const TYPE_MODULES = "Modules";
29 public const TYPE_SERVICES = "Services";
30
31 protected string $id;
32 protected string $type;
33 protected string $name;
37 protected array $pluginslots;
38
39 public function __construct(
40 string $id,
41 string $type,
42 string $name,
43 array &$pluginslots
44 ) {
45 if (!in_array($type, self::TYPES)) {
46 throw new \InvalidArgumentException(
47 "Invalid component type: $type"
48 );
49 }
50
51 $this->id = $id;
52 $this->type = $type;
53 $this->name = $name;
54 $this->pluginslots = &$pluginslots;
55 }
56
57 public function getId(): string
58 {
59 return $this->id;
60 }
61
62 public function getType(): string
63 {
64 return $this->type;
65 }
66
67 public function getName(): string
68 {
69 return $this->name;
70 }
71
72 public function getQualifiedName(): string
73 {
74 return $this->type . "/" . $this->name;
75 }
76
80 public function getPluginSlots(): Iterator
81 {
82 foreach ($this->pluginslots as $id => $slot) {
83 yield $slot->getId() => $slot;
84 }
85 }
86
87 public function hasPluginSlotId(string $id): bool
88 {
89 foreach ($this->pluginslots as $slot) {
90 if ($slot->getId() === $id) {
91 return true;
92 }
93 }
94 return false;
95 }
96
100 public function getPluginSlotById(string $id): \ilPluginSlotInfo
101 {
102 foreach ($this->pluginslots as $slot) {
103 if ($slot->getId() === $id) {
104 return $slot;
105 }
106 }
107 throw new \InvalidArgumentException(
108 "No plugin slot $id at component {$this->getQualifiedName()}"
109 );
110 }
111
112 public function hasPluginSlotName(string $name): bool
113 {
114 foreach ($this->pluginslots as $slot) {
115 if ($slot->getName() === $name) {
116 return true;
117 }
118 }
119 return false;
120 }
121
126 {
127 foreach ($this->pluginslots as $slot) {
128 if ($slot->getName() === $name) {
129 return $slot;
130 }
131 }
132 throw new \InvalidArgumentException(
133 "No plugin slot $name at component {$this->getQualifiedName()}"
134 );
135 }
136}
Simple value class for basic information about a component.
getPluginSlotByName(string $name)
__construct(string $id, string $type, string $name, array &$pluginslots)
hasPluginSlotName(string $name)
Simple value class for basic information about a pluginslot.