diff --git a/src/Intervention/Image/AbstractDecoder.php b/src/Intervention/Image/AbstractDecoder.php index c1aff632..a8c29d23 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 Symfony UploadedFile component + * + * @return boolean + */ + public function isSymfonyUpload() + { + return is_a($this->data, 'Symfony\Component\HttpFoundation\File\UploadedFile'); + } + /** * Determines if current source data is file path * @@ -161,6 +171,10 @@ abstract class AbstractDecoder return $this->initFromInterventionImage($this->data); break; + case $this->isSymfonyUpload(): + return $this->initFromPath($this->data->getRealPath()); + break; + case $this->isBinary(): return $this->initFromBinary($this->data); break; diff --git a/tests/AbstractDecoderTest.php b/tests/AbstractDecoderTest.php index 5b5991f7..d3679318 100644 --- a/tests/AbstractDecoderTest.php +++ b/tests/AbstractDecoderTest.php @@ -89,6 +89,16 @@ class AbstractDecoderTest extends PHPUnit_Framework_TestCase $this->assertTrue($source->isInterventionImage()); } + public function testIsSymfonyUpload() + { + $source = $this->getTestDecoder(1); + $this->assertFalse($source->isSymfonyUpload()); + + $img = Mockery::mock('Symfony\Component\HttpFoundation\File\UploadedFile'); + $source = $this->getTestDecoder($img); + $this->assertTrue($source->isSymfonyUpload()); + } + public function getTestDecoder($data) { return $this->getMockForAbstractClass('\Intervention\Image\AbstractDecoder', array($data));