ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
NewMethodTransformation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use InvalidArgumentException;
27
29{
32
33 private object $object;
34 private string $method;
35
36 public function __construct(object $object, string $methodToCall)
37 {
38 if (false === method_exists($object, $methodToCall)) {
39 throw new InvalidArgumentException(
40 'The second parameter MUST be an method of the object'
41 );
42 }
43
44 $this->object = $object;
45 $this->method = $methodToCall;
46 }
47
51 public function transform($from)
52 {
53 if (false === is_array($from)) {
54 $from = [$from];
55 }
56
57 return call_user_func_array([$this->object, $this->method], $from);
58 }
59}
A transformation is a function from one datatype to another.