/**
* Constructor
*
* @param string $key File key
* @param Storage $storage Storage to use
* @param bool $recursive (Optional) By default, Directory will only read the first level if items.
* If set to true, Directory will read all children items and list them as one-dimensional array.
* @param null|string $filter (Optional) Filter to use when reading directory items
*
* @throws \Webiny\Component\Storage\StorageException
*/
public function __construct($key, Storage $storage, $recursive = false, $filter = null)
{
if (!$storage->supportsDirectories()) {
$driver = get_class($storage->getDriver());
throw new StorageException(StorageException::DRIVER_CAN_NOT_WORK_WITH_DIRECTORIES, [$driver]);
}
$this->key = $key;
$this->recursive = $recursive;
$this->storage = $storage;
if ($this->storage->keyExists($key) && !$this->storage->isDirectory($key)) {
throw new StorageException(StorageException::DIRECTORY_OBJECT_CAN_NOT_READ_FILE_PATHS, [$key]);
}
$this->parseFilter($filter);
}