summaryrefslogtreecommitdiff
path: root/src/Utilities.php
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2022-03-06 00:48:14 +0100
committerDaniel Weipert <code@drogueronin.de>2022-03-06 00:48:14 +0100
commitb2a86c7df7d5a473e80034832a01b21444fa50e6 (patch)
tree2b18e08124ff3e8602a20ba27fef3ae4d066cc28 /src/Utilities.php
parentdf428380e288db75b41ace5d6274f44916517f9f (diff)
Refactor
Diffstat (limited to 'src/Utilities.php')
-rw-r--r--src/Utilities.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Utilities.php b/src/Utilities.php
new file mode 100644
index 0000000..0462ad6
--- /dev/null
+++ b/src/Utilities.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace FlatFileForms;
+
+class Utilities
+{
+ public function isPagedFieldSet(array $fields): bool
+ {
+ $firstItem = reset($fields);
+
+ return ! (isset($firstItem['name']) && ! is_array($firstItem['name']));
+ }
+
+ public function scandir(string $path): array
+ {
+ $path = rtrim($path, '/');
+
+ return array_values(
+ array_map(
+ fn ($item) => $path . '/' . $item,
+ array_filter(
+ scandir($path), fn ($item) => ! in_array($item, ['.', '..'])
+ )
+ )
+ );
+ }
+
+ public function scandirMultiple(string|array $paths): array
+ {
+ $paths = (array)$paths;
+
+ $merged = [];
+ foreach ($paths as $path) {
+ $scanned = $this->scandir($path);
+ array_push($merged, ...$scanned);
+ }
+
+ return $merged;
+ }
+}