From fd4bcf5f0bb606ca70db8769f25caa4e6ff582dc Mon Sep 17 00:00:00 2001 From: Johnson Date: Thu, 28 Aug 2014 09:37:10 +1000 Subject: [PATCH] Support creating Image from SplFileInfo object --- src/Intervention/Image/AbstractDecoder.php | 12 +++++++++++- tests/AbstractDecoderTest.php | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Intervention/Image/AbstractDecoder.php b/src/Intervention/Image/AbstractDecoder.php index 97135cae..dbf71666 100644 --- a/src/Intervention/Image/AbstractDecoder.php +++ b/src/Intervention/Image/AbstractDecoder.php @@ -87,6 +87,16 @@ abstract class AbstractDecoder return is_a($this->data, '\Intervention\Image\Image'); } + /** + * Determines if current data is SplFileInfo object + * + * @return boolean + */ + public function isSplFileInfo() + { + return is_a($this->data, 'SplFileInfo'); + } + /** * Determines if current data is Symfony UploadedFile component * @@ -198,7 +208,7 @@ abstract class AbstractDecoder case $this->isInterventionImage(): return $this->initFromInterventionImage($this->data); - case $this->isSymfonyUpload(): + case $this->isSplFileInfo(): return $this->initFromPath($this->data->getRealPath()); case $this->isBinary(): diff --git a/tests/AbstractDecoderTest.php b/tests/AbstractDecoderTest.php index b237dbc2..2fbe348c 100644 --- a/tests/AbstractDecoderTest.php +++ b/tests/AbstractDecoderTest.php @@ -89,6 +89,19 @@ class AbstractDecoderTest extends PHPUnit_Framework_TestCase $this->assertTrue($source->isInterventionImage()); } + public function testIsSplFileInfo() + { + $source = $this->getTestDecoder(1); + $this->assertFalse($source->isSplFileInfo()); + + $img = Mockery::mock('SplFileInfo'); + $source = $this->getTestDecoder($img); + $this->assertTrue($source->isSplFileInfo()); + + $img = Mockery::mock('Symfony\Component\HttpFoundation\File\UploadedFile', 'SplFileInfo'); + $this->assertTrue($source->isSplFileInfo()); + } + public function testIsSymfonyUpload() { $source = $this->getTestDecoder(1);