partkeepr

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

commit 9552c122260d01c7ab71f192a9f2899919996b69
parent 8ae8450e1e98c9cfb7e6409963d1b4472097d7d4
Author: Felicitus <felicitus@felicitus.org>
Date:   Thu, 16 Jun 2011 08:10:45 +0800

Added "size" information to uploaded files, misc minor changes + documentation

Diffstat:
Msrc/de/RaumZeitLabor/PartKeepr/Image/CachedImage.php | 22++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartKeepr/Image/TempImage.php | 5++++-
Msrc/de/RaumZeitLabor/PartKeepr/UploadedFile/UploadedFile.php | 20+++++++++++++++++++-
3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/src/de/RaumZeitLabor/PartKeepr/Image/CachedImage.php b/src/de/RaumZeitLabor/PartKeepr/Image/CachedImage.php @@ -5,6 +5,10 @@ declare(encoding = 'UTF-8'); use de\RaumZeitLabor\PartKeepr\PartKeepr; /** + * Represtends a cached image. Cached images are used for scale/resize + * operations, so that the resize/scale operation doesn't need to be done + * every time a scaled/resized image is requested. + * * @Entity */ class CachedImage { @@ -42,16 +46,34 @@ class CachedImage { */ private $cacheFile; + /** + * 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 + */ public function __construct (Image $image, $cacheFile) { $this->originalId = (int)$image->getId(); $this->originalType = $image->getType(); $this->cacheFile = $cacheFile; } + /** + * Returns the cache file + * @return string The cache file including path + */ public function getCacheFile () { return $this->cacheFile; } + /** + * Removes all caches for a specific image. This is usually called + * when a new version of an image is uploaded. + * + * Automatically calls "flush" on the entity manager. + * + * @param Image $image The image to invalidate + */ public static function invalidate (Image $image) { $qb = PartKeepr::getEM()->createQueryBuilder(); $qb->select(array("c")) diff --git a/src/de/RaumZeitLabor/PartKeepr/Image/TempImage.php b/src/de/RaumZeitLabor/PartKeepr/Image/TempImage.php @@ -8,7 +8,10 @@ use de\RaumZeitLabor\PartKeepr\Image\Exceptions\InvalidImageTypeException, de\RaumZeitLabor\PartKeepr\PartKeepr; /** - * @Entity + * Represents a temporary image. Temporary images are used when + * a user uploaded an image, but not attached it to an entity. + * + * @Entity */ class TempImage extends Image { public function __construct () { diff --git a/src/de/RaumZeitLabor/PartKeepr/UploadedFile/UploadedFile.php b/src/de/RaumZeitLabor/PartKeepr/UploadedFile/UploadedFile.php @@ -43,6 +43,13 @@ abstract class UploadedFile { private $mimetype; /** + * The size of the uploaded file + * @Column(type="integer") + * @var integer + */ + private $size; + + /** * Constructs a new file object. * */ @@ -64,10 +71,13 @@ abstract class UploadedFile { * @param string $path The path to the original file */ public function replace ($path) { + // Parse the file's mimetype $finfo = new \finfo(FILEINFO_MIME); - $this->mimetype = $finfo->file($path, FILEINFO_MIME_TYPE); + // Get the file size + $this->size = filesize($path); + $this->ensureFilePathExists(); copy($path, $this->getFilename()); } @@ -82,6 +92,14 @@ abstract class UploadedFile { } /** + * Returns the size of this file + * @return integer The size in bytes + */ + public function getSize () { + return $this->size; + } + + /** * Returns the type of the file * @param none * @return string The type of the file