ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
Services.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
4
5use Generator;
20use LogicException;
21
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
An exception for terminatinating execution or to throw for unit testing.
__construct()
Services constructor.
Definition: Services.php:45
getRevision(ResourceIdentification $identification)
Definition: Services.php:93
stream(ResourceIdentification $identification)
Definition: Services.php:135
find(string $identification)
Definition: Services.php:81
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's id...
Definition: Services.php:67
download(ResourceIdentification $identification)
Definition: Services.php:123
Class ilAsqQuestionAuthoringFactory.