ILIAS
release_6 Revision v6.24-5-g0c8bfefb3b8
◀ ilDoc Overview
DictionaryTransformation.php
Go to the documentation of this file.
1
<?php
2
declare(strict_types=1);
3
/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
9
namespace
ILIAS\Refinery\To\Transformation
;
10
11
use
ILIAS\Refinery\DeriveApplyToFromTransform
;
12
use
ILIAS\Refinery\Transformation
;
13
use
ILIAS\Refinery\ConstraintViolationException
;
14
15
class
DictionaryTransformation
implements
Transformation
16
{
17
use
DeriveApplyToFromTransform
;
18
22
private
$transformation
;
23
27
public
function
__construct
(
Transformation
$transformation
)
28
{
29
$this->transformation =
$transformation
;
30
}
31
35
public
function
transform
($from)
36
{
37
if
(
false
=== is_array($from)) {
38
throw
new
ConstraintViolationException
(
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)) {
47
throw
new
ConstraintViolationException
(
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
}
ILIAS\Refinery\To\Transformation\DictionaryTransformation\__invoke
__invoke($from)
Transformations should be callable.This MUST do the same as transform.
Definition:
DictionaryTransformation.php:63
$result
$result
Definition:
CleanUpTest.php:463
ILIAS\Refinery\To\Transformation\DictionaryTransformation\transform
transform($from)
Perform the transformation.Please use this for transformations. It's more performant than calling inv...
Definition:
DictionaryTransformation.php:35
ILIAS\Refinery\To\Transformation\DictionaryTransformation\__construct
__construct(Transformation $transformation)
Definition:
DictionaryTransformation.php:27
Transformation
ILIAS\Refinery\DeriveApplyToFromTransform
trait DeriveApplyToFromTransform
Definition:
DeriveApplyToFromTransform.php:13
ILIAS\Refinery\To\Transformation
Definition:
BooleanTransformation.php:10
ILIAS\Refinery\ConstraintViolationException
Definition:
ConstraintViolationException.php:14
ILIAS\Refinery\To\Transformation\DictionaryTransformation
Definition:
DictionaryTransformation.php:15
ILIAS\Refinery\Transformation
A transformation is a function from one datatype to another.
Definition:
Transformation.php:17
ILIAS\Refinery\To\Transformation\DictionaryTransformation\$transformation
$transformation
Definition:
DictionaryTransformation.php:22
ConstraintViolationException
src
Refinery
To
Transformation
DictionaryTransformation.php
Generated on Wed Sep 3 2025 20:01:29 for ILIAS by
1.8.13 (using
Doxyfile
)