ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
TupleType.php
Go to the documentation of this file.
1 <?php
2 
20 
21 class TupleType implements Type
22 {
26  protected array $types = [];
27 
32  public function __construct(array $fullyQualifiedClassNames)
33  {
34  foreach ($fullyQualifiedClassNames as $fullyQualifiedClassName) {
35  if (!is_a($fullyQualifiedClassName, Type::class)) {
36  $fullyQualifiedClassName = new SingleType($fullyQualifiedClassName);
37  }
38  $this->types[] = $fullyQualifiedClassName;
39  }
40  }
41 
45  public function __toString(): string
46  {
47  return "(" . implode(", ", $this->types) . ")";
48  }
49 
54  public function isExtensionOf(Type $type): bool
55  {
56  if (!$type instanceof TupleType) {
57  return false;
58  }
59 
60  $others = $type->getTypes();
61  foreach ($this->types as $i => $type) {
62  if (!$type->isExtensionOf($others[$i])) {
63  return false;
64  }
65  }
66 
67  return true;
68  }
69 
73  public function getTypes(): array
74  {
75  return $this->types;
76  }
77 
81  public function equals(Type $otherType): bool
82  {
83  if (!$otherType instanceof TupleType) {
84  return false;
85  }
86 
87  foreach ($this->types as $i => $type) {
88  $otherTypes = $otherType->getTypes();
89  if (!$otherTypes[$i]->equals($type)) {
90  return false;
91  }
92  }
93 
94  return true;
95  }
96 }
isExtensionOf(Type $type)
tuple A is a subtype of tuple B, iff every element i of tuple A is a subtype of element i of tuple B...
Definition: TupleType.php:54
__construct(array $fullyQualifiedClassNames)
SingleType constructor.
Definition: TupleType.php:32
equals(Type $otherType)
returns true if the two types are equal.
Definition: TupleType.php:81
__toString()
string A string representation of the Type.
Definition: TupleType.php:45
isExtensionOf(Type $type)
Is this type a subtype of $type.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Ancestors.php:19