ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Group.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
34 use ILIAS\Refinery\To\DefaultToNull\Group as DefaultToNull;
39 
40 class Group
41 {
42  public function __construct(
43  private readonly Factory $dataFactory,
44  private readonly Language $language
45  ) {
46  }
47 
52  public function string(): Transformation
53  {
54  return new StringTransformation();
55  }
56 
61  public function int(): Transformation
62  {
63  return new IntegerTransformation();
64  }
65 
70  public function float(): Transformation
71  {
72  return new FloatTransformation();
73  }
74 
79  public function bool(): Transformation
80  {
81  return new BooleanTransformation();
82  }
83 
92  public function listOf(Transformation $transformation): Transformation
93  {
94  return new ListTransformation($transformation);
95  }
96 
105  public function dictOf(Transformation $transformation): Transformation
106  {
107  return new DictionaryTransformation($transformation);
108  }
109 
124  public function tupleOf(array $transformation): Transformation
125  {
126  return new TupleTransformation($transformation);
127  }
128 
145  public function recordOf(array $transformations): Transformation
146  {
147  return new RecordTransformation($transformations);
148  }
149 
158  public function toNew($classNameOrArray): Transformation
159  {
160  if (is_array($classNameOrArray)) {
161  if (2 !== count($classNameOrArray)) {
162  throw new InvalidArgumentException('The array MUST contain exactly two elements');
163  }
164  return new NewMethodTransformation($classNameOrArray[0], $classNameOrArray[1]);
165  }
166  return new NewObjectTransformation($classNameOrArray);
167  }
168 
174  public function data(string $dataType): Transformation
175  {
176  return $this->toNew([$this->dataFactory, $dataType]);
177  }
178 
179  public function dateTime(): Transformation
180  {
181  return new DateTimeTransformation();
182  }
183 
191  public function inArray(array $valid_members): Transformation
192  {
193  return new InArrayTransformation($valid_members, $this->language);
194  }
195 }
inArray(array $valid_members)
Validates that the value to be transformed is in the set given to this transformation.
Definition: Group.php:191
toNew($classNameOrArray)
Returns either an transformation object to create objects of an existing class, with variations of co...
Definition: Group.php:158
float()
Returns an object that allows to transform a value to a float value.
Definition: Group.php:70
recordOf(array $transformations)
Returns an object that allows to transform the values of an associative array with the given associat...
Definition: Group.php:145
data(string $dataType)
Definition: Group.php:174
__construct(private readonly Factory $dataFactory, private readonly Language $language)
Definition: Group.php:42
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Builds data types.
Definition: Factory.php:35
int()
Returns an object that allows to transform a value to an integer value.
Definition: Group.php:61
dictOf(Transformation $transformation)
Returns an object that allows to transform the values of an associative array with the given transfor...
Definition: Group.php:105
Transform a string representing a datetime-value to php&#39;s DateTimeImmutable see https://www.php.net/manual/de/datetime.formats.php.
A transformation is a function from one datatype to another.
string()
Returns an object that allows to transform a value to a string value.
Definition: Group.php:52
listOf(Transformation $transformation)
Returns an object that allows to transform an value in a given array with the given transformation ob...
Definition: Group.php:92
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
tupleOf(array $transformation)
Returns an object that allows to transform the values of an array with the given array of transformat...
Definition: Group.php:124
bool()
Returns an object that allows to transform a value to a boolean value.
Definition: Group.php:79