/
SerjPopov
/
cloud-mail-ru-php
Обзор
Документация
Войти
/
SerjPopov
/
cloud-mail-ru-php
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/FolderHelper.php
53 строки
1 KB
biodata
Исправлено получение токена. Обновлена библиотека Guzzle. Обновлен docker контейнер. Протестировано на PHP 8.2.
03 фев 2024, 20:16
03 фев 2024, 20:16
605acc0
Код
Авторство
О чём код?
<?php namespace SergPopov\CloudMailRu; class FolderHelper { /** * @param string $str * @return array an array describing the contents of the directory * [ * 'folders' => [ * 'folder1', * 'folder2', * ], * 'files' => [ * 'file1.txt', * 'file2.jpg', * ], * ]; * @throws CloudMailRuException */ public static function parseFolderList(string $str): array { $list = json_decode($str)->body->list; if (!is_array($list)) { throw new CloudMailRuException('Error parsing data of folder list'); } $folders = []; $files = []; foreach ($list as $item) { if ($item->type == null || $item->name == null) { throw new CloudMailRuException('Error parsing data of folder list - unknown data'); } switch ($item->type) { case 'folder' : $folders[] = $item->name; break; case 'file' : $files[] = $item->name; break; } } return [ 'folders' => $folders, 'files' => $files, ]; } }