1 | <?php |
||
8 | class Excludes { |
||
9 | |||
10 | /** |
||
11 | * The array of exclude rules. |
||
12 | * |
||
13 | * @var array |
||
14 | */ |
||
15 | private $excludes; |
||
16 | |||
17 | /** |
||
18 | * The array of default exclude rules. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | private $default_excludes = array( |
||
23 | '.svn', |
||
24 | '_svn', |
||
25 | 'CVS', |
||
26 | '_darcs', |
||
27 | '.arch-params', |
||
28 | '.monotone', |
||
29 | '.bzr', |
||
30 | '.git', |
||
31 | '.hg', |
||
32 | 'backupwp', |
||
33 | 'backwpup-*', |
||
34 | 'updraft', |
||
35 | '(?:wp-)?snapshots?', // wp-snapshots, snapshots, snapshot |
||
36 | 'backupbuddy_backups', |
||
37 | 'pb_backupbuddy', |
||
38 | 'backup-db', |
||
39 | 'Envato-backups', |
||
40 | 'managewp', |
||
41 | 'backupwordpress-*-backups', |
||
42 | ); |
||
43 | |||
44 | public function __construct( $excludes = array() ) { |
||
45 | $this->set_excludes( $excludes ); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Set the exclude rules. |
||
50 | * |
||
51 | * Excludes rules should be a complete or partial directory or file path. |
||
52 | * Wildcards can be specified with the * character. |
||
53 | * |
||
54 | * @param string|array $excludes The list of exclude rules, accepts either |
||
55 | * a comma separated list or an array. |
||
56 | */ |
||
57 | public function set_excludes( $excludes ) { |
||
58 | |||
59 | if ( is_string( $excludes ) ) { |
||
60 | $excludes = explode( ',', $excludes ); |
||
61 | } |
||
62 | |||
63 | $this->excludes = $excludes; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Get the excludes. |
||
68 | * |
||
69 | * Returns any user set excludes as well as the default list. |
||
70 | * |
||
71 | * @return array The array of exclude rules. |
||
72 | */ |
||
73 | public function get_excludes() { |
||
76 | |||
77 | /** |
||
78 | * Get the excludes prepared for use with regex. |
||
79 | * |
||
80 | * The primary difference being that any wildcard (*) rules are converted to the regex |
||
81 | * fragment `[\s\S]*?`. |
||
82 | * |
||
83 | * @return array The array of exclude rules. |
||
84 | */ |
||
85 | public function get_excludes_for_regex() { |
||
108 | |||
109 | /** |
||
110 | * Get the user defined excludes. |
||
111 | * |
||
112 | * @return array The array of excludes. |
||
113 | */ |
||
114 | public function get_user_excludes() { |
||
125 | |||
126 | /** |
||
127 | * Get the array of default excludes. |
||
128 | * |
||
129 | * @return array The array of excludes. |
||
130 | */ |
||
131 | public function get_default_excludes() { |
||
151 | |||
152 | /** |
||
153 | * Normalise the exclude rules so they are ready to work with. |
||
154 | * |
||
155 | * @param array $excludes The array of exclude rules to normalise. |
||
156 | * |
||
157 | * @return array The array of normalised rules. |
||
158 | */ |
||
159 | public function normalize( $excludes ) { |
||
183 | |||
184 | /** |
||
185 | * Check if a file is excluded, |
||
186 | * i.e. excluded directly or is in an excluded folder. |
||
187 | * |
||
188 | * @param \SplFileInfo $file File to check if it's excluded. |
||
189 | * |
||
190 | * @return bool|null True if file is excluded, false otherwise. |
||
191 | * Null - if it's not a file. |
||
192 | */ |
||
193 | public function is_file_excluded( \SplFileInfo $file ) { |
||
208 | } |
||
209 |