ILIAS  release_7 Revision v7.30-3-g800a261c036
StorageHandlerFactory.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
4
6
12{
13 public const BASE_DIRECTORY = "storage";
17 protected $handlers = [];
21 protected $primary;
22
27 public function __construct(array $handlers)
28 {
29 foreach ($handlers as $handler) {
30 $this->handlers[$handler->getID()] = $handler;
31 if ($handler->isPrimary()) {
32 if ($this->primary !== null) {
33 throw new \LogicException("Only one primary StorageHandler can exist");
34 }
35 $this->primary = $handler;
36 }
37 }
38 if ($this->primary === null) {
39 throw new \LogicException("One primary StorageHandler must exist");
40 }
41 }
42
48 {
49 return $this->getHandlerForStorageId($resource->getStorageID());
50 }
51
52 public function getHandlerForStorageId(string $storage_id) : StorageHandler
53 {
54 if (isset($this->handlers[$storage_id])) {
55 return $this->handlers[$storage_id];
56 }
57
58 throw new \LogicException("no other StorageHandler possible at the moment");
59 }
60
61 public function getPrimary() : StorageHandler
62 {
63 return $this->primary;
64 }
65}
An exception for terminatinating execution or to throw for unit testing.
__construct(array $handlers)
StorageHandlerFactory constructor.