@@ -62,13 +62,15 @@ |
||
62 | 62 | */ |
63 | 63 | public function getContents(): string |
64 | 64 | { |
65 | - if (!$this->exists()) { |
|
65 | + if (!$this->exists()) |
|
66 | + { |
|
66 | 67 | throw $this->buildNotFoundException(); |
67 | 68 | } |
68 | 69 | |
69 | 70 | $content = file_get_contents($this->getAbsolutePath()); |
70 | 71 | |
71 | - if ($content === false) { |
|
72 | + if ($content === false) |
|
73 | + { |
|
72 | 74 | $error = error_get_last(); |
73 | 75 | |
74 | 76 | throw new RuntimeException($error['message']); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | /** |
123 | 123 | * Get the current File object. |
124 | 124 | */ |
125 | - public function current(): File|Folder |
|
125 | + public function current(): File | Folder |
|
126 | 126 | { |
127 | 127 | /** @var SplFileInfo $current */ |
128 | 128 | $current = parent::current(); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | /** |
139 | 139 | * {@inheritdoc} |
140 | 140 | */ |
141 | - public function getChildren(): FileExplorer|RecursiveFilterIterator|null |
|
141 | + public function getChildren(): FileExplorer | RecursiveFilterIterator | null |
|
142 | 142 | { |
143 | 143 | $explorer = new self( |
144 | 144 | $this->getInnerIterator()->getChildren(), |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * |
199 | 199 | * @deprecated use `FileExplorer::createFromDefinition()` instead |
200 | 200 | */ |
201 | - public static function create(string|Folder $folder, array $includes = [], array $excludes = [], ?int $flags = null): FileExplorer |
|
201 | + public static function create(string | Folder $folder, array $includes = [], array $excludes = [], ?int $flags = null): FileExplorer |
|
202 | 202 | { |
203 | 203 | $folder = fs::realpath($folder); |
204 | 204 | $iterator = new RecursiveDirectoryIterator((string)$folder, RecursiveDirectoryIterator::SKIP_DOTS); |
@@ -103,12 +103,15 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function accept(): bool |
105 | 105 | { |
106 | - if (!empty($this->matchers)) { |
|
107 | - foreach ($this->matchers as $matcher) { |
|
106 | + if (!empty($this->matchers)) |
|
107 | + { |
|
108 | + foreach ($this->matchers as $matcher) |
|
109 | + { |
|
108 | 110 | $result = call_user_func($matcher, $this->current()); |
109 | 111 | |
110 | 112 | // If any custom matchers return false, let's exit immediately |
111 | - if ($result === false) { |
|
113 | + if ($result === false) |
|
114 | + { |
|
112 | 115 | return false; |
113 | 116 | } |
114 | 117 | } |
@@ -128,7 +131,8 @@ discard block |
||
128 | 131 | $current = parent::current(); |
129 | 132 | $path = new FilesystemPath($current->getPathname()); |
130 | 133 | |
131 | - if ($current->isDir()) { |
|
134 | + if ($current->isDir()) |
|
135 | + { |
|
132 | 136 | return new Folder($path); |
133 | 137 | } |
134 | 138 | |
@@ -147,7 +151,8 @@ discard block |
||
147 | 151 | $this->flags |
148 | 152 | ); |
149 | 153 | |
150 | - foreach ($this->matchers as $matcher) { |
|
154 | + foreach ($this->matchers as $matcher) |
|
155 | + { |
|
151 | 156 | $explorer->addMatcher($matcher); |
152 | 157 | } |
153 | 158 | |
@@ -167,18 +172,22 @@ discard block |
||
167 | 172 | */ |
168 | 173 | public function matchesPattern(string $filePath): bool |
169 | 174 | { |
170 | - if (self::strpos_array($filePath, $this->includes)) { |
|
175 | + if (self::strpos_array($filePath, $this->includes)) |
|
176 | + { |
|
171 | 177 | return true; |
172 | 178 | } |
173 | - if (($this->flags & self::INCLUDE_ONLY_FILES) && !$this->current()->isDir()) { |
|
179 | + if (($this->flags & self::INCLUDE_ONLY_FILES) && !$this->current()->isDir()) |
|
180 | + { |
|
174 | 181 | return false; |
175 | 182 | } |
176 | - if (($this->flags & self::IGNORE_DIRECTORIES) && $this->current()->isDir()) { |
|
183 | + if (($this->flags & self::IGNORE_DIRECTORIES) && $this->current()->isDir()) |
|
184 | + { |
|
177 | 185 | return false; |
178 | 186 | } |
179 | 187 | |
180 | 188 | if (!($this->flags & self::ALLOW_DOT_FILES) |
181 | - && preg_match('#(^|\\\\|\/)\..+(\\\\|\/|$)#', $filePath) === 1) { |
|
189 | + && preg_match('#(^|\\\\|\/)\..+(\\\\|\/|$)#', $filePath) === 1) |
|
190 | + { |
|
182 | 191 | return false; |
183 | 192 | } |
184 | 193 | |
@@ -218,12 +227,16 @@ discard block |
||
218 | 227 | */ |
219 | 228 | private static function strpos_array(string $haystack, array $needle): bool |
220 | 229 | { |
221 | - foreach ($needle as $query) { |
|
222 | - if ($query[0] === '/' && $query[strlen($query) - 1] === '/' && preg_match($query, $haystack) === 1) { |
|
230 | + foreach ($needle as $query) |
|
231 | + { |
|
232 | + if ($query[0] === '/' && $query[strlen($query) - 1] === '/' && preg_match($query, $haystack) === 1) |
|
233 | + { |
|
223 | 234 | return true; |
224 | 235 | } |
225 | 236 | |
226 | - if (str_contains($haystack, $query)) { // stop on first true result |
|
237 | + if (str_contains($haystack, $query)) |
|
238 | + { |
|
239 | +// stop on first true result |
|
227 | 240 | return true; |
228 | 241 | } |
229 | 242 | } |
@@ -39,7 +39,8 @@ discard block |
||
39 | 39 | $this->isWindows = $dirSep === '\\'; |
40 | 40 | $this->isVFS = fs::isVFS($filePath); |
41 | 41 | |
42 | - if ($this->isWindows) { |
|
42 | + if ($this->isWindows) |
|
43 | + { |
|
43 | 44 | $filePath = $this->unixifyPath($filePath); |
44 | 45 | } |
45 | 46 | |
@@ -58,7 +59,8 @@ discard block |
||
58 | 59 | */ |
59 | 60 | public function appendToPath($append): self |
60 | 61 | { |
61 | - if ($this->isFile(false)) { |
|
62 | + if ($this->isFile(false)) |
|
63 | + { |
|
62 | 64 | throw new InvalidArgumentException("Appending to a file's path is not possible"); |
63 | 65 | } |
64 | 66 | |
@@ -86,7 +88,8 @@ discard block |
||
86 | 88 | */ |
87 | 89 | public function getAbsolutePath(): string |
88 | 90 | { |
89 | - if (!$this->isVFS && $this->isWindows) { |
|
91 | + if (!$this->isVFS && $this->isWindows) |
|
92 | + { |
|
90 | 93 | return str_replace('/', '\\', $this->absolutePath); |
91 | 94 | } |
92 | 95 | |
@@ -112,7 +115,8 @@ discard block |
||
112 | 115 | { |
113 | 116 | $absPath = $this->absolutePath; |
114 | 117 | |
115 | - if ($checkExistence) { |
|
118 | + if ($checkExistence) |
|
119 | + { |
|
116 | 120 | return file_exists($absPath) && is_dir($absPath); |
117 | 121 | } |
118 | 122 | |
@@ -130,7 +134,8 @@ discard block |
||
130 | 134 | { |
131 | 135 | $absPath = $this->absolutePath; |
132 | 136 | |
133 | - if ($checkExistence) { |
|
137 | + if ($checkExistence) |
|
138 | + { |
|
134 | 139 | return file_exists($absPath) && is_file($absPath); |
135 | 140 | } |
136 | 141 | |
@@ -147,8 +152,10 @@ discard block |
||
147 | 152 | { |
148 | 153 | $paths = []; |
149 | 154 | |
150 | - foreach (func_get_args() as $arg) { |
|
151 | - if ($arg !== '') { |
|
155 | + foreach (func_get_args() as $arg) |
|
156 | + { |
|
157 | + if ($arg !== '') |
|
158 | + { |
|
152 | 159 | $paths[] = $arg; |
153 | 160 | } |
154 | 161 | } |
@@ -25,7 +25,8 @@ |
||
25 | 25 | |
26 | 26 | public static function __callStatic($name, $arguments) |
27 | 27 | { |
28 | - if (self::$fs === null) { |
|
28 | + if (self::$fs === null) |
|
29 | + { |
|
29 | 30 | self::$fs = new Filesystem(); |
30 | 31 | } |
31 | 32 |
@@ -20,9 +20,11 @@ |
||
20 | 20 | */ |
21 | 21 | public static function modifiedAfter(DateTime $time): Closure |
22 | 22 | { |
23 | - return function ($file) use ($time) { |
|
23 | + return function ($file) use ($time) |
|
24 | + { |
|
24 | 25 | /** @var File|Folder $file */ |
25 | - if ($file instanceof Folder) { |
|
26 | + if ($file instanceof Folder) |
|
27 | + { |
|
26 | 28 | return true; |
27 | 29 | } |
28 | 30 |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * |
25 | 25 | * @throws FileNotFoundException |
26 | 26 | */ |
27 | - public function __construct(protected string|FilesystemPath $rawPath) |
|
27 | + public function __construct(protected string | FilesystemPath $rawPath) |
|
28 | 28 | { |
29 | 29 | $realPath = fs::realpath($rawPath); |
30 | 30 |
@@ -28,7 +28,8 @@ discard block |
||
28 | 28 | { |
29 | 29 | $realPath = fs::realpath($rawPath); |
30 | 30 | |
31 | - if ($realPath === false) { |
|
31 | + if ($realPath === false) |
|
32 | + { |
|
32 | 33 | throw $this->buildNotFoundException(); |
33 | 34 | } |
34 | 35 | |
@@ -112,11 +113,13 @@ discard block |
||
112 | 113 | */ |
113 | 114 | protected function isSafeToRead(): void |
114 | 115 | { |
115 | - if (fs::isVFS($this->getAbsolutePath())) { |
|
116 | + if (fs::isVFS($this->getAbsolutePath())) |
|
117 | + { |
|
116 | 118 | return; |
117 | 119 | } |
118 | 120 | |
119 | - if (!str_starts_with($this->getAbsolutePath(), (string)Service::getWorkingDirectory())) { |
|
121 | + if (!str_starts_with($this->getAbsolutePath(), (string)Service::getWorkingDirectory())) |
|
122 | + { |
|
120 | 123 | throw $this->buildNotFoundException(); |
121 | 124 | } |
122 | 125 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @return false|T |
225 | 225 | */ |
226 | - public function realpath(string|BaseFilesystemItem $path): false|string|BaseFilesystemItem |
|
226 | + public function realpath(string | BaseFilesystemItem $path): false | string | BaseFilesystemItem |
|
227 | 227 | { |
228 | 228 | return $this->isVFS($path) ? $path : realpath((string)$path); |
229 | 229 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | /** |
232 | 232 | * Check whether a given path is on the virtual filesystem. |
233 | 233 | */ |
234 | - public function isVFS(string|BaseFilesystemItem $path): bool |
|
234 | + public function isVFS(string | BaseFilesystemItem $path): bool |
|
235 | 235 | { |
236 | 236 | return str_starts_with((string)$path, 'vfs://'); |
237 | 237 | } |
@@ -25,11 +25,13 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function absolutePath($pathFragments): string |
27 | 27 | { |
28 | - if ($pathFragments instanceof FilesystemPath) { |
|
28 | + if ($pathFragments instanceof FilesystemPath) |
|
29 | + { |
|
29 | 30 | $pathFragments = (string)$pathFragments; |
30 | 31 | } |
31 | 32 | |
32 | - if ($this->isAbsolutePath($pathFragments)) { |
|
33 | + if ($this->isAbsolutePath($pathFragments)) |
|
34 | + { |
|
33 | 35 | return $pathFragments; |
34 | 36 | } |
35 | 37 | |
@@ -61,16 +63,20 @@ discard block |
||
61 | 63 | */ |
62 | 64 | public function copy($originFile, $targetFile, $overwriteNewerFiles = false): void |
63 | 65 | { |
64 | - if ($this->isDir($originFile)) { |
|
65 | - if (!$this->isDir($targetFile)) { |
|
66 | + if ($this->isDir($originFile)) |
|
67 | + { |
|
68 | + if (!$this->isDir($targetFile)) |
|
69 | + { |
|
66 | 70 | mkdir($targetFile, 0755, true); |
67 | 71 | } |
68 | 72 | |
69 | 73 | $dir = dir($originFile); |
70 | 74 | |
71 | - while (false !== $entry = $dir->read()) { |
|
75 | + while (false !== $entry = $dir->read()) |
|
76 | + { |
|
72 | 77 | // Skip pointers |
73 | - if ($entry == '.' || $entry == '..') { |
|
78 | + if ($entry == '.' || $entry == '..') |
|
79 | + { |
|
74 | 80 | continue; |
75 | 81 | } |
76 | 82 | |
@@ -78,7 +84,9 @@ discard block |
||
78 | 84 | } |
79 | 85 | |
80 | 86 | $dir->close(); |
81 | - } else { |
|
87 | + } |
|
88 | + else |
|
89 | + { |
|
82 | 90 | parent::copy($originFile, $targetFile, $overwriteNewerFiles); |
83 | 91 | } |
84 | 92 | } |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
165 | - protected function addFileToTracker(File &$file): void |
|
165 | + protected function addFileToTracker(File & $file): void |
|
166 | 166 | { |
167 | 167 | $this->trackedItemsFlattened[$file->getRelativeFilePath()] = &$file; |
168 | 168 | } |
169 | 169 | |
170 | - protected function delFileFromTracker(File &$file): void |
|
170 | + protected function delFileFromTracker(File & $file): void |
|
171 | 171 | { |
172 | 172 | unset($this->trackedItemsFlattened[$file->getRelativeFilePath()]); |
173 | 173 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @param null|string $namespace |
179 | 179 | */ |
180 | - protected function addObjectToTracker(ReadableDocument &$trackedItem, $namespace = null): void |
|
180 | + protected function addObjectToTracker(ReadableDocument & $trackedItem, $namespace = null): void |
|
181 | 181 | { |
182 | 182 | if ($namespace == null) { |
183 | 183 | $this->trackedItems[$trackedItem->getIndexName()] = &$trackedItem; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @param null|string $namespace |
195 | 195 | */ |
196 | - protected function delObjectFromTracker(ReadableDocument &$trackedItem, $namespace = null): void |
|
196 | + protected function delObjectFromTracker(ReadableDocument & $trackedItem, $namespace = null): void |
|
197 | 197 | { |
198 | 198 | if ($namespace == null) { |
199 | 199 | unset($this->trackedItems[$trackedItem->getIndexName()]); |
@@ -96,7 +96,8 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function getTracked($filePath): mixed |
98 | 98 | { |
99 | - if ($this->isTracked($filePath)) { |
|
99 | + if ($this->isTracked($filePath)) |
|
100 | + { |
|
100 | 101 | return $this->trackedItemsFlattened[(string)$filePath]; |
101 | 102 | } |
102 | 103 | |
@@ -125,8 +126,10 @@ discard block |
||
125 | 126 | */ |
126 | 127 | public function shouldBeTracked($filePath): bool |
127 | 128 | { |
128 | - foreach ($this->folderDefinitions as $folder) { |
|
129 | - if (str_starts_with($filePath, $folder)) { |
|
129 | + foreach ($this->folderDefinitions as $folder) |
|
130 | + { |
|
131 | + if (str_starts_with($filePath, $folder)) |
|
132 | + { |
|
130 | 133 | return true; |
131 | 134 | } |
132 | 135 | } |
@@ -157,7 +160,8 @@ discard block |
||
157 | 160 | */ |
158 | 161 | protected function declareTrackingNamespace($namespace): void |
159 | 162 | { |
160 | - if (!isset($this->trackedItems[$namespace])) { |
|
163 | + if (!isset($this->trackedItems[$namespace])) |
|
164 | + { |
|
161 | 165 | $this->trackedItems[$namespace] = []; |
162 | 166 | } |
163 | 167 | } |
@@ -179,9 +183,12 @@ discard block |
||
179 | 183 | */ |
180 | 184 | protected function addObjectToTracker(ReadableDocument &$trackedItem, $namespace = null): void |
181 | 185 | { |
182 | - if ($namespace == null) { |
|
186 | + if ($namespace == null) |
|
187 | + { |
|
183 | 188 | $this->trackedItems[$trackedItem->getIndexName()] = &$trackedItem; |
184 | - } else { |
|
189 | + } |
|
190 | + else |
|
191 | + { |
|
185 | 192 | $this->trackedItems[$namespace][$trackedItem->getIndexName()] = &$trackedItem; |
186 | 193 | } |
187 | 194 | |
@@ -195,9 +202,12 @@ discard block |
||
195 | 202 | */ |
196 | 203 | protected function delObjectFromTracker(ReadableDocument &$trackedItem, $namespace = null): void |
197 | 204 | { |
198 | - if ($namespace == null) { |
|
205 | + if ($namespace == null) |
|
206 | + { |
|
199 | 207 | unset($this->trackedItems[$trackedItem->getIndexName()]); |
200 | - } else { |
|
208 | + } |
|
209 | + else |
|
210 | + { |
|
201 | 211 | unset($this->trackedItems[$namespace][$trackedItem->getIndexName()]); |
202 | 212 | } |
203 | 213 | |
@@ -255,14 +265,16 @@ discard block |
||
255 | 265 | { |
256 | 266 | $this->watchedFolders[$def->folder->getAbsolutePath()] = $def; |
257 | 267 | |
258 | - if (empty($def->excludes)) { |
|
268 | + if (empty($def->excludes)) |
|
269 | + { |
|
259 | 270 | $def->excludes = self::$documentIgnoreList; |
260 | 271 | } |
261 | 272 | |
262 | 273 | $fileExplorer = FileExplorer::createFromDefinition($def); |
263 | 274 | $fileIterator = $fileExplorer->getFileIterator(); |
264 | 275 | |
265 | - foreach ($fileIterator as $file) { |
|
276 | + foreach ($fileIterator as $file) |
|
277 | + { |
|
266 | 278 | $this->handleTrackableItem($file, $options); |
267 | 279 | } |
268 | 280 | } |
@@ -298,18 +310,24 @@ discard block |
||
298 | 310 | $jailItems = []; |
299 | 311 | |
300 | 312 | /** @var CollectableItem|ReadableDocument $item */ |
301 | - foreach ($elements as &$item) { |
|
302 | - if ($item instanceof TemplateReadyDocument) { |
|
303 | - if (!Service::hasRunTimeFlag(RuntimeStatus::USING_DRAFTS) && $item->isDraft()) { |
|
313 | + foreach ($elements as &$item) |
|
314 | + { |
|
315 | + if ($item instanceof TemplateReadyDocument) |
|
316 | + { |
|
317 | + if (!Service::hasRunTimeFlag(RuntimeStatus::USING_DRAFTS) && $item->isDraft()) |
|
318 | + { |
|
304 | 319 | continue; |
305 | 320 | } |
306 | 321 | } |
307 | 322 | |
308 | 323 | $keyName = ($name === null) ? $item->getRelativeFilePath() : $name($item); |
309 | 324 | |
310 | - if (empty($item->getNamespace())) { |
|
325 | + if (empty($item->getNamespace())) |
|
326 | + { |
|
311 | 327 | $jailItems[$keyName] = $item->createJail(); |
312 | - } else { |
|
328 | + } |
|
329 | + else |
|
330 | + { |
|
313 | 331 | $jailItems[$item->getNamespace()][$keyName] = $item->createJail(); |
314 | 332 | } |
315 | 333 | } |
@@ -38,7 +38,8 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function compileManager(): void |
40 | 40 | { |
41 | - if (!$this->configuration->hasDataItems()) { |
|
41 | + if (!$this->configuration->hasDataItems()) |
|
42 | + { |
|
42 | 43 | $this->logger->notice('No DataItems or Datasets detected... Ignoring.'); |
43 | 44 | |
44 | 45 | return; |
@@ -73,11 +74,13 @@ discard block |
||
73 | 74 | */ |
74 | 75 | public function parseDataItems($folders): void |
75 | 76 | { |
76 | - if ($folders === null) { |
|
77 | + if ($folders === null) |
|
78 | + { |
|
77 | 79 | return; |
78 | 80 | } |
79 | 81 | |
80 | - foreach ($folders as $folder) { |
|
82 | + foreach ($folders as $folder) |
|
83 | + { |
|
81 | 84 | $cls = new Folder($folder); |
82 | 85 | |
83 | 86 | $this->logger->debug('Scanning "{folder}" for data items...', [ |
@@ -101,7 +104,8 @@ discard block |
||
101 | 104 | */ |
102 | 105 | public function parseDataSets($dataSets): void |
103 | 106 | { |
104 | - if ($dataSets === null) { |
|
107 | + if ($dataSets === null) |
|
108 | + { |
|
105 | 109 | return; |
106 | 110 | } |
107 | 111 | |
@@ -113,7 +117,8 @@ discard block |
||
113 | 117 | * 'folder' => '(string) The folder where this collection has its ContentItems' |
114 | 118 | * ] |
115 | 119 | */ |
116 | - foreach ($dataSets as $dataSet) { |
|
120 | + foreach ($dataSets as $dataSet) |
|
121 | + { |
|
117 | 122 | $folder = new Folder($dataSet['folder']); |
118 | 123 | |
119 | 124 | $this->logger->debug('Scanning "{folder}" for the "{name}" dataset...', [ |
@@ -137,7 +142,8 @@ discard block |
||
137 | 142 | */ |
138 | 143 | protected function handleTrackableItem(File $filePath, array $options = []): mixed |
139 | 144 | { |
140 | - try { |
|
145 | + try |
|
146 | + { |
|
141 | 147 | $namespace = $options['namespace'] ?? null; |
142 | 148 | |
143 | 149 | $dataItem = new DataItem($filePath); |
@@ -151,12 +157,17 @@ discard block |
||
151 | 157 | $this->saveTrackerOptions($dataItem->getRelativeFilePath(), $options); |
152 | 158 | |
153 | 159 | return $dataItem->getRelativeFilePath(); |
154 | - } catch (DependencyMissingException $e) { |
|
155 | - if ($e->getDependency() === 'XML') { |
|
160 | + } |
|
161 | + catch (DependencyMissingException $e) |
|
162 | + { |
|
163 | + if ($e->getDependency() === 'XML') |
|
164 | + { |
|
156 | 165 | $this->logger->critical('XML support is not available in your PHP installation. For XML support, please install the appropriate package for your system:'); |
157 | 166 | $this->logger->critical(' e.g. php7.0-xml'); |
158 | 167 | } |
159 | - } catch (UnsupportedDataTypeException $e) { |
|
168 | + } |
|
169 | + catch (UnsupportedDataTypeException $e) |
|
170 | + { |
|
160 | 171 | $this->logger->warning('There is no function to handle {ext} file format.', [ |
161 | 172 | 'ext' => $e->getDataType(), |
162 | 173 | ]); |