ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.HTTPUtil.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\HTTP;
27
32{
34
35 public function __construct(HTTP\Services $http)
36 {
37 $this->http = $http;
38 }
39
40 public function sendString(string $output): void
41 {
42 $this->http->saveResponse($this->http->response()->withBody(
43 Streams::ofString($output)
44 ));
45 $this->http->sendResponse();
46 $this->http->close();
47 }
48
49 public function deliverString(
50 string $data,
51 string $filename,
52 string $mime = "application/octet-stream"
53 ): void {
54 $delivery = new Delivery(
55 Delivery::DIRECT_PHP_OUTPUT,
56 $this->http
57 );
58 $delivery->setMimeType($mime);
59 $delivery->setSendMimeType(true);
60 $delivery->setDisposition(Delivery::DISP_ATTACHMENT);
61 $delivery->setDownloadFileName($filename);
62 $delivery->setConvertFileNameToAsci(true);
63 $repsonse = $this->http->response()->withBody(Streams::ofString($data));
64 $this->http->saveResponse($repsonse);
65 $delivery->deliver();
66 }
67
68 public function deliverStream(
69 FileStream $stream,
70 string $filename,
71 string $mime = "application/octet-stream"
72 ): void {
73 $delivery = new Delivery(
74 Delivery::DIRECT_PHP_OUTPUT,
75 $this->http
76 );
77 $delivery->setMimeType($mime);
78 $delivery->setSendMimeType(true);
79 $delivery->setDisposition(Delivery::DISP_ATTACHMENT);
80 $delivery->setDownloadFileName($filename);
81 $delivery->setConvertFileNameToAsci(true);
82 $repsonse = $this->http->response()->withBody($stream);
83 $this->http->saveResponse($repsonse);
84 $delivery->deliver();
85 }
86}
$filename
Definition: buildRTE.php:78
setMimeType(string $mime_type)
Definition: Delivery.php:285
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
Class Services.
Definition: Services.php:38
deliverString(string $data, string $filename, string $mime="application/octet-stream")
deliverStream(FileStream $stream, string $filename, string $mime="application/octet-stream")
__construct(HTTP\Services $http)
The base interface for all filesystem streams.
Definition: FileStream.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...