-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #291 from formapro-forks/mime-type-guesser
[1.0] Rework data loaders. Introduce mime type guesser.
- Loading branch information
Showing
28 changed files
with
811 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
namespace Liip\ImagineBundle\Binary; | ||
|
||
interface BinaryInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getContent(); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getMimeType(); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getFormat(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
namespace Liip\ImagineBundle\Binary; | ||
|
||
interface MimeTypeGuesserInterface | ||
{ | ||
/** | ||
* @param string $binary The image binary | ||
* | ||
* @return string|null mime type or null if it could be not be guessed. | ||
*/ | ||
function guess($binary); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
namespace Liip\ImagineBundle\Binary; | ||
|
||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface as SymfonyMimeTypeGuesserInterface; | ||
|
||
class SimpleMimeTypeGuesser implements MimeTypeGuesserInterface | ||
{ | ||
/** | ||
* @var \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface | ||
*/ | ||
protected $mimeTypeGuesser; | ||
|
||
/** | ||
* @param SymfonyMimeTypeGuesserInterface $mimeTypeGuesser | ||
*/ | ||
public function __construct(SymfonyMimeTypeGuesserInterface $mimeTypeGuesser) | ||
{ | ||
$this->mimeTypeGuesser = $mimeTypeGuesser; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function guess($binary) | ||
{ | ||
$tmpFile = tempnam(sys_get_temp_dir(), 'liip-imagine-bundle'); | ||
|
||
try { | ||
file_put_contents($tmpFile, $binary); | ||
|
||
$mimeType = $this->mimeTypeGuesser->guess($tmpFile); | ||
|
||
unlink($tmpFile); | ||
|
||
return $mimeType; | ||
} catch (\Exception $e) { | ||
unlink($tmpFile); | ||
|
||
throw $e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.