ILIAS  release_7 Revision v7.30-3-g800a261c036
BasicScalarValueFactory.php
Go to the documentation of this file.
1<?php
2
4
7
8trait BasicScalarValueFactory
9{
10
16 protected function boolean($bool)
17 {
18 $value = new BooleanValue();
19 $value->setValue($bool);
20
21 return $value;
22 }
23
24
30 protected function float($float)
31 {
32 $value = new FloatValue();
33 $value->setValue($float);
34
35 return $value;
36 }
37
38
44 protected function integer($integer)
45 {
46 $value = new IntegerValue();
47 $value->setValue($integer);
48
49 return $value;
50 }
51
52
58 protected function string($string)
59 {
60 $value = new StringValue();
61 $value->setValue($string);
62
63 return $value;
64 }
65
66
75 protected function wrapValue($value)
76 {
77 // It's already a Value. We don't need to wrap it.
78 if ($value instanceof Value) {
79 return $value;
80 }
81
82 if (is_scalar($value)) {
83 return $this->wrapScalar($value);
84 }
85
86 throw new InvalidArgumentException("The given parameter is not a Background Task Value and cannot be wrapped in a Background Task Value: "
87 . var_export($value, true));
88 }
89
90
96 protected function scalar($scalar)
97 {
98 $value = new ScalarValue();
99 $value->setValue($scalar);
100
101 return $value;
102 }
103
104
111 protected function wrapScalar($value)
112 {
113 if (is_string($value)) {
114 return $this->string($value);
115 }
116 if (is_bool($value)) {
117 return $this->boolean($value);
118 }
119 if (is_integer($value)) {
120 return $this->integer($value);
121 }
122 if (is_float($value)) {
123 return $this->float($value);
124 }
125 if (is_scalar($value)) {
126 return $this->scalar($value);
127 }
128 throw new InvalidArgumentException("The given value " . var_export($value, true)
129 . " is not a scalar and cannot be wrapped.");
130 }
131}
An exception for terminatinating execution or to throw for unit testing.