ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Data.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2018 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3 
5 
8 
12 class Data implements Transformation
13 {
17  protected $type;
18 
22  protected $value;
23 
27  public function __construct($type)
28  {
29  $this->type = $type;
30  if (!method_exists($this->getDataFactory(), $type)) {
31  throw new \InvalidArgumentException("No such type to transform to: $type");
32  }
33  }
34 
38  public function transform($from)
39  {
41  $data_factory = $this->getDataFactory();
42  return $data_factory->$type($from);
43  }
44 
48  public function __invoke($from)
49  {
50  return $this->transform($from);
51  }
52 
57  protected function getDataFactory()
58  {
59  return new DataFactory();
60  }
61 }
transform($from)
Perform the transformation.Please use this for transformations. It&#39;s more performant than calling inv...
Definition: Data.php:38
A transformation is a function from one datatype to another.
$from
__invoke($from)
Transformations should be callable.This MUST do the same as transform.
Definition: Data.php:48
Convert a primitive to a data type.
Definition: Data.php:12
getDataFactory()
Get an instance of the data-factory.
Definition: Data.php:57