|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* It's free open-source software released under the MIT License. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Anatoly Fenric <[email protected]> |
|
7
|
|
|
* @copyright Copyright (c) 2018, Anatoly Fenric |
|
8
|
|
|
* @license https://github.com/sunrise-php/http-router/blob/master/LICENSE |
|
9
|
|
|
* @link https://github.com/sunrise-php/http-router |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sunrise\Http\Router\Exception; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Import functions |
|
16
|
|
|
*/ |
|
17
|
|
|
use function is_array; |
|
18
|
|
|
use function is_int; |
|
19
|
|
|
use function is_string; |
|
20
|
|
|
use function is_subclass_of; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* ArgumentException |
|
24
|
|
|
* |
|
25
|
|
|
* @since 2.6.0 |
|
26
|
|
|
*/ |
|
27
|
|
|
class ArgumentException extends Exception |
|
28
|
|
|
{ |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param mixed $operand |
|
32
|
|
|
* @param string $message |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
* @throws static |
|
36
|
|
|
*/ |
|
37
|
51 |
|
public static function assertIsArray($operand, string $message) : void |
|
38
|
|
|
{ |
|
39
|
51 |
|
if (!is_array($operand)) { |
|
40
|
26 |
|
throw new static($message, [ |
|
41
|
26 |
|
'invalidValue' => $operand, |
|
42
|
|
|
]); |
|
43
|
|
|
} |
|
44
|
25 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param mixed $operand |
|
48
|
|
|
* @param string $message |
|
49
|
|
|
* |
|
50
|
|
|
* @return void |
|
51
|
|
|
* @throws static |
|
52
|
|
|
*/ |
|
53
|
12 |
|
public static function assertIsInteger($operand, string $message) : void |
|
54
|
|
|
{ |
|
55
|
12 |
|
if (!is_int($operand)) { |
|
56
|
9 |
|
throw new static($message, [ |
|
57
|
9 |
|
'invalidValue' => $operand, |
|
58
|
|
|
]); |
|
59
|
|
|
} |
|
60
|
3 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param mixed $operand |
|
64
|
|
|
* @param string $message |
|
65
|
|
|
* |
|
66
|
|
|
* @return void |
|
67
|
|
|
* @throws static |
|
68
|
|
|
*/ |
|
69
|
19 |
|
public static function assertIsString($operand, string $message) : void |
|
70
|
|
|
{ |
|
71
|
19 |
|
if (!is_string($operand)) { |
|
72
|
16 |
|
throw new static($message, [ |
|
73
|
16 |
|
'invalidValue' => $operand, |
|
74
|
|
|
]); |
|
75
|
|
|
} |
|
76
|
3 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param mixed $operand |
|
80
|
|
|
* @param string $message |
|
81
|
|
|
* |
|
82
|
|
|
* @return void |
|
83
|
|
|
* @throws static |
|
84
|
|
|
*/ |
|
85
|
101 |
|
public static function assertIsNotEmptyArray($operand, string $message) : void |
|
86
|
|
|
{ |
|
87
|
101 |
|
if ([] === $operand || !is_array($operand)) { |
|
88
|
13 |
|
throw new static($message, [ |
|
89
|
13 |
|
'invalidValue' => $operand, |
|
90
|
|
|
]); |
|
91
|
|
|
} |
|
92
|
88 |
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param mixed $operand |
|
96
|
|
|
* @param string $message |
|
97
|
|
|
* |
|
98
|
|
|
* @return void |
|
99
|
|
|
* @throws static |
|
100
|
|
|
*/ |
|
101
|
173 |
|
public static function assertIsNotEmptyString($operand, string $message) : void |
|
102
|
|
|
{ |
|
103
|
173 |
|
if ('' === $operand || !is_string($operand)) { |
|
104
|
73 |
|
throw new static($message, [ |
|
105
|
73 |
|
'invalidValue' => $operand, |
|
106
|
|
|
]); |
|
107
|
|
|
} |
|
108
|
150 |
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param mixed $operand |
|
112
|
|
|
* @param string $className |
|
113
|
|
|
* @param string $message |
|
114
|
|
|
* |
|
115
|
|
|
* @return void |
|
116
|
|
|
* @throws static |
|
117
|
|
|
*/ |
|
118
|
31 |
|
public static function assertIsSubclassOf($operand, string $className, string $message) : void |
|
119
|
|
|
{ |
|
120
|
31 |
|
if (!is_subclass_of($operand, $className)) { |
|
121
|
25 |
|
throw new static($message, [ |
|
122
|
25 |
|
'invalidValue' => $operand, |
|
123
|
|
|
]); |
|
124
|
|
|
} |
|
125
|
7 |
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @param mixed $operand |
|
129
|
|
|
* @param string $message |
|
130
|
|
|
* |
|
131
|
|
|
* @return void |
|
132
|
|
|
* @throws static |
|
133
|
|
|
*/ |
|
134
|
40 |
|
public static function assertIsNotEmpty($operand, string $message) : void |
|
135
|
|
|
{ |
|
136
|
40 |
|
if ('' === $operand || [] === $operand) { |
|
137
|
4 |
|
throw new static($message, [ |
|
138
|
4 |
|
'invalidValue' => $operand, |
|
139
|
|
|
]); |
|
140
|
|
|
} |
|
141
|
39 |
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|