ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SingleType.php
Go to the documentation of this file.
1<?php
2
20
21class SingleType implements Type, Ancestors
22{
23 protected \ReflectionClass $type;
24
29 public function __construct($fullyQualifiedClassName)
30 {
31 $this->type = new \ReflectionClass($fullyQualifiedClassName);
32 }
33
37 public function __toString(): string
38 {
39 return $this->type->getName();
40 }
41
45 public function isExtensionOf(Type $type): bool
46 {
47 if (!$type instanceof SingleType) {
48 return false;
49 }
50 if ($this->type->isSubclassOf($type->__toString())) {
51 return true;
52 }
53 return $this->__toString() === $type->__toString();
54 }
55
59 public function getAncestors(): array
60 {
61 $class = $this->type;
62 $ancestors = [new SingleType($class->getName())];
63
64 while ($class = $class->getParentClass()) {
65 $ancestors[] = new SingleType($class->getName());
66 }
67
68 return array_reverse($ancestors);
69 }
70
74 public function equals(Type $otherType): bool
75 {
76 if (!$otherType instanceof SingleType) {
77 return false;
78 }
79
80 return $this->__toString() === $otherType->__toString();
81 }
82}
getAncestors()
returns the hierarchy of this type.E.g. ["AbstractValue", "ScalarValue", "IntegerValue",...
Definition: SingleType.php:59
__toString()
string A string representation of the Type.
Definition: SingleType.php:37
equals(Type $otherType)
returns true if the two types are equal.
Definition: SingleType.php:74
isExtensionOf(Type $type)
Is this type a subtype of $type.Not strict! x->isExtensionOf(x) == true.
Definition: SingleType.php:45
__construct($fullyQualifiedClassName)
SingleType constructor.
Definition: SingleType.php:29
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Ancestors.php:19