forked from ILIAS-eLearning/ILIAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConstraint.php
71 lines (64 loc) · 1.84 KB
/
Constraint.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/* Copyright (c) 2017 Richard Klees <[email protected]> Extended GPL, see docs/LICENSE */
/* Copyright (c) 2017 Stefan Hecken <[email protected]> Extended GPL, see docs/LICENSE */
namespace ILIAS\Refinery;
use ILIAS\Data\Result;
/**
* A constraint encodes some resrtictions on values.
*
* Constraints MUST NOT modify the supplied value.
*/
interface Constraint extends Transformation
{
/**
* Checks the provided value.
*
* Should not throw if accepts($value).
*
* @throws \UnexpectedValueException if value does not comply with encoded constraint.
* @param mixed $value
* @return null
*/
public function check($value);
/**
* Tells if the provided value complies.
*
* @param mixed $value
* @return bool
*/
public function accepts($value);
/**
* Tells what the problem with the provided value is.
*
* Should return null if accepts($value).
*
* @param mixed $value
* @return string|null
*/
public function problemWith($value);
/**
* Restricts a Result.
*
* Must do nothing with the result if $result->isError().
* Must replace the result with an error according to problemWith() if
* !accepts($result->value()).
*
* @param Result $result
* @return Result
*/
public function applyTo(Result $result) : Result;
/**
* Get a constraint like this one with a builder for a custom error
* message.
*
* problemWith() must return an error message according to the new builder for
* the new constraint.
*
* The builder needs to be callable that takes two parameters:
*
*
* @param callable $builder
* @return Constraint
*/
public function withProblemBuilder(callable $builder);
}