-
Notifications
You must be signed in to change notification settings - Fork 449
Expand file tree
/
Copy pathFilesCollection.php
More file actions
230 lines (208 loc) · 5.91 KB
/
Copy pathFilesCollection.php
File metadata and controls
230 lines (208 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
declare(strict_types=1);
namespace GrumPHP\Collection;
use Closure;
use Doctrine\Common\Collections\ArrayCollection;
use GrumPHP\Util\Regex;
use SplFileInfo;
use Traversable;
/**
* @extends ArrayCollection<array-key, string>
*/
class FilesCollection extends ArrayCollection
{
/**
* @deprecated use FilesCollectionFilter::name directly
*
* Adds a rule that files must match.
*
* You can use a pattern (delimited with / sign), a glob or a simple string.
*
* $collection->name('*.php')
* $collection->name('/\.php$/') // same as above
* $collection->name('test.php')
*
* @param string|Regex $pattern A pattern (a regexp, a glob, or a string)
*/
public function name($pattern): self
{
return FilesCollectionFilter::name($this, $pattern);
}
/**
* @deprecated use FilesCollectionFilter::names directly
*
* Adds rules that files must match.
*
* You can use patterns (delimited with / sign), globs or simple strings.
*
* $collection->names(['*.php'])
* $collection->names(['/\.php$/']) // same as above
* $collection->names(['test.php'])
*/
public function names(array $patterns): self
{
return FilesCollectionFilter::names($this, $patterns);
}
/**
* @deprecated use FilesCollectionFilter::notName directly
*
* Adds rules that files must match.
*
* You can use patterns (delimited with / sign), globs or simple strings.
*
* $collection->name('*.php')
* $collection->name('/\.php$/') // same as above
* $collection->name('test.php')
*/
public function notName(string $pattern): self
{
return FilesCollectionFilter::notName($this, $pattern);
}
/**
* @deprecated use FilesCollectionFilter::path directly
*
* Filter by path.
*
* $collection->path('/^spec\/')
*/
public function path(string $pattern): self
{
return FilesCollectionFilter::path($this, $pattern);
}
/**
* @deprecated use FilesCollectionFilter::paths directly
*
* Filter by paths.
*
* $collection->paths(['/^spec\/','/^src\/'])
*/
public function paths(array $patterns): self
{
return FilesCollectionFilter::paths($this, $patterns);
}
/**
* @deprecated use FilesCollectionFilter::notPath directly
*
* Adds rules that filenames must not match.
*
* You can use patterns (delimited with / sign) or simple strings.
*
* $collection->notPath('/^spec\/')
*/
public function notPath(string $pattern): self
{
return FilesCollectionFilter::notPath($this, $pattern);
}
/**
* @deprecated use FilesCollectionFilter::notPaths directly
*
* Adds rules that filenames must not match.
*
* You can use patterns (delimited with / sign) or simple strings.
*
* $collection->notPaths(['/^spec\/','/^src\/'])
*/
public function notPaths(array $pattern): self
{
return FilesCollectionFilter::notPaths($this, $pattern);
}
/**
* @deprecated use FilesCollectionFilter::extensions directly
*/
public function extensions(array $extensions): self
{
return FilesCollectionFilter::extensions($this, $extensions);
}
/**
* @deprecated use FilesCollectionFilter::size directly
*
* Adds tests for file sizes.
*
* $collection->filterBySize('> 10K');
* $collection->filterBySize('<= 1Ki');
* $collection->filterBySize(4);
*
* @see NumberComparator
*/
public function size(string $size): self
{
return FilesCollectionFilter::size($this, $size);
}
/**
* @deprecated use FilesCollectionFilter::date directly
*
* Adds tests for file dates (last modified).
*
* The date must be something that strtotime() is able to parse:
*
* $collection->filterByDate('since yesterday');
* $collection->filterByDate('until 2 days ago');
* $collection->filterByDate('> now - 2 hours');
* $collection->filterByDate('>= 2005-10-15');
*
* @see DateComparator
*/
public function date(string $date): self
{
return FilesCollectionFilter::date($this, $date);
}
/**
* @deprecated use FilesCollectionFilter::filter directly
*
* Filters the iterator with an anonymous function.
*
* The anonymous function receives a \SplFileInfo and must return false
* to remove files.
*
* @see CustomFilterIterator
*
* @psalm-suppress LessSpecificImplementedReturnType
* @psalm-suppress LessSpecificReturnStatement
* @psalm-suppress MoreSpecificReturnType
*/
public function filter(Closure $p): self
{
return FilesCollectionFilter::filter($this, $p);
}
/**
* @deprecated use FilesCollectionFilter::filterByFileList directly
*
* @param Traversable<array-key, SplFileInfo> $fileList
*/
public function filterByFileList(Traversable $fileList): self
{
return FilesCollectionFilter::filterByFileList($this, $fileList);
}
public function ensureFiles(self $files): self
{
$newFiles = new self($this->toArray());
foreach ($files as $file) {
if (!$newFiles->contains($file)) {
$newFiles->add($file);
}
}
return $newFiles;
}
/**
* @deprecated use FilesCollectionFilter::ignoreSymlinks directly
*/
public function ignoreSymlinks(): self
{
return FilesCollectionFilter::ignoreSymlinks($this);
}
public function __serialize(): array
{
return $this->toArray();
}
public function __unserialize(array $data): void
{
$this->clear();
foreach ($data as $path) {
$this->add($path);
}
}
public function toFileList(): string
{
return \implode(PHP_EOL, $this->toArray());
}
}