ILIAS  release_7 Revision v7.30-3-g800a261c036
DictionaryTransformation.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3/* Copyright (c) 2020 Luka K. A. Stocker, Extended GPL, see docs/LICENSE */
4
6
11
13{
16
18
20 {
21 $this->transformation = $transformation;
22 }
23
27 public function transform($from)
28 {
29 if (!is_array($from)) {
31 sprintf('The value "%s" is no array.', $from),
32 'value_is_no_array',
33 $from
34 );
35 }
36
37 $result = [];
38 foreach ($from as $key => $value) {
39 if (!is_string($key)) {
41 'Key is not a string',
42 'key_is_no_string'
43 );
44 }
45 $transformedValue = $this->transformation->transform($value);
46 $result[$key] = $transformedValue;
47 }
48 return $result;
49 }
50}
$result
An exception for terminatinating execution or to throw for unit testing.
transform($from)
Perform the transformation.Please use this for transformations. It's more performant than calling inv...
A transformation is a function from one datatype to another.