ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
StorageHandlerFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
32 {
33  public const BASE_DIRECTORY = "storage";
37  protected array $handlers = [];
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 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$handler
Definition: oai.php:30
__construct(array $handlers, private string $base_dir)
StorageHandlerFactory constructor.