ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DictionaryTransformation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
29{
32
34
36 {
37 $this->transformation = $transformation;
38 }
39
44 public function transform($from): array
45 {
46 if (!is_array($from)) {
48 sprintf('The value "%s" is no array.', var_export($from, true)),
49 'value_is_no_array',
50 $from
51 );
52 }
53
54 $result = [];
55 foreach ($from as $key => $value) {
56 if (!(is_int($key) || is_string($key))) {
58 'Key is not a string or int',
59 'key_is_no_string_or_int'
60 );
61 }
62 $transformedValue = $this->transformation->transform($value);
63 $result[(string) $key] = $transformedValue;
64 }
65
66 return $result;
67 }
68}
A transformation is a function from one datatype to another.