Blame view

sources/apps/contacts/lib/imageresponse.php 1.11 KB
d1bafeea1   Kload   [fix] Upgrade to ...
1
2
3
  <?php
  /**
   * @author Thomas Tanghus
6d9380f96   Cédric Dupont   Update sources OC...
4
5
   * @copyright 2013-2014 Thomas Tanghus (thomas@tanghus.net)
   *
d1bafeea1   Kload   [fix] Upgrade to ...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
   * This file is licensed under the Affero General Public License version 3 or
   * later.
   * See the COPYING-README file.
   */
  
  namespace OCA\Contacts;
  
  use OCP\AppFramework\Http\Response;
  
  
  /**
   * A renderer for images
   */
  class ImageResponse extends Response {
  	/**
  	 * @var OCP\Image
  	 */
  	protected $image;
  
  	/**
6d9380f96   Cédric Dupont   Update sources OC...
26
  	 * @param \OCP\Image $image
d1bafeea1   Kload   [fix] Upgrade to ...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  	 */
  	public function __construct($image = null) {
  		if(!is_null($image)) {
  			$this->setImage($image);
  		}
  	}
  
  	/**
  	 * @param OCP\Image $image
  	 */
  	public function setImage(\OCP\Image $image) {
  		if(!$image->valid()) {
  			throw new \InvalidArgumentException(__METHOD__. ' The image resource is not valid.');
  		}
  		$this->image = $image;
  		$this->addHeader('Content-Type', $image->mimeType());
  		return $this;
  	}
  
  	/**
  	 * Return the image data stream
  	 * @return Image data
  	 */
  	public function render() {
  		if(is_null($this->image)) {
  			throw new \BadMethodCallException(__METHOD__. ' Image must be set either in constructor or with setImage()');
  		}
  		return $this->image->data();
  	}
  
  }