-
Notifications
You must be signed in to change notification settings - Fork 0
/
5-server-folder-structure.php
59 lines (46 loc) · 1.54 KB
/
5-server-folder-structure.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
use jalsoedesign\filezilla\enum\ServerProtocol;
use jalsoedesign\filezilla\enum\ServerType;
use jalsoedesign\filezilla\Server;
use jalsoedesign\filezilla\Folder;
use jalsoedesign\filezilla\SiteManager;
// Load composer
require_once(__DIR__ . '/../vendor/autoload.php');
$siteManager = new SiteManager(__DIR__ . '/../tests/fixtures/sitemanager.xml');
$servers = $siteManager->getServers();
$ascii = convertToAscii($siteManager);
echo $ascii;
function convertToAscii(Folder $folder, $prefix = '') {
$folderName = $folder->getName();
if (empty($folderName)) {
$folderName = 'My Sites';
}
$output = $prefix . '📁 ' . $folderName . PHP_EOL;
$children = $folder->getChildren();
$childCount = count($children);
foreach ($children as $index => $child) {
$isLast = ($index === $childCount - 1);
$childPrefix = $prefix . ($isLast ? '└── ' : '├── ');
if ($child instanceof Folder) {
// Recursively handle Folder
$output .= convertToAscii($child, $prefix . ($isLast ? ' ' : '│ '));
} else if ($child instanceof Server) {
$cloudTypes = [
ServerProtocol::AZURE_BLOB,
ServerProtocol::AZURE_FILE,
ServerProtocol::B2,
ServerProtocol::BOX,
ServerProtocol::DROPBOX,
ServerProtocol::GOOGLE_DRIVE,
ServerProtocol::ONEDRIVE,
ServerProtocol::SWIFT,
ServerProtocol::RACKSPACE,
ServerProtocol::S3,
];
$icon = in_array($child->getProtocol(), $cloudTypes) ? '☁️' : '🌐';
// Handle Server
$output .= $childPrefix . $icon . ' ' . $child->getName() . PHP_EOL;
}
}
return $output;
}