|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Assert |
|
4
|
|
|
* |
|
5
|
|
|
* LICENSE |
|
6
|
|
|
* |
|
7
|
|
|
* This source file is subject to the MIT license that is bundled |
|
8
|
|
|
* with this package in the file LICENSE.txt. |
|
9
|
|
|
* If you did not receive a copy of the license and are unable to |
|
10
|
|
|
* obtain it through the world-wide-web, please send an email |
|
11
|
|
|
* to [email protected] so I can send you a copy immediately. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Assert; |
|
15
|
|
|
|
|
16
|
|
|
if ( ! function_exists(__NAMESPACE__ . '\that')) { |
|
17
|
|
|
/** |
|
18
|
|
|
* Start validation on a value, returns {@link AssertionChain} |
|
19
|
|
|
* |
|
20
|
|
|
* The invocation of this method starts an assertion chain |
|
21
|
|
|
* that is happening on the passed value. |
|
22
|
|
|
* |
|
23
|
|
|
* @example |
|
24
|
|
|
* |
|
25
|
|
|
* \Assert\that($value)->notEmpty()->integer(); |
|
26
|
|
|
* \Assert\that($value)->nullOr()->string()->startsWith("Foo"); |
|
27
|
|
|
* |
|
28
|
|
|
* The assertion chain can be stateful, that means be careful when you reuse |
|
29
|
|
|
* it. You should never pass around the chain. |
|
30
|
|
|
* |
|
31
|
|
|
* @param mixed $value |
|
32
|
|
|
* @param string $defaultMessage |
|
33
|
|
|
* @param string $defaultPropertyPath |
|
34
|
|
|
* |
|
35
|
|
|
* @return \Assert\AssertionChain |
|
36
|
|
|
*/ |
|
37
|
|
|
function that($value, $defaultMessage = null, $defaultPropertyPath = null) |
|
38
|
|
|
{ |
|
39
|
|
|
return new AssertionChain($value, $defaultMessage, $defaultPropertyPath); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if ( ! function_exists(__NAMESPACE__ . '\thatAll')) { |
|
44
|
|
|
/** |
|
45
|
|
|
* Start validation on a set of values, returns {@link AssertionChain} |
|
46
|
|
|
* |
|
47
|
|
|
* @return \Assert\AssertionChain |
|
48
|
|
|
*/ |
|
49
|
|
|
function thatAll($values, $defaultMessage = null, $defaultPropertyPath = null) |
|
50
|
|
|
{ |
|
51
|
|
|
return that($values, $defaultMessage, $defaultPropertyPath)->all(); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
if ( ! function_exists(__NAMESPACE__ . '\thatNullOr')) { |
|
56
|
|
|
/** |
|
57
|
|
|
* Start validation and allow NULL, returns {@link AssertionChain} |
|
58
|
|
|
* |
|
59
|
|
|
* @return \Assert\AssertionChain |
|
60
|
|
|
*/ |
|
61
|
|
|
function thatNullOr($value, $defaultMessage = null, $defaultPropertyPath = null) |
|
62
|
|
|
{ |
|
63
|
|
|
return that($value, $defaultMessage, $defaultPropertyPath)->nullOr(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if ( ! function_exists(__NAMESPACE__ . '\lazy')) { |
|
68
|
|
|
/** |
|
69
|
|
|
* Create a lazy assertion object. |
|
70
|
|
|
* |
|
71
|
|
|
* @return \Assert\LazyAssertion |
|
72
|
|
|
*/ |
|
73
|
|
|
function lazy() |
|
74
|
|
|
{ |
|
75
|
|
|
return new LazyAssertion(); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|