/** * Sets the type of the image. Once the type is set, * it may not be changed later. * * @param string $type The type for the image, one of the IMAGE_ constants. * * @throws InvalidImageTypeException */ protected function setType($type) { switch ($type) { case self::IMAGE_ICLOGO: case self::IMAGE_TEMP: case self::IMAGE_PART: case self::IMAGE_FOOTPRINT: case self::IMAGE_STORAGELOCATION: parent::setType($type); break; default: throw new InvalidImageTypeException($type); } }
/** * Invalidates any cached files. * * @param UploadedFile $file The file to invalidate */ public function invalidate(UploadedFile $file) { /** * @var EntityManager */ $entityManager = $this->container->get('doctrine')->getManager(); $queryBuilder = $entityManager->createQueryBuilder(); $queryBuilder->select(['c'])->from('PartKeepr\\ImageBundle\\Entity\\CachedImage', 'c')->where('c.originalId = :id')->andWhere('c.originalType = :type')->setParameter('id', $file->getId())->setParameter('type', $file->getType()); $query = $queryBuilder->getQuery(); foreach ($query->getResult() as $file) { /** * @var CachedImage */ if (file_exists($file->getCacheFile())) { unlink($file->getCacheFile()); } $entityManager->remove($file); } }
/** * Creates a new cache entry for a specific image. * * @param UploadedFile $image The image to cache * @param string $cacheFile The file which holds the cached image */ public function __construct(UploadedFile $image, $cacheFile) { $this->originalId = (int) $image->getId(); $this->originalType = $image->getType(); $this->cacheFile = $cacheFile; }
public function __construct() { parent::__construct(); $this->setType('tempfile'); }
/** * Creates a new part attachment. */ public function __construct() { parent::__construct(); $this->setType('PartAttachment'); $this->isImage = null; }
/** * Creates a new project attachment. */ public function __construct() { parent::__construct(); $this->setType('ProjectAttachment'); }
/** * @param UploadedFile $file * * @return Filesystem */ public function getStorage(UploadedFile $file) { $type = strtolower($file->getType()); return $this->container->get("filesystem_" . $type); }
/** * Creates a new footprint attachment */ public function __construct() { parent::__construct(); $this->setType("FootprintAttachment"); }
/** * Returns the path to an image which has been cached in a particular width, height and mode. * * @param UploadedFile $image The image * @param integer $width The width * @param integer $height The height * @param string $mode The mode * * @return string */ public function getImageCacheFilename(UploadedFile $image, $width, $height, $mode) { $outputFile = $this->getImageCacheDirectory(); $outputFile .= "/" . sha1($image->getFilename()); $outputFile .= $width . "x" . $height . "_" . $mode . ".png"; return $outputFile; }
/** * Returns the path to an image which has been cached in a particular width, height and mode. * * @param UploadedFile $image The image * @param int $width The width * @param int $height The height * @param string $mode The mode * * @return string */ public function getImageCacheFilename(UploadedFile $image, $width, $height, $mode) { $outputFile = $this->getImageCacheDirectory(); $outputFile .= '/' . sha1($image->getFilename()); $outputFile .= $width . 'x' . $height . '_' . $mode . '.png'; return $outputFile; }