ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
StorageHandlerFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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 
86  {
87  return $this->primary;
88  }
89 }
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.