ILIAS
trunk Revision v11.0_alpha-1862-g4e205cb56d4
◀ ilDoc Overview
Main Page
Related Pages
Modules
+
Namespaces
Namespace List
+
Namespace Members
+
All
$
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
x
+
Variables
$
c
e
g
h
j
l
m
p
s
t
u
v
+
Enumerations
a
c
e
f
i
j
l
m
n
o
p
r
s
t
u
v
z
+
Enumerator
a
c
d
e
f
g
i
l
m
n
o
p
q
s
t
u
v
y
+
Data Structures
Data Structures
Data Structure Index
Class Hierarchy
+
Data Fields
+
All
$
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Ö
+
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
+
Variables
$
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Ö
Enumerations
Enumerator
+
Files
File List
+
Globals
+
All
$
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
z
+
Functions
a
b
c
d
e
f
g
h
i
m
n
p
r
s
t
u
v
+
Variables
$
a
c
e
g
h
i
m
n
o
p
r
s
t
u
v
z
Enumerations
Enumerator
Examples
•
All
Data Structures
Namespaces
Files
Functions
Variables
Enumerations
Enumerator
Modules
Pages
FloatTransformation.php
Go to the documentation of this file.
1
<?php
2
19
declare(strict_types=1);
20
21
namespace
ILIAS\Refinery\KindlyTo\Transformation
;
22
23
use
ILIAS\Refinery\DeriveApplyToFromTransform
;
24
use
ILIAS\Refinery\DeriveInvokeFromTransform
;
25
use
ILIAS\Refinery\Transformation
;
26
use
ILIAS\Refinery\ConstraintViolationException
;
27
28
class
FloatTransformation
implements
Transformation
29
{
30
use
DeriveApplyToFromTransform
;
31
use
DeriveInvokeFromTransform
;
32
private
const
REG_STRING
=
'/^\s*(-?(0|([1-9]\d*)))([.,]\d*)?\s*$/'
;
33
private
const
REG_STRING_FLOATING
=
'/^\s*-?\d+[eE]-?\d+\s*$/'
;
34
38
public
function
transform
($from): float
39
{
40
if
($from !== INF && $from !== -INF && is_float($from) && !is_nan($from)) {
41
return
$from;
42
}
43
44
if
(is_int($from)) {
45
return
(
float
) $from;
46
}
47
48
if
(is_bool($from)) {
49
return
(
float
) $from;
50
}
51
52
if
(is_string($from)) {
53
$preg_match_string = preg_match(self::REG_STRING, $from, $RegMatch);
54
if
($preg_match_string) {
55
return
(
float
) str_replace(
','
,
'.'
, $from);
56
}
57
58
$preg_match_floating_string = preg_match(self::REG_STRING_FLOATING, $from, $RegMatch);
59
if
($preg_match_floating_string) {
60
return
(
float
) $from;
61
}
62
63
throw
new
ConstraintViolationException
(
64
sprintf(
'The value "%s" could not be transformed into an float'
, var_export($from,
true
)),
65
'not_float'
,
66
$from
67
);
68
}
69
70
throw
new
ConstraintViolationException
(
71
sprintf(
'The value "%s" could not be transformed into an float'
, var_export($from,
true
)),
72
'not_float'
,
73
$from
74
);
75
}
76
}
ILIAS\Refinery\DeriveInvokeFromTransform
trait DeriveInvokeFromTransform
Definition:
DeriveInvokeFromTransform.php:24
ILIAS\Refinery\KindlyTo\Transformation\FloatTransformation\REG_STRING
const REG_STRING
Definition:
FloatTransformation.php:32
ILIAS\Refinery\DeriveApplyToFromTransform
trait DeriveApplyToFromTransform
Definition:
DeriveApplyToFromTransform.php:29
ILIAS\Refinery\KindlyTo\Transformation\FloatTransformation\REG_STRING_FLOATING
const REG_STRING_FLOATING
Definition:
FloatTransformation.php:33
Transformation
ILIAS\Refinery\ConstraintViolationException
Definition:
ConstraintViolationException.php:29
ILIAS\Refinery\KindlyTo\Transformation\FloatTransformation\transform
transform($from)
Definition:
FloatTransformation.php:38
ILIAS\Refinery\Transformation
A transformation is a function from one datatype to another.
Definition:
Transformation.php:34
ConstraintViolationException
ILIAS\Refinery\KindlyTo\Transformation
Definition:
BooleanTransformation.php:21
ILIAS\Refinery\KindlyTo\Transformation\FloatTransformation
Definition:
FloatTransformation.php:28
components
ILIAS
Refinery
src
KindlyTo
Transformation
FloatTransformation.php
Generated on Thu Apr 24 2025 23:05:04 for ILIAS by
1.8.13 (using
Doxyfile
)