ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
NewMethodTransformation.php
Go to the documentation of this file.
1 <?php
2 declare(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 }
transform($from)
Perform the transformation.Please use this for transformations. It&#39;s more performant than calling inv...
__invoke($from)
Transformations should be callable.This MUST do the same as transform.
A transformation is a function from one datatype to another.