# wpide/3.1/App/Services/Storage/DirectoryCollection.php

WPIDE – File Manager &amp; Code Editor, version 3.1. 62 lines.

- Page: https://pluginprobe.com/plugins/wpide/3.1/code/App/Services/Storage/DirectoryCollection.php
- Raw: https://pluginprobe.com/plugins/wpide/3.1/raw/App/Services/Storage/DirectoryCollection.php
- Modified: 2022-07-30T20:33:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wpide/3.1/code/App/Services/Storage/DirectoryCollection.php#L10-L20`.

```php
<?php

namespace WPIDE\App\Services\Storage;

use WPIDE\App\Utils\Collection;

class DirectoryCollection implements \JsonSerializable
{
    use Collection;

    protected $location;

    public function __construct($location)
    {
        $this->location = $location;
    }

    public function addFile(string $type, array $dir_info, string $path, string $dir, string $mime, string $name, int $size, int $timestamp)
    {
        if (! in_array($type, ['dir', 'file', 'back'])) {
            throw new \Exception('Invalid file type.');
        }

        $ext = pathinfo($path, PATHINFO_EXTENSION);

        $entry = [
            'id' => md5($path),
            'type' => $type,
            'path' => $path,
            'dir' => $dir,
            'ext' => $ext,
            'mime' => $mime,
            'name' => $name,
            'size' => $size,
            'time' => $timestamp,
        ];

        if($type === 'dir') {
            $entry = array_merge($entry, $dir_info);
        }

        $this->add($entry);
    }

    public function resetTimestamps($timestamp = 0)
    {
        foreach ($this->items as &$item) {
            $item['time'] = $timestamp;
        }
    }

    public function jsonSerialize(): array
    {
        $this->sortByValue('type');

        return [
            'location' => $this->location,
            'files' => $this->items,
        ];
    }
}

```
