Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
UploaderController.php
1<?php
2
4
5abstract class UploaderController
6{
7 protected array $options = [];
8
9 private string $moduleId;
10 private string $name;
11 private ?string $filePath = null;
12
13 protected function __construct(array $options)
14 {
15 // You have to validate $options in a derived class constructor
16 $this->options = $options;
17
18 $this->moduleId = getModuleId($this->getFilePath());
19 $this->name = ControllerResolver::getNameByController($this);
20 }
21
22 abstract public function isAvailable(): bool;
23
24 abstract public function getConfiguration(): Configuration;
25
31 abstract public function canUpload();
32
33 abstract public function canView(): bool;
34
35 abstract public function verifyFileOwner(FileOwnershipCollection $files): void;
36
37 abstract public function canRemove(): bool;
38
39 // Events
40 public function onUploadStart(UploadResult $uploadResult): void {}
41 public function onUploadComplete(UploadResult $uploadResult): void {}
42 public function onUploadError(UploadResult $uploadResult): void {}
43
45 {
46 // Default commit options
47 return new CommitOptions([
48 'moduleId' => $this->getModuleId(),
49 'savePath' => $this->getModuleId(),
50 ]);
51 }
52
53 final public function getOptions(): array
54 {
55 return $this->options;
56 }
57
58 final public function getOption(string $option, $defaultValue = null)
59 {
60 return array_key_exists($option, $this->options) ? $this->options[$option] : $defaultValue;
61 }
62
63 final public function getName(): string
64 {
65 return $this->name;
66 }
67
68 final public function getModuleId(): string
69 {
70 return $this->moduleId;
71 }
72
73 final protected function getFilePath(): string
74 {
75 if (!$this->filePath)
76 {
77 $reflector = new \ReflectionClass($this);
78 $this->filePath = preg_replace('#[\\\/]+#', '/', $reflector->getFileName());
79 }
80
81 return $this->filePath;
82 }
83}
static getNameByController(UploaderController $controller)
getOption(string $option, $defaultValue=null)
verifyFileOwner(FileOwnershipCollection $files)