1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* this file is part of pipelines */ |
4
|
|
|
|
5
|
|
|
namespace Ktomk\Pipelines\File; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class References |
9
|
|
|
* |
10
|
|
|
* Utility class for pipeline references (ids) definition and validation |
11
|
|
|
* |
12
|
|
|
* pipeline : that what can be referenced (id): default, branches/**, custom/foo etc. |
13
|
|
|
* section : branches, tags, bookmarks, pull-requests, custom |
14
|
|
|
* pattern section : a section that can match by pattern to some input (all sections but custom) |
15
|
|
|
* |
16
|
|
|
* @package Ktomk\Pipelines\File |
17
|
|
|
*/ |
18
|
|
|
class ReferenceTypes |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* pipelines sections on first level that contain pipelines on second level |
22
|
|
|
* |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private static $sections = array('branches', 'tags', 'bookmarks', 'pull-requests', 'custom'); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $id |
29
|
|
|
* |
30
|
|
|
* @return bool |
31
|
|
|
*/ |
32
|
7 |
|
public static function isValidId($id) |
33
|
|
|
{ |
34
|
7 |
|
return (bool)preg_match('~^(default|(' . implode('|', self::$sections) . ')/[^\x00-\x1F\x7F-\xFF]*)$~', $id); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* a section that contains pipelines that can match by pattern |
39
|
|
|
* |
40
|
|
|
* @param null|int|string $section |
41
|
|
|
* |
42
|
|
|
* @return bool |
43
|
|
|
*/ |
44
|
9 |
|
public static function isPatternSection($section) |
45
|
|
|
{ |
46
|
9 |
|
return is_string($section) && \in_array($section, array_slice(self::$sections, 0, 4), true); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param null|int|string $section |
51
|
|
|
* |
52
|
|
|
* @return bool |
53
|
|
|
*/ |
54
|
9 |
|
public static function isSection($section) |
55
|
|
|
{ |
56
|
9 |
|
return is_string($section) && in_array($section, self::$sections, true); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* get sections |
61
|
|
|
* |
62
|
|
|
* @return array|string[] |
63
|
|
|
*/ |
64
|
1 |
|
public static function getSections() |
65
|
|
|
{ |
66
|
1 |
|
return self::$sections; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|