summaryrefslogtreecommitdiff
path: root/src/Utilities.php
blob: 0462ad6d7fea990a67da9e8b51577e34f6da3d0b (plain)
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
<?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;
  }
}