ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
InArrayTransformation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
36{
38
40 private $error;
41
46 public function __construct(private readonly array $valid_members, private readonly Language $lng)
47 {
48 if (!array_is_list($this->valid_members)) {
49 throw new ConstraintViolationException('The valid members MUST be a list.', 'array_not_a_list');
50 }
51 $this->error = sprintf(
52 'The value MUST be one of: %s.',
53 join(', ', array_map(json_encode(...), $this->valid_members))
54 );
55 }
56
57 public function accepts($value): bool
58 {
59 return in_array($value, $this->valid_members, true);
60 }
61
62 public function getError()
63 {
64 return $this->error;
65 }
66}
Validates that the value to be transformed is in the set given to this transformation.
accepts($value)
Tells if the provided value complies.
__construct(private readonly array $valid_members, private readonly Language $lng)
trait DeriveTransformWithProblem
This trait is a convenience trait which uses DeriveApplyToFromTransform, DeriveInvokeFromTransform an...
error(string $a_errmsg)
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
global $lng
Definition: privfeed.php:31