ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
StorageHandlerFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
32{
33 public const BASE_DIRECTORY = "storage";
37 protected array $handlers = [];
38 protected ?StorageHandler $primary = null;
39
44 public function __construct(array $handlers, private string $base_dir)
45 {
46 foreach ($handlers as $handler) {
47 $this->handlers[$handler->getID()] = $handler;
48 if ($handler->isPrimary()) {
49 if ($this->primary !== null) {
50 throw new \LogicException("Only one primary StorageHandler can exist");
51 }
52 $this->primary = $handler;
53 }
54 }
55 if ($this->primary === null) {
56 throw new \LogicException("One primary StorageHandler must exist");
57 }
58 }
59
60 public function getBaseDir(): string
61 {
62 return $this->base_dir;
63 }
64
66 {
67 return $this->getHandlerForStorageId($resource->getStorageID());
68 }
69
70 public function getHandlerForRevision(Revision $revision): StorageHandler
71 {
72 return $this->getHandlerForStorageId($revision->getStorageID());
73 }
74
75 public function getHandlerForStorageId(string $storage_id): StorageHandler
76 {
77 if (isset($this->handlers[$storage_id])) {
78 return $this->handlers[$storage_id];
79 }
80
81 throw new \LogicException("no StorageHandler for '$storage_id' available");
82 }
83
84 public function getPrimary(): ?StorageHandler
85 {
86 return $this->primary;
87 }
88
89 public function getRidForURI(string $uri): ?ResourceIdentification
90 {
91 $internal_path = str_replace($this->getBaseDir(), "", $uri);
92 $internal_path = ltrim(str_replace(self::BASE_DIRECTORY, "", $internal_path), "/");
93
94 $fs_identifier = explode("/", $internal_path)[0];
95
96 $internal_path = str_replace($fs_identifier . "/", "", $internal_path);
97
98 $handler = $this->getHandlerForStorageId($fs_identifier);
99 $path_generator = $handler->getPathGenerator();
100 try {
101 $rid = $path_generator->getIdentificationFor($internal_path);
102 } catch (\Throwable) {
103 return null;
104 }
105 return $rid;
106 }
107}
__construct(array $handlers, private string $base_dir)
StorageHandlerFactory constructor.
$handler
Definition: oai.php:29