1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-01 11:30:16 +02:00

allow decoding directly from upload object

This commit is contained in:
Oliver Vogel
2014-06-16 11:52:34 +02:00
parent 005999c873
commit edd507dacf
2 changed files with 24 additions and 0 deletions

View File

@@ -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;

View File

@@ -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));