1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PHPSu\ShellCommandBuilder\Conditional; |
6
|
|
|
|
7
|
|
|
use PHPSu\ShellCommandBuilder\Definition\ConditionalOperator; |
8
|
|
|
use PHPSu\ShellCommandBuilder\ShellInterface; |
9
|
|
|
|
10
|
|
|
final class FileExpression extends BasicExpression |
11
|
|
|
{ |
12
|
|
|
protected $escapedValue = true; |
13
|
|
|
|
14
|
|
|
public static function create(bool $useBashBrackets = true, bool $negateExpression = false): FileExpression |
15
|
|
|
{ |
16
|
|
|
return new self($useBashBrackets, $negateExpression); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param string|ShellInterface $file |
21
|
|
|
* @return $this |
22
|
|
|
*/ |
23
|
|
|
public function exists($file): FileExpression |
24
|
|
|
{ |
25
|
|
|
$this->operator = ConditionalOperator::FILE_EXISTS; |
26
|
|
|
$this->compareWith = $file; |
27
|
|
|
return $this; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string|ShellInterface $file |
32
|
|
|
* @return $this |
33
|
|
|
*/ |
34
|
|
|
public function existsBlockSpecial($file): FileExpression |
35
|
|
|
{ |
36
|
|
|
$this->operator = ConditionalOperator::FILE_EXISTS_BLOCK_SPECIAL; |
37
|
|
|
$this->compareWith = $file; |
38
|
|
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string|ShellInterface $file |
43
|
|
|
* @return $this |
44
|
|
|
*/ |
45
|
|
|
public function existsCharacterSpecial($file): FileExpression |
46
|
|
|
{ |
47
|
|
|
$this->operator = ConditionalOperator::FILE_EXISTS_CHARACTER_SPECIAL; |
48
|
|
|
$this->compareWith = $file; |
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string|ShellInterface $directory |
54
|
|
|
* @return $this |
55
|
|
|
*/ |
56
|
|
|
public function isDirectory($directory): FileExpression |
57
|
|
|
{ |
58
|
|
|
$this->operator = ConditionalOperator::FILE_EXISTS_IS_DIRECTORY; |
59
|
|
|
$this->compareWith = $directory; |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string|ShellInterface $file |
65
|
|
|
* @return $this |
66
|
|
|
*/ |
67
|
|
|
public function isRegularFile($file): FileExpression |
68
|
|
|
{ |
69
|
|
|
$this->operator = ConditionalOperator::FILE_EXISTS_REGULAR_FILE; |
70
|
|
|
$this->compareWith = $file; |
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string|ShellInterface $file |
76
|
|
|
* @return $this |
77
|
|
|
*/ |
78
|
|
|
public function hasSetGroupIDBit($file): FileExpression |
79
|
|
|
{ |
80
|
|
|
$this->operator = ConditionalOperator::FILE_EXISTS_HAS_SET_GROUP_ID; |
81
|
|
|
$this->compareWith = $file; |
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string|ShellInterface $file |
87
|
|
|
* @return $this |
88
|
|
|
*/ |
89
|
|
|
public function symbolicLink($file): FileExpression |
90
|
|
|
{ |
91
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_SYMBOLIC_LINK; |
92
|
|
|
$this->compareWith = $file; |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string|ShellInterface $file |
98
|
|
|
* @return $this |
99
|
|
|
*/ |
100
|
|
|
public function withStickyBit($file): FileExpression |
101
|
|
|
{ |
102
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_STICKY_BIT; |
103
|
|
|
$this->compareWith = $file; |
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param string|ShellInterface $file |
109
|
|
|
* @return $this |
110
|
|
|
*/ |
111
|
|
|
public function isNamedPipe($file): FileExpression |
112
|
|
|
{ |
113
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_NAMED_PIPE; |
114
|
|
|
$this->compareWith = $file; |
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param string|ShellInterface $file |
120
|
|
|
* @return $this |
121
|
|
|
*/ |
122
|
|
|
public function isReadably($file): FileExpression |
123
|
|
|
{ |
124
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_READABLE; |
125
|
|
|
$this->compareWith = $file; |
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string|ShellInterface $file |
131
|
|
|
* @return $this |
132
|
|
|
*/ |
133
|
|
|
public function notEmpty($file): FileExpression |
134
|
|
|
{ |
135
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_NOT_EMPTY; |
136
|
|
|
$this->compareWith = $file; |
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param string|ShellInterface $file |
142
|
|
|
* @return $this |
143
|
|
|
*/ |
144
|
|
|
public function openReferringToTerminal($file): FileExpression |
145
|
|
|
{ |
146
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_OPEN_REFERING_TO_TERMINAL; |
147
|
|
|
$this->compareWith = $file; |
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param string|ShellInterface $file |
153
|
|
|
* @return $this |
154
|
|
|
*/ |
155
|
|
|
public function hasSetUserIDBit($file): FileExpression |
156
|
|
|
{ |
157
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_HAS_SET_USER_ID; |
158
|
|
|
$this->compareWith = $file; |
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param string|ShellInterface $file |
164
|
|
|
* @return $this |
165
|
|
|
*/ |
166
|
|
|
public function writable($file): FileExpression |
167
|
|
|
{ |
168
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_WRITABLE; |
169
|
|
|
$this->compareWith = $file; |
170
|
|
|
return $this; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param string|ShellInterface $file |
175
|
|
|
* @return $this |
176
|
|
|
*/ |
177
|
|
|
public function executable($file): FileExpression |
178
|
|
|
{ |
179
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_EXECUTABLE; |
180
|
|
|
$this->compareWith = $file; |
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param string|ShellInterface $file |
186
|
|
|
* @return $this |
187
|
|
|
*/ |
188
|
|
|
public function ownedByGroupId($file): FileExpression |
189
|
|
|
{ |
190
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_OWNED_BY_GROUP_ID; |
191
|
|
|
$this->compareWith = $file; |
192
|
|
|
return $this; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param string|ShellInterface $file |
197
|
|
|
* @return $this |
198
|
|
|
*/ |
199
|
|
|
public function modifiedSinceLastRead($file): FileExpression |
200
|
|
|
{ |
201
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_MODIFIED_SINCE_LAST_READ; |
202
|
|
|
$this->compareWith = $file; |
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param string|ShellInterface $file |
208
|
|
|
* @return $this |
209
|
|
|
*/ |
210
|
|
|
public function ownedByUserId($file): FileExpression |
211
|
|
|
{ |
212
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_OWNED_BY_USER_ID; |
213
|
|
|
$this->compareWith = $file; |
214
|
|
|
return $this; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param string|ShellInterface $file |
219
|
|
|
* @return $this |
220
|
|
|
*/ |
221
|
|
|
public function isSocket($file): FileExpression |
222
|
|
|
{ |
223
|
|
|
$this->operator = ConditionalOperator::FILE_EXSITS_IS_SOCKET; |
224
|
|
|
$this->compareWith = $file; |
225
|
|
|
return $this; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @param string|ShellInterface $fileA |
230
|
|
|
* @param string|ShellInterface $fileB |
231
|
|
|
* @return $this |
232
|
|
|
*/ |
233
|
|
|
public function refersToSameDevice($fileA, $fileB): FileExpression |
234
|
|
|
{ |
235
|
|
|
$this->operator = ConditionalOperator::FILE_REFERS_TO_SAME_DEVICE; |
236
|
|
|
$this->compare = $fileA; |
237
|
|
|
$this->compareWith = $fileB; |
238
|
|
|
return $this; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @param string|ShellInterface $fileA |
243
|
|
|
* @param string|ShellInterface $fileB |
244
|
|
|
* @return $this |
245
|
|
|
*/ |
246
|
|
|
public function isNewerThan($fileA, $fileB): FileExpression |
247
|
|
|
{ |
248
|
|
|
$this->operator = ConditionalOperator::FILE_IS_NEWER_THAN; |
249
|
|
|
$this->compare = $fileA; |
250
|
|
|
$this->compareWith = $fileB; |
251
|
|
|
return $this; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @param string|ShellInterface $fileA |
256
|
|
|
* @param string|ShellInterface $fileB |
257
|
|
|
* @return $this |
258
|
|
|
*/ |
259
|
|
|
public function isOlderThan($fileA, $fileB): FileExpression |
260
|
|
|
{ |
261
|
|
|
$this->operator = ConditionalOperator::FILE_IS_OLDER_THAN; |
262
|
|
|
$this->compare = $fileA; |
263
|
|
|
$this->compareWith = $fileB; |
264
|
|
|
return $this; |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|