partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 4c47bdc55b7f648c9cd509d5fe1ceb86024f3b88
parent 58bc00b52c6bf00242ee0b78c709fd1b552bab62
Author: Felicitus <felicitus@felicitus.org>
Date:   Sun,  2 Aug 2015 16:27:20 +0200

Refactored the image controller infrastructure to allow using UploadedFile and not only Image entities. This is important as attachments can be either an image or not

Diffstat:
Mapp/config/config.yml | 17++++++++++++++++-
Msrc/PartKeepr/ImageBundle/Controller/ImageController.php | 13+++++++------
Msrc/PartKeepr/ImageBundle/Entity/CachedImage.php | 15++++++++++-----
Msrc/PartKeepr/PartBundle/Controller/PartAttachmentController.php | 4++--
4 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/app/config/config.yml b/app/config/config.yml @@ -343,6 +343,21 @@ services: arguments: - { groups: [ "default" ] } + resource.part_attachment.item_operation.custom_get_image: + class: "Dunglas\ApiBundle\Api\Operation\Operation" + public: false + factory: [ "@api.operation_factory", "createItemOperation" ] + arguments: + - "@resource.part_attachment" # Resource + - [ "GET" ] # Methods + - "/part_attachments/{id}/getImage" # Path + - "PartKeeprPartBundle:PartAttachment:getImage" # Controller + - "PartAttachmentGetImage" # Route name + - # Context (will be present in Hydra documentation) + "@type": "hydra:Operation" + "hydra:title": "A custom operation" + "returns": "xmls:string" + resource.part_attachment.item_operation.custom_get: class: "Dunglas\ApiBundle\Api\Operation\Operation" public: false @@ -385,7 +400,7 @@ services: tags: [ { name: "api.resource" } ] calls: - method: "initItemOperations" - arguments: [ [ "@resource.part_attachment.item_operation.get", "@resource.part_attachment.item_operation.custom_get", "@resource.part_attachment.item_operation.custom_get_mime" ] ] + arguments: [ [ "@resource.part_attachment.item_operation.get", "@resource.part_attachment.item_operation.custom_get", "@resource.part_attachment.item_operation.custom_get_mime", "@resource.part_attachment.item_operation.custom_get_image" ] ] - method: "initFilters" arguments: [ [ "@doctrine_reflection_service.search_filter" ] ] - method: "initNormalizationContext" diff --git a/src/PartKeepr/ImageBundle/Controller/ImageController.php b/src/PartKeepr/ImageBundle/Controller/ImageController.php @@ -11,6 +11,7 @@ use PartKeepr\ImageBundle\Entity\CachedImage; use PartKeepr\ImageBundle\Entity\Image as PartKeeprImage; use PartKeepr\ImageBundle\Response\ImageNotFoundResponse; use PartKeepr\UploadedFileBundle\Controller\FileController; +use PartKeepr\UploadedFileBundle\Entity\UploadedFile; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -95,14 +96,14 @@ abstract class ImageController extends FileController /** * Scales the image to fit within the given size. * - * @param PartKeeprImage $image The image to scale + * @param UploadedFile $image The image to scale * @param int $width The width * @param int $height The height * @param boolean $padding If true, pad the output image to the given size (transparent background). * * @return string The path to the scaled file */ - public function fitWithin(PartKeeprImage $image, $width, $height, $padding = false) + public function fitWithin(UploadedFile $image, $width, $height, $padding = false) { $this->ensureCacheDirExists(); @@ -132,14 +133,14 @@ abstract class ImageController extends FileController /** * Returns the path to an image which has been cached in a particular width, height and mode. * - * @param PartKeeprImage $image The image + * @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(PartKeeprImage $image, $width, $height, $mode) + public function getImageCacheFilename(UploadedFile $image, $width, $height, $mode) { $outputFile = $this->getImageCacheDirectory(); $outputFile .= "/".sha1($image->getFilename()); @@ -151,14 +152,14 @@ abstract class ImageController extends FileController /** * Checks if the database contains the cache file. * - * @param PartKeeprImage $image + * @param UploadedFile $image * @param $width * @param $height * @param $mode * * @return bool */ - protected function hasCacheFile(PartKeeprImage $image, $width, $height, $mode) + protected function hasCacheFile(UploadedFile $image, $width, $height, $mode) { $cacheFilename = $this->getImageCacheFilename($image, $width, $height, $mode); diff --git a/src/PartKeepr/ImageBundle/Entity/CachedImage.php b/src/PartKeepr/ImageBundle/Entity/CachedImage.php @@ -2,6 +2,7 @@ namespace PartKeepr\ImageBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use PartKeepr\UploadedFileBundle\Entity\UploadedFile; use PartKeepr\Util\BaseEntity; /** @@ -40,10 +41,10 @@ class CachedImage extends BaseEntity /** * Creates a new cache entry for a specific image. * - * @param Image $image The image to cache - * @param string $cacheFile The file which holds the cached image + * @param UploadedFile $image The image to cache + * @param string $cacheFile The file which holds the cached image */ - public function __construct(Image $image, $cacheFile) + public function __construct(UploadedFile $image, $cacheFile) { $this->originalId = (int)$image->getId(); $this->originalType = $image->getType(); @@ -62,17 +63,21 @@ class CachedImage extends BaseEntity /** * Returns the original ID + * * @return int */ - public function getOriginalId () { + public function getOriginalId() + { return $this->originalId; } /** * Returns the original type + * * @return string */ - public function getOriginalType () { + public function getOriginalType() + { return $this->originalType; } } diff --git a/src/PartKeepr/PartBundle/Controller/PartAttachmentController.php b/src/PartKeepr/PartBundle/Controller/PartAttachmentController.php @@ -1,9 +1,9 @@ <?php namespace PartKeepr\PartBundle\Controller; -use PartKeepr\UploadedFileBundle\Controller\FileController; +use PartKeepr\ImageBundle\Controller\ImageController; -class PartAttachmentController extends FileController +class PartAttachmentController extends ImageController { /** * @inheritdoc