19declare(strict_types=1);
58 return $this->
filterBy(InputConditionInterface::class);
63 return $this->
filterBy(OutputConditionInterface::class);
71 return $this->condition_classes ??= $this->
validate(array_values(array_unique(array_map(
73 $this->condition_types
94 private function validate(array $classes): array
96 $classes_by_name = [];
97 foreach ($classes as $class) {
98 if (!class_exists($class)) {
99 throw new LogicException(
"Contributed condition class '{$class}' does not exist.");
101 if (!is_subclass_of($class, AbstractCondition::class)) {
102 throw new LogicException(
103 "Contributed condition class '{$class}' does not extend " . AbstractCondition::class .
'.'
106 if (!(
new ReflectionClass($class))->isInstantiable()) {
107 throw new LogicException(
"Contributed condition class '{$class}' cannot be instantiated.");
109 if (!is_subclass_of($class, InputConditionInterface::class)
110 && !is_subclass_of($class, OutputConditionInterface::class)
112 throw new LogicException(
113 "Contributed condition class '{$class}' is neither an input nor an output condition."
118 if (isset($classes_by_name[$name])) {
119 throw new LogicException(
120 "Contributed condition classes '{$classes_by_name[$name]}' and '{$class}' "
121 .
"share the name '{$name}'."
124 $classes_by_name[$name] = $class;
133 private function filterBy(
string $interface): array
135 return array_values(array_filter(
137 static fn(
string $class):
bool => is_subclass_of($class, $interface)
static getIdentifierForClass(string $class)
Extracts the identifier for the condition type from the class name.
Knows all contributed condition types.
filterBy(string $interface)
validate(array $classes)
Makes sure every class is an instantiable condition which is either an input or an output condition,...
getConditionByName(string $name_to_find)
__construct(array $condition_types)
A type of condition, contributed to the LearningSequence component.
All condition types known to the system.
Marker interface for input conditions in the Learning Sequence condition system.
Marker interface for output conditions in the Learning Sequence condition system.