ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
AddLabels.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2017 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
5
7
11class AddLabels implements Transformation
12{
16 protected $labels;
17
21 public function __construct(array $labels)
22 {
23 $this->labels = $labels;
24 }
25
29 public function transform($from)
30 {
31 if (!is_array($from)) {
32 throw new \InvalidArgumentException(__METHOD__ . " argument is not an array.");
33 }
34
35 if (count($from) != count($this->labels)) {
36 throw new \InvalidArgumentException(__METHOD__ . " number of items in arrays are not equal.");
37 }
38
39 return array_combine($this->labels, $from);
40 }
41
45 public function __invoke($from)
46 {
47 return $this->transform($from);
48 }
49}
An exception for terminatinating execution or to throw for unit testing.
Adds to any array keys for each value.
Definition: AddLabels.php:12
__invoke($from)
Transformations should be callable.This MUST do the same as transform.InvalidArgumentException if the...
Definition: AddLabels.php:45
transform($from)
Perform the transformation.Please use this for transformations. It's more performant than calling inv...
Definition: AddLabels.php:29
A transformation is a function from one datatype to another.
$from