ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
Consumers.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 
36 class Consumers
37 {
42 
46  public function __construct(
47  ConsumerFactory $consumer_factory,
48  ResourceBuilder $resource_builder,
49  CollectionBuilder $collection_builder,
50  ?SrcBuilder $src_builder = null
51  ) {
52  $this->consumer_factory = $consumer_factory;
53  $this->resource_builder = $resource_builder;
54  $this->collection_builder = $collection_builder;
55  $this->src_builder = $src_builder ?? new InlineSrcBuilder();
56  }
57 
58  public function download(ResourceIdentification $identification): DownloadConsumer
59  {
60  return $this->consumer_factory->download($this->resource_builder->get($identification));
61  }
62 
63  public function inline(ResourceIdentification $identification): InlineConsumer
64  {
65  return $this->consumer_factory->inline($this->resource_builder->get($identification));
66  }
67 
68  public function stream(ResourceIdentification $identification): FileStreamConsumer
69  {
70  return $this->consumer_factory->fileStream($this->resource_builder->get($identification));
71  }
72 
73  public function src(ResourceIdentification $identification): SrcConsumer
74  {
75  return $this->consumer_factory->src($this->resource_builder->get($identification), $this->src_builder);
76  }
77 
78  public function downloadCollection(
79  ResourceCollectionIdentification $identification,
80  ?string $zip_filename = null
82  return $this->downloadResources(
83  iterator_to_array($this->collection_builder->getResourceIds($identification)),
84  $zip_filename
85  );
86  }
87 
88  public function downloadResources(
89  array $identifications,
90  ?string $zip_filename = null
92  $resources = [];
93  foreach ($identifications as $rid) {
94  if (!$rid instanceof ResourceIdentification) {
95  throw new \InvalidArgumentException('Expected ResourceIdentification');
96  }
97  $resources[] = $this->resource_builder->get($rid);
98  }
99 
100  return $this->consumer_factory->downloadMultiple(
101  $resources,
102  $zip_filename
103  );
104  }
105 
106  public function flavourUrls(Flavour $flavour): FlavourURLs
107  {
108  return $this->consumer_factory->flavourUrl($flavour, $this->src_builder);
109  }
110 
115  {
116  $resource = $this->resource_builder->get($identification);
117  if ($resource->getType() !== ResourceType::CONTAINER || !$resource instanceof StorableContainerResource) {
118  throw new \InvalidArgumentException('Expected StorableContainerResource');
119  }
120 
121  return $this->consumer_factory->containerZIP(
122  $resource
123  );
124  }
125 
126  public function containerURI(
127  ResourceIdentification $identification,
128  string $start_file = 'index.html',
129  float $valid_for_at_least_minutes = 60.0
131  $resource = $this->resource_builder->get($identification);
132  if ($resource->getType() !== ResourceType::CONTAINER || !$resource instanceof StorableContainerResource) {
133  throw new \InvalidArgumentException('Expected StorableContainerResource');
134  }
135  return $this->consumer_factory->containerURI(
136  $resource,
137  $this->src_builder,
138  ltrim($start_file, '/'),
139  $valid_for_at_least_minutes
140  );
141  }
142 }
$resources
Definition: ltiservices.php:68
download(ResourceIdentification $identification)
Definition: Consumers.php:58
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
containerURI(ResourceIdentification $identification, string $start_file='index.html', float $valid_for_at_least_minutes=60.0)
Definition: Consumers.php:126
downloadResources(array $identifications, ?string $zip_filename=null)
Definition: Consumers.php:88
containerZIP(ResourceIdentification $identification)
This consumer can be used to obtain a StorageContainerResource as a ZIP.
Definition: Consumers.php:114
__construct(ConsumerFactory $consumer_factory, ResourceBuilder $resource_builder, CollectionBuilder $collection_builder, ?SrcBuilder $src_builder=null)
Consumers constructor.
Definition: Consumers.php:46
src(ResourceIdentification $identification)
Definition: Consumers.php:73
downloadCollection(ResourceCollectionIdentification $identification, ?string $zip_filename=null)
Definition: Consumers.php:78
stream(ResourceIdentification $identification)
Definition: Consumers.php:68