Completed
Push — stable8.2 ( 09e830...ae9bfd )
by Olivier
12:09
created

ImageResponse   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A render() 0 8 2
1
<?php
2
/**
3
 * ownCloud - galleryplus
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Olivier Paroz <[email protected]>
9
 *
10
 * @copyright Olivier Paroz 2014-2015
11
 */
12
13
namespace OCA\GalleryPlus\Http;
14
15
use OCP\AppFramework\Http\Response;
16
use OCP\AppFramework\Http;
17
18
/**
19
 * A renderer for images
20
 *
21
 * @package OCA\GalleryPlus\Http
22
 */
23
class ImageResponse extends Response {
24
25
	/**
26
	 * @var \OC_Image|string
27
	 */
28
	private $preview;
29
30
	/**
31
	 * Constructor
32
	 *
33
	 * @param array $image image meta data
34
	 * @param int $statusCode the HTTP status code, defaults to 200
35
	 */
36 18
	public function __construct(array $image, $statusCode = Http::STATUS_OK) {
37 18
		$name = $image['name'];
38 18
		$this->preview = $image['preview'];
39
40 18
		$this->setStatus($statusCode);
41 18
		$this->addHeader('Content-type', $image['mimetype'] . '; charset=utf-8');
42 18
		$this->addHeader('Content-Disposition',
43 18
						 'attachment; filename*=UTF-8\'\'' . rawurlencode($name) . '; filename="'
44 18
						 . rawurlencode($name) . '"'
45
		);
46 18
	}
47
48
	/**
49
	 * Returns the rendered image
50
	 *
51
	 * @return string the file
52
	 */
53 13
	public function render() {
54 13
		if ($this->preview instanceof \OC_Image) {
55
			// Uses imagepng() to output the image
56 3
			return $this->preview->data();
57
		} else {
58 10
			return $this->preview;
59
		}
60
	}
61
62
}
63