ILIAS  release_7 Revision v7.30-3-g800a261c036
StringTransformation.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3/* Copyright (c) 2020 Luka K. A. Stocker, Extended GPL, see docs/LICENSE */
4
6
11
13{
14 const BOOL_TRUE = true;
15 const BOOL_FALSE = false;
18 const BOOL_TRUE_STRING = 'true';
19 const BOOL_FALSE_STRING = 'false';
20
23
27 public function transform($from)
28 {
29 if (is_int($from) || is_float($from) || is_double($from)) {
30 return strval($from);
31 }
32
33 if (is_bool($from) || $from === self::BOOL_TRUE_NUMBER || $from === self::BOOL_FALSE_NUMBER) {
34 if ($from === self::BOOL_TRUE || $from === self::BOOL_TRUE_NUMBER) {
36 }
37 if ($from === self::BOOL_FALSE || $from === self::BOOL_FALSE_NUMBER) {
39 }
40 }
41
42 if (is_string($from)) {
43 return $from;
44 }
45
46 if (is_object($from) && method_exists($from, '__toString')) {
47 return (string) $from;
48 }
49
51 sprintf('The value "%s" could not be transformed into a string', $from),
52 'not_string',
53 $from
54 );
55 }
56}
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...
A transformation is a function from one datatype to another.