ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
NewMethodTransformation.php
Go to the documentation of this file.
1<?php
2declare(strict_types=1);
3
4/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
5
11
15
17{
19
23 private $object;
24
28 private $method;
29
34 public function __construct(object $object, string $methodToCall)
35 {
36 if (false === method_exists($object, $methodToCall)) {
37 throw new \InvalidArgumentException(
38 'The second parameter MUST be an method of the object'
39 );
40 }
41
42 $this->object = $object;
43 $this->method = $methodToCall;
44 }
45
50 public function transform($from)
51 {
52 if (false === is_array($from)) {
53 $from = array($from);
54 }
55
56 return call_user_func_array(array($this->object, $this->method), $from);
57 }
58
62 public function __invoke($from)
63 {
64 return $this->transform($from);
65 }
66}
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...
__invoke($from)
Transformations should be callable.This MUST do the same as transform.InvalidArgumentException if the...
A transformation is a function from one datatype to another.