Image.php (1482B)
1 <?php 2 3 namespace PartKeepr\ImageBundle\Entity; 4 5 use Doctrine\ORM\Mapping as ORM; 6 use PartKeepr\Image\Exceptions\InvalidImageTypeException; 7 use PartKeepr\UploadedFileBundle\Entity\UploadedFile; 8 9 /** 10 * This is only a storage class; actual image rendering is done by the ImageRenderer. 11 * 12 * @ORM\MappedSuperclass 13 */ 14 abstract class Image extends UploadedFile 15 { 16 const IMAGE_ICLOGO = 'iclogo'; 17 const IMAGE_TEMP = 'temp'; 18 const IMAGE_PART = 'part'; 19 const IMAGE_STORAGELOCATION = 'storagelocation'; 20 const IMAGE_FOOTPRINT = 'footprint'; 21 22 /** 23 * Constructs a new image object. 24 * 25 * @param string $type The type for the image, one of the IMAGE_ constants. 26 */ 27 public function __construct($type = null) 28 { 29 $this->setType($type); 30 parent::__construct(); 31 } 32 33 /** 34 * Sets the type of the image. Once the type is set, 35 * it may not be changed later. 36 * 37 * @param string $type The type for the image, one of the IMAGE_ constants. 38 * 39 * @throws InvalidImageTypeException 40 */ 41 protected function setType($type) 42 { 43 switch ($type) { 44 case self::IMAGE_ICLOGO: 45 case self::IMAGE_TEMP: 46 case self::IMAGE_PART: 47 case self::IMAGE_FOOTPRINT: 48 case self::IMAGE_STORAGELOCATION: 49 parent::setType($type); 50 break; 51 default: 52 throw new InvalidImageTypeException($type); 53 } 54 } 55 }