ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
BooleanTransformation.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
28 
30 {
33  use ProblemBuilder;
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:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getErrorMessage($value)
Get the problem message.