Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
entrybuilder.php
1<?php
2
3declare(strict_types=1);
4
6
9
10final class EntryBuilder
11{
12 public function __construct()
13 {
14 }
15
16 public function createEmptyDirectory(string $path): DirectoryEntry
17 {
19 }
20
21 public function createFromFileArray(array $fileArray, string $path = null): FileEntry
22 {
23 $isFromCloud = $this->isFromCloud($fileArray);
24 $path = $this->getPath($fileArray, $path);
25 $size = $this->getSize($fileArray);
26 $fileSrc = $this->getFileSrc($fileArray);
27
28 if ($isFromCloud)
29 {
30 $fileSrc = $this->prepareCloudUrl($fileSrc);
31 $serverRelativeUrl = $this->getCloudUploadPath() . $fileSrc;
32 }
33 else
34 {
35 $serverRelativeUrl = $fileSrc;
36 }
37
38 $serverRelativeUrl = Uri::urnEncode($serverRelativeUrl, 'UTF-8');
39
40 return new FileEntry($path, $serverRelativeUrl, $size);
41 }
42
43 public function createFromFileId($fileId, string $path = null): ?FileEntry
44 {
45 $fileArray = \CFile::getFileArray($fileId);
46 if ($this->isValidFileArray($fileArray) === false)
47 {
48 return null;
49 }
50
51 return $this->createFromFileArray($fileArray, $path);
52 }
53
54 private function isValidFileArray($fileArray): bool
55 {
56 return \is_array($fileArray) && !empty($fileArray['SRC']);
57 }
58
59 private function isFromCloud(array $fileArray): bool
60 {
61 return !empty($fileArray['HANDLER_ID']);
62 }
63
64 private function getPath(array $fileArray, $path): string
65 {
66 return $path ? : $fileArray['ORIGINAL_NAME'];
67 }
68
69 private function getSize(array $fileArray): int
70 {
71 return (int)$fileArray['FILE_SIZE'];
72 }
73
74 private function getFileSrc(array $fileArray): ?string
75 {
76 $fileSrc = $fileArray['SRC'] ?? null;
77
78 return $fileSrc ? : \CFile::getFileSrc($fileArray);
79 }
80
81 private function prepareCloudUrl(string $fileSrc): string
82 {
83 return preg_replace('~^(http[s]?)(\://)~i', '\\1.', $fileSrc);
84 }
85
86 private function getCloudUploadPath(): string
87 {
88 return Option::get('main', 'bx_cloud_upload', '/upload/bx_cloud_upload/');
89 }
90}
static createEmptyDirectory(string $path)
__construct()
createEmptyDirectory(string $path)
createFromFileArray(array $fileArray, string $path=null)
createFromFileId($fileId, string $path=null)
Definition fileentry.php:8