ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
Services.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
3 namespace ILIAS\MainMenu\Storage;
4 
5 use Generator;
20 use LogicException;
21 
29 class Services
30 {
31 
40 
41 
45  public function __construct()
46  {
47  $this->resource_builder = new ResourceBuilder(
52  );
53  $this->consumer_factory = new ConsumerFactory(new StorageHandlerFactory());
54  }
55 
56 
67  public function upload(UploadResult $result, ResourceStakeholder $stakeholder, string $title = null) : ResourceIdentification
68  {
69  if ($result->isOK()) {
70  $resource = $this->resource_builder->new($result);
71 
72  $this->resource_builder->store($resource);
73 
74  return $resource->getIdentification();
75  } else {
76  throw new LogicException("Can't handle UploadResult: " . $result->getStatus()->getMessage());
77  }
78  }
79 
80 
81  public function find(string $identification) : ?ResourceIdentification
82  {
83  $resource_identification = new ResourceIdentification($identification);
84 
85  if ($this->resource_builder->has($resource_identification)) {
86  return $resource_identification;
87  }
88 
89  return null;
90  }
91 
92 
93  public function getRevision(ResourceIdentification $identification) : Revision
94  {
95  return $this->resource_builder->get($identification)->getCurrentRevision();
96  }
97 
98 
99  public function remove(ResourceIdentification $identification) : void
100  {
101  $this->resource_builder->remove($this->resource_builder->get($identification));
102  }
103 
104 
108  public function getAll() : Generator
109  {
110  foreach ($this->resource_builder->getAll() as $item) {
114  yield $item->getIdentification();
115  }
116  }
117 
118 
119  //
120  // CONSUMERS
121  //
122 
123  public function download(ResourceIdentification $identification) : DownloadConsumer
124  {
125  return $this->consumer_factory->download($this->resource_builder->get($identification));
126  }
127 
128 
129  public function inline(ResourceIdentification $identification) : InlineConsumer
130  {
131  return $this->consumer_factory->inline($this->resource_builder->get($identification));
132  }
133 
134 
135  public function stream(ResourceIdentification $identification) : FileStreamConsumer
136  {
137  return $this->consumer_factory->fileStream($this->resource_builder->get($identification));
138  }
139 }
$result
__construct()
Services constructor.
Definition: Services.php:45
stream(ResourceIdentification $identification)
Definition: Services.php:135
download(ResourceIdentification $identification)
Definition: Services.php:123
find(string $identification)
Definition: Services.php:81
getRevision(ResourceIdentification $identification)
Definition: Services.php:93
upload(UploadResult $result, ResourceStakeholder $stakeholder, string $title=null)
this is the fast-lane: in most cases you want to store a uploaded file in the storage and use it&#39;s id...
Definition: Services.php:67
Class ilAsqQuestionAuthoringFactory.