ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
StorageHandlerFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
33 {
34  public const BASE_DIRECTORY = "storage";
38  protected array $handlers = [];
40  private string $base_dir;
41 
46  public function __construct(array $handlers, string $base_dir)
47  {
48  $this->base_dir = $base_dir;
49  foreach ($handlers as $handler) {
50  $this->handlers[$handler->getID()] = $handler;
51  if ($handler->isPrimary()) {
52  if ($this->primary !== null) {
53  throw new \LogicException("Only one primary StorageHandler can exist");
54  }
55  $this->primary = $handler;
56  }
57  }
58  if ($this->primary === null) {
59  throw new \LogicException("One primary StorageHandler must exist");
60  }
61  }
62 
63  public function getBaseDir(): string
64  {
65  return $this->base_dir;
66  }
67 
69  {
70  return $this->getHandlerForStorageId($resource->getStorageID());
71  }
72 
73  public function getHandlerForRevision(Revision $revision): StorageHandler
74  {
75  return $this->getHandlerForStorageId($revision->getStorageID());
76  }
77 
78  public function getHandlerForStorageId(string $storage_id): StorageHandler
79  {
80  if (isset($this->handlers[$storage_id])) {
81  return $this->handlers[$storage_id];
82  }
83 
84  throw new \LogicException("no StorageHandler for '$storage_id' available");
85  }
86 
88  {
89  return $this->primary;
90  }
91 
92  public function getRidForURI(string $uri): ?ResourceIdentification
93  {
94  $internal_path = str_replace($this->getBaseDir(), "", $uri);
95  $internal_path = ltrim(str_replace(self::BASE_DIRECTORY, "", $internal_path), "/");
96 
97  $fs_identifier = explode("/", $internal_path)[0];
98 
99  $internal_path = str_replace($fs_identifier . "/", "", $internal_path);
100 
101  $handler = $this->getHandlerForStorageId($fs_identifier);
102  $path_generator = $handler->getPathGenerator();
103  try {
104  $rid = $path_generator->getIdentificationFor($internal_path);
105  } catch (\Throwable) {
106  return null;
107  }
108  return $rid;
109  }
110 }
Interface Observer Contains several chained tasks and infos about them.
ILIAS ResourceStorage StorageHandler StorageHandler $primary
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(array $handlers, string $base_dir)
StorageHandlerFactory constructor.
$handler
Definition: oai.php:14