ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.HTTPUtil.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 use ILIAS\HTTP;
26 
30 class HTTPUtil
31 {
32  protected HTTP\Services $http;
33 
34  public function __construct(HTTP\Services $http)
35  {
36  $this->http = $http;
37  }
38 
39  public function sendString(string $output): void
40  {
41  $this->http->saveResponse($this->http->response()->withBody(
42  Streams::ofString($output)
43  ));
44  $this->http->sendResponse();
45  $this->http->close();
46  }
47 
48  public function deliverString(
49  string $data,
50  string $filename,
51  string $mime = "application/octet-stream"
52  ): void {
53  $delivery = new Delivery(
55  $this->http
56  );
57  $delivery->setMimeType($mime);
58  $delivery->setSendMimeType(true);
59  $delivery->setDisposition(Delivery::DISP_ATTACHMENT);
60  $delivery->setDownloadFileName($filename);
61  $delivery->setConvertFileNameToAsci(true);
62  $repsonse = $this->http->response()->withBody(Streams::ofString($data));
63  $this->http->saveResponse($repsonse);
64  $delivery->deliver();
65  }
66 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
deliverString(string $data, string $filename, string $mime="application/octet-stream")
$filename
Definition: buildRTE.php:78
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
Class Delivery.
Definition: Delivery.php:38
__construct(HTTP\Services $http)