freebox_api_php/freebox/api/v3/services/FileSystem/FileSystemListing.php

54 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace alphayax\freebox\api\v3\services\FileSystem;
use alphayax\freebox\api\v3\models\FileSystem\FileInfo;
use alphayax\freebox\api\v3\Service;
/**
* Class FileSystemListing
* @package alphayax\freebox\api\v3\services\FileSystem
*/
class FileSystemListing extends Service {
const API_FS_LS = '/api/v3/fs/ls/';
const API_FS_INFO = '/api/v3/fs/info/';
/**
* @param string $DirectoryName
* @param bool $onlyFolder Only list folders
* @param bool $countSubFolder Return files and subfolder count for folders
* @param bool $removeHidden Dont return hidden files in directory listing
* @return FileInfo[]
*/
public function getFilesFromDirectory( $DirectoryName = '/Disque dur/', $onlyFolder = true, $countSubFolder = false, $removeHidden = true){
$Directory_b64 = base64_encode( $DirectoryName);
$rest = $this->getAuthService( self::API_FS_LS . $Directory_b64);
$rest->GET([
'onlyFolder' => $onlyFolder,
'countSubFolder' => $countSubFolder,
'removeHidden' => $removeHidden,
]);
$FileInfo_xs = $rest->getCurlResponse()['result'];
$FileInfos = [];
foreach( $FileInfo_xs as $FileInfo_x) {
$FileInfos[] = new FileInfo( $FileInfo_x);
}
return $FileInfos;
}
/**
* Get file information
* @param string $DirectoryName
* @return FileInfo
*/
public function getFileInformation( $DirectoryName){
$Directory_b64 = base64_encode( $DirectoryName);
$rest = $this->getAuthService( self::API_FS_INFO . $Directory_b64);
$rest->GET();
return new FileInfo( $rest->getCurlResponse()['result']);
}
}