PluginProbe
WPIDE – File Manager & Code Editor / trunk
WPIDE – File Manager & Code Editor vtrunk
3.5.8 3.5.7 2.0.14 2.0.15 2.0.16 2.0.2 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1 2.2 2.3 2.3.1 2.3.2 2.4.0 2.5 2.6 3.0 3.1 3.2 3.3 3.4 All 54 releases
wpide / App / Services / Storage / DirectoryCollection.php

DirectoryCollection.php in WPIDE – File Manager & Code Editor trunk, at App/Services/Storage/DirectoryCollection.php

62 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPIDE\App\Services\Storage;
4
5 use WPIDE\App\Utils\Collection;
6
7 class DirectoryCollection implements \JsonSerializable
8 {
9 use Collection;
10
11 protected $location;
12
13 public function __construct($location)
14 {
15 $this->location = $location;
16 }
17
18 public function addFile(string $type, array $dir_info, string $path, string $dir, string $mime, string $name, int $size, int $timestamp)
19 {
20 if (! in_array($type, ['dir', 'file', 'back'])) {
21 throw new \Exception('Invalid file type.');
22 }
23
24 $ext = pathinfo($path, PATHINFO_EXTENSION);
25
26 $entry = [
27 'id' => md5($path),
28 'type' => $type,
29 'path' => $path,
30 'dir' => $dir,
31 'ext' => $ext,
32 'mime' => $mime,
33 'name' => $name,
34 'size' => $size,
35 'time' => $timestamp,
36 ];
37
38 if($type === 'dir') {
39 $entry = array_merge($entry, $dir_info);
40 }
41
42 $this->add($entry);
43 }
44
45 public function resetTimestamps($timestamp = 0)
46 {
47 foreach ($this->items as &$item) {
48 $item['time'] = $timestamp;
49 }
50 }
51
52 public function jsonSerialize(): array
53 {
54 $this->sortByValue('name');
55
56 return [
57 'location' => $this->location,
58 'files' => $this->items,
59 ];
60 }
61 }
62