aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/AppFramework/Http/TextPlainResponse.php
blob: e7c728c37ab84c43a5605c7efbf47eb9f1c14d23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

declare(strict_types=1);
/**
 * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCP\AppFramework\Http;

use OCP\AppFramework\Http;

/**
 * A renderer for text responses
 * @since 22.0.0
 * @template S of int
 * @template H of array<string, mixed>
 * @template-extends Response<int, array<string, mixed>>
 */
class TextPlainResponse extends Response {
	/** @var string */
	private $text = '';

	/**
	 * constructor of TextPlainResponse
	 * @param string $text The text body
	 * @param S $statusCode the Http status code, defaults to 200
	 * @param H $headers
	 * @since 22.0.0
	 */
	public function __construct(string $text = '', int $statusCode = Http::STATUS_OK, array $headers = []) {
		parent::__construct($statusCode, $headers);

		$this->text = $text;
		$this->addHeader('Content-Type', 'text/plain');
	}


	/**
	 * Returns the text
	 * @return string
	 * @since 22.0.0
	 * @throws \Exception If data could not get encoded
	 */
	public function render() : string {
		return $this->text;
	}
}