ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BooleanTransformation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use UnexpectedValueException;
28
30{
34
38 public function transform($from): bool
39 {
40 $this->check($from);
41 return (bool) $from;
42 }
43
47 public function getError(): string
48 {
49 return 'The value MUST be of type boolean.';
50 }
51
55 public function check($value)
56 {
57 if (!$this->accepts($value)) {
58 throw new UnexpectedValueException($this->getErrorMessage($value));
59 }
60
61 return null;
62 }
63
67 public function accepts($value): bool
68 {
69 return is_bool($value);
70 }
71
75 public function problemWith($value): ?string
76 {
77 if (!$this->accepts($value)) {
78 return $this->getErrorMessage($value);
79 }
80
81 return null;
82 }
83}
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
getErrorMessage($value)