ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
DictionaryTransformation.php
Go to the documentation of this file.
1<?php
2declare(strict_types=1);
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
10
14
16{
18
23
28 {
29 $this->transformation = $transformation;
30 }
31
35 public function transform($from)
36 {
37 if (false === is_array($from)) {
39 'The value MUST be an array',
40 'not_array'
41 );
42 }
43
44 $result = array();
45 foreach ($from as $key => $value) {
46 if (false === is_string($key)) {
48 'The key "%s" is NOT a string',
49 'key_is_not_a_string'
50 );
51 }
52
53 $transformedValue = $this->transformation->transform($value);
54 $result[$key] = $transformedValue;
55 }
56
57 return $result;
58 }
59
63 public function __invoke($from)
64 {
65 return $this->transform($from);
66 }
67}
$result
An exception for terminatinating execution or to throw for unit testing.
__invoke($from)
Transformations should be callable.This MUST do the same as transform.InvalidArgumentException if the...
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.