ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
StringTransformation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
29{
32 private const BOOL_TRUE = true;
33 private const BOOL_FALSE = false;
34 private const BOOL_TRUE_NUMBER = 1;
35 private const BOOL_FALSE_NUMBER = 0;
36 private const BOOL_TRUE_STRING = 'true';
37 private const BOOL_FALSE_STRING = 'false';
38
42 public function transform($from): string
43 {
44 if (is_int($from) || is_float($from)) {
45 return (string) $from;
46 }
47
48 if (is_bool($from) || $from === self::BOOL_TRUE_NUMBER || $from === self::BOOL_FALSE_NUMBER) {
49 if ($from === self::BOOL_TRUE || $from === self::BOOL_TRUE_NUMBER) {
51 }
52 if ($from === self::BOOL_FALSE || $from === self::BOOL_FALSE_NUMBER) {
54 }
55 }
56
57 if (is_string($from)) {
58 return $from;
59 }
60
61 if (is_object($from) && method_exists($from, '__toString')) {
62 return (string) $from;
63 }
64
66 sprintf('The value "%s" could not be transformed into a string', var_export($from, true)),
67 'not_string',
68 $from
69 );
70 }
71}
A transformation is a function from one datatype to another.