ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
DateTimeTransformation.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
5
10
16{
18
22 private $factory;
23
27 public function __construct(Factory $factory)
28 {
29 $this->factory = $factory;
30 }
31
35 public function transform($from)
36 {
37 try {
38 return new \DateTimeImmutable($from);
39 } catch (\Exception $e) {
40 throw new \InvalidArgumentException($e->getMessage(), 1);
41 }
42 }
43
47 public function __invoke($from)
48 {
49 return $this->transform($from);
50 }
51}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
Transform a string representing a datetime-value to php's DateTimeImmutable see https://www....
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.