1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-04 15:24:35 +01:00
OwncloudContactsOfficial/lib/imageresponse.php

57 lines
1.1 KiB
PHP
Raw Normal View History

2013-04-24 23:38:31 +02:00
<?php
/**
2013-09-24 13:39:45 +02:00
* @author Thomas Tanghus
2014-01-26 00:40:22 +01:00
* @copyright 2013-2014 Thomas Tanghus (thomas@tanghus.net)
*
2013-04-24 23:38:31 +02:00
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Contacts;
2013-09-24 13:39:45 +02:00
use OCP\AppFramework\Http\Response;
2013-04-24 23:38:31 +02:00
/**
* A renderer for images
*/
class ImageResponse extends Response {
/**
2013-08-29 17:46:37 +02:00
* @var OCP\Image
2013-04-24 23:38:31 +02:00
*/
protected $image;
2013-09-24 13:39:45 +02:00
/**
2014-03-23 19:02:16 +01:00
* @param \OCP\Image $image
2013-09-24 13:39:45 +02:00
*/
2013-04-24 23:38:31 +02:00
public function __construct($image = null) {
2013-09-24 13:39:45 +02:00
if(!is_null($image)) {
$this->setImage($image);
}
2013-04-24 23:38:31 +02:00
}
2013-09-24 13:39:45 +02:00
/**
* @param OCP\Image $image
*/
2013-08-29 17:46:37 +02:00
public function setImage(\OCP\Image $image) {
2013-04-24 23:38:31 +02:00
if(!$image->valid()) {
2013-10-17 02:10:34 +02:00
throw new \InvalidArgumentException(__METHOD__. ' The image resource is not valid.');
2013-04-24 23:38:31 +02:00
}
$this->image = $image;
$this->addHeader('Content-Type', $image->mimeType());
2013-10-17 02:10:34 +02:00
return $this;
2013-04-24 23:38:31 +02:00
}
/**
* Return the image data stream
* @return Image data
*/
public function render() {
if(is_null($this->image)) {
2013-10-17 02:10:34 +02:00
throw new \BadMethodCallException(__METHOD__. ' Image must be set either in constructor or with setImage()');
2013-04-24 23:38:31 +02:00
}
return $this->image->data();
}
}