ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BasicScalarValueFactory.php
Go to the documentation of this file.
1<?php
2
20
23
24trait BasicScalarValueFactory
25{
26 protected function boolean(bool $bool): BooleanValue
27 {
28 $value = new BooleanValue();
29 $value->setValue($bool);
30
31 return $value;
32 }
33
34 protected function float(float $float): FloatValue
35 {
36 $value = new FloatValue();
37 $value->setValue($float);
38
39 return $value;
40 }
41
42 protected function integer(int $integer): IntegerValue
43 {
44 $value = new IntegerValue();
45 $value->setValue($integer);
46
47 return $value;
48 }
49
50 protected function string(string $string): StringValue
51 {
52 $value = new StringValue();
53 $value->setValue($string);
54
55 return $value;
56 }
57
63 protected function wrapValue($value): Value
64 {
65 // It's already a Value. We don't need to wrap it.
66 if ($value instanceof Value) {
67 return $value;
68 }
69
70 if (is_scalar($value)) {
71 return $this->wrapScalar($value);
72 }
73
74 throw new InvalidArgumentException("The given parameter is not a Background Task Value and cannot be wrapped in a Background Task Value: "
75 . var_export($value, true));
76 }
77
81 protected function scalar($scalar): ScalarValue
82 {
83 $value = new ScalarValue();
84 $value->setValue($scalar);
85
86 return $value;
87 }
88
93 protected function wrapScalar($value): Value
94 {
95 if (is_string($value)) {
96 return $this->string($value);
97 }
98 if (is_bool($value)) {
99 return $this->boolean($value);
100 }
101 if (is_int($value)) {
102 return $this->integer($value);
103 }
104 if (is_float($value)) {
105 return $this->float($value);
106 }
107 if (is_scalar($value)) {
108 return $this->scalar($value);
109 }
110 throw new InvalidArgumentException("The given value " . var_export($value, true)
111 . " is not a scalar and cannot be wrapped.");
112 }
113}
Class Exception Thrown if some procedure did not get the arguments it expected.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...