|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the puli/manager package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Puli\Manager\Assert; |
|
13
|
|
|
|
|
14
|
|
|
use Webmozart\PathUtil\Path; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Domain-specific assertions. |
|
18
|
|
|
* |
|
19
|
|
|
* @since 1.0 |
|
20
|
|
|
* |
|
21
|
|
|
* @author Bernhard Schussek <[email protected]> |
|
22
|
|
|
* |
|
23
|
|
|
* @method static void nullOrSystemPath($value, $message = null, $propertyPath = null) |
|
24
|
|
|
* @method static void nullOrAbsoluteSystemPath($value, $message = null, $propertyPath = null) |
|
25
|
|
|
* @method static void nullOrModuleName($value, $message = null, $propertyPath = null) |
|
26
|
|
|
* @method static void nullOrQuery($value, $message = null, $propertyPath = null) |
|
27
|
|
|
* @method static void nullOrLanguage($value, $message = null, $propertyPath = null) |
|
28
|
|
|
* @method static void nullOrTypeName($value, $message = null, $propertyPath = null) |
|
29
|
|
|
* @method static void nullOrParameterName($value, $message = null, $propertyPath = null) |
|
30
|
|
|
* @method static void nullOrParameterValue($value, $message = null, $propertyPath = null) |
|
31
|
|
|
* @method static void allSystemPath($value, $object, $message = null, $propertyPath = null) |
|
32
|
|
|
* @method static void allAbsoluteSystemPath($value, $object, $message = null, $propertyPath = null) |
|
33
|
|
|
* @method static void allModuleName($value, $object, $message = null, $propertyPath = null) |
|
34
|
|
|
* @method static void allQuery($value, $message = null, $propertyPath = null) |
|
35
|
|
|
* @method static void allLanguage($value, $message = null, $propertyPath = null) |
|
36
|
|
|
* @method static void allTypeName($value, $message = null, $propertyPath = null) |
|
37
|
|
|
* @method static void allParameterName($value, $message = null, $propertyPath = null) |
|
38
|
|
|
* @method static void allParameterValue($value, $message = null, $propertyPath = null) |
|
39
|
|
|
*/ |
|
40
|
|
|
class Assert extends \Webmozart\Assert\Assert |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
110 |
|
public static function path($value) |
|
43
|
|
|
{ |
|
44
|
110 |
|
self::stringNotEmpty($value, 'The path must be a non-empty string. Got: %s'); |
|
45
|
108 |
|
self::startsWith($value, '/', 'The path %s is not absolute.'); |
|
46
|
108 |
|
} |
|
47
|
|
|
|
|
48
|
206 |
|
public static function systemPath($value) |
|
49
|
|
|
{ |
|
50
|
206 |
|
self::stringNotEmpty($value, 'The path must be a non-empty string. Got: %s'); |
|
51
|
204 |
|
} |
|
52
|
|
|
|
|
53
|
539 |
|
public static function absoluteSystemPath($value) |
|
54
|
|
|
{ |
|
55
|
539 |
|
self::stringNotEmpty($value, 'The path must be a non-empty string. Got: %s'); |
|
56
|
537 |
|
self::true(Path::isAbsolute($value), sprintf( |
|
57
|
537 |
|
'The path %s is not absolute.', |
|
58
|
|
|
$value |
|
59
|
|
|
)); |
|
60
|
537 |
|
} |
|
61
|
|
|
|
|
62
|
550 |
|
public static function moduleName($value) |
|
63
|
|
|
{ |
|
64
|
550 |
|
self::stringNotEmpty($value, 'The module name must be a non-empty string. Got: %s'); |
|
65
|
|
|
|
|
66
|
544 |
|
if ('__root__' !== $value) { |
|
67
|
544 |
|
self::contains($value, '/', 'The module name %s must contain a vendor name followed by a "/".'); |
|
68
|
|
|
} |
|
69
|
544 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
public static function query($value) |
|
72
|
|
|
{ |
|
73
|
|
|
self::stringNotEmpty($value, 'The query must be a non-empty string. Got: %s'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public static function language($value) |
|
77
|
|
|
{ |
|
78
|
|
|
self::stringNotEmpty($value, 'The language must be a non-empty string. Got: %s'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public static function typeName($value) |
|
82
|
|
|
{ |
|
83
|
|
|
self::stringNotEmpty($value, 'The type name must be a non-empty string. Got: %s'); |
|
84
|
|
|
self::contains($value, '/', 'The type name %s must contain a vendor name followed by a "/".'); |
|
85
|
|
|
self::startsWithLetter($value, 'The type name %s must start with a letter.'); |
|
86
|
|
|
self::regex($value, '~^[a-z][a-z0-9\-]*/[a-z0-9\-]+$~', 'The type name %s must contain lower-case characters, digits and hyphens only.'); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
111 |
|
public static function parameterName($value) |
|
90
|
|
|
{ |
|
91
|
111 |
|
self::stringNotEmpty($value, 'The parameter name must be a non-empty string. Got: %s'); |
|
92
|
108 |
|
self::startsWithLetter($value, 'The parameter name %s must start with a letter.'); |
|
93
|
108 |
|
self::regex($value, '~^[a-z][a-z0-9\-]*$~', 'The parameter %s name must contain lower-case characters, digits and hyphens only.'); |
|
94
|
108 |
|
} |
|
95
|
|
|
|
|
96
|
88 |
|
public static function parameterValue($value) |
|
97
|
|
|
{ |
|
98
|
88 |
|
self::scalar($value, 'The parameter value must be a scalar. Got: %s'); |
|
99
|
87 |
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|