ILIAS  release_8 Revision v8.24
StorageHandlerFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
31{
32 public const BASE_DIRECTORY = "storage";
36 protected array $handlers = [];
38 private string $base_dir;
39
44 public function __construct(array $handlers, string $base_dir)
45 {
46 $this->base_dir = $base_dir;
47 foreach ($handlers as $handler) {
48 $this->handlers[$handler->getID()] = $handler;
49 if ($handler->isPrimary()) {
50 if ($this->primary !== null) {
51 throw new \LogicException("Only one primary StorageHandler can exist");
52 }
53 $this->primary = $handler;
54 }
55 }
56 if ($this->primary === null) {
57 throw new \LogicException("One primary StorageHandler must exist");
58 }
59 }
60
61 public function getBaseDir(): string
62 {
63 return $this->base_dir;
64 }
65
67 {
68 return $this->getHandlerForStorageId($resource->getStorageID());
69 }
70
71 public function getHandlerForRevision(Revision $revision): StorageHandler
72 {
73 return $this->getHandlerForStorageId($revision->getStorageID());
74 }
75
76 public function getHandlerForStorageId(string $storage_id): StorageHandler
77 {
78 if (isset($this->handlers[$storage_id])) {
79 return $this->handlers[$storage_id];
80 }
81
82 throw new \LogicException("no StorageHandler for '$storage_id' available");
83 }
84
85 public function getPrimary(): ?\ILIAS\ResourceStorage\StorageHandler\StorageHandler
86 {
87 return $this->primary;
88 }
89}
__construct(array $handlers, string $base_dir)
StorageHandlerFactory constructor.
ILIAS ResourceStorage StorageHandler StorageHandler $primary
Class ChatMainBarProvider \MainMenu\Provider.