2014-12-20 22:44:41 +01:00
|
|
|
<?php
|
2024-05-23 09:26:56 +02:00
|
|
|
|
2014-12-20 22:44:41 +01:00
|
|
|
/**
|
2024-05-23 09:26:56 +02:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2014-12-20 22:44:41 +01:00
|
|
|
*/
|
|
|
|
namespace OCP\AppFramework\Http;
|
|
|
|
|
2023-06-14 08:56:42 +02:00
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
|
2015-04-16 17:00:08 +02:00
|
|
|
/**
|
|
|
|
* Class DataDownloadResponse
|
|
|
|
*
|
|
|
|
* @since 8.0.0
|
2024-12-16 16:20:48 +01:00
|
|
|
* @template S of Http::STATUS_*
|
2023-06-14 08:56:42 +02:00
|
|
|
* @template C of string
|
|
|
|
* @template H of array<string, mixed>
|
2024-12-16 16:20:48 +01:00
|
|
|
* @template-extends DownloadResponse<Http::STATUS_*, string, array<string, mixed>>
|
2015-04-16 17:00:08 +02:00
|
|
|
*/
|
2014-12-20 22:44:41 +01:00
|
|
|
class DataDownloadResponse extends DownloadResponse {
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a response that prompts the user to download the text
|
|
|
|
* @param string $data text to be downloaded
|
|
|
|
* @param string $filename the name that the downloaded file should have
|
2023-06-14 08:56:42 +02:00
|
|
|
* @param C $contentType the mimetype that the downloaded file should have
|
|
|
|
* @param S $status
|
|
|
|
* @param H $headers
|
2015-04-16 17:00:08 +02:00
|
|
|
* @since 8.0.0
|
2014-12-20 22:44:41 +01:00
|
|
|
*/
|
2023-06-14 08:56:42 +02:00
|
|
|
public function __construct(string $data, string $filename, string $contentType, int $status = Http::STATUS_OK, array $headers = []) {
|
2014-12-20 22:44:41 +01:00
|
|
|
$this->data = $data;
|
2023-06-14 08:56:42 +02:00
|
|
|
parent::__construct($filename, $contentType, $status, $headers);
|
2014-12-20 22:44:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $data
|
2015-04-16 17:00:08 +02:00
|
|
|
* @since 8.0.0
|
2014-12-20 22:44:41 +01:00
|
|
|
*/
|
|
|
|
public function setData($data) {
|
|
|
|
$this->data = $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
2015-04-16 17:00:08 +02:00
|
|
|
* @since 8.0.0
|
2014-12-20 22:44:41 +01:00
|
|
|
*/
|
|
|
|
public function render() {
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
}
|