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