ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 sendJson(\stdClass $data): void
50 {
52 $string = json_encode($data);
54 $http->saveResponse($http
55 ->response()
56 ->withAddedHeader('Content-Type', 'application/json')
57 ->withBody($stream));
58 $http->sendResponse();
59 $http->close();
60 }
61
62 public function deliverString(
63 string $data,
64 string $filename,
65 string $mime = "application/octet-stream"
66 ): void {
67 $delivery = new Delivery(
68 Delivery::DIRECT_PHP_OUTPUT,
69 $this->http
70 );
71 $delivery->setMimeType($mime);
72 $delivery->setSendMimeType(true);
73 $delivery->setDisposition(Delivery::DISP_ATTACHMENT);
74 $delivery->setDownloadFileName($filename);
75 $delivery->setConvertFileNameToAsci(true);
76 $repsonse = $this->http->response()->withBody(Streams::ofString($data));
77 $this->http->saveResponse($repsonse);
78 $delivery->deliver();
79 }
80
81 public function deliverStream(
82 FileStream $stream,
83 string $filename,
84 string $mime = "application/octet-stream"
85 ): void {
86 $delivery = new Delivery(
87 Delivery::DIRECT_PHP_OUTPUT,
88 $this->http
89 );
90 $delivery->setMimeType($mime);
91 $delivery->setSendMimeType(true);
92 $delivery->setDisposition(Delivery::DISP_ATTACHMENT);
93 $delivery->setDownloadFileName($filename);
94 $delivery->setConvertFileNameToAsci(true);
95 $repsonse = $this->http->response()->withBody($stream);
96 $this->http->saveResponse($repsonse);
97 $delivery->deliver();
98 }
99}
$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...