-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add GaufretteFilesystemLoader #63
Changes from 2 commits
ba7c2dc
cb38837
b95de65
848ffab
2c18c55
3a66d4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Liip\ImagineBundle\Imagine\Data\Loader; | ||
|
||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
|
||
use Imagine\Image\ImagineInterface; | ||
|
||
class StreamLoader implements LoaderInterface | ||
{ | ||
/** | ||
* @var ImagineInterface | ||
*/ | ||
protected $imagine; | ||
|
||
/** | ||
* The wrapper prefix to append to the path to be loaded. | ||
* | ||
* @var string | ||
*/ | ||
protected $wrapperPrefix; | ||
|
||
/** | ||
* A stream context resource to use. | ||
* | ||
* @var \resource|null | ||
*/ | ||
protected $context; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \Imagine\Image\ImagineInterface $imagine | ||
* @param string $wrapperPrefix | ||
* @param \resource|null $context | ||
*/ | ||
public function __construct(ImagineInterface $imagine, $wrapperPrefix, \resource $context = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you really typehint a resource ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, no you can't, fixed. |
||
{ | ||
$this->imagine = $imagine; | ||
$this->wrapperPrefix = $wrapperPrefix; | ||
$this->context = $context; | ||
} | ||
|
||
/** | ||
* @param string $path | ||
* | ||
* @return \Imagine\Image\ImageInterface | ||
*/ | ||
public function find($path) | ||
{ | ||
$name = $this->wrapperPrefix.$path; | ||
|
||
/* | ||
* This looks strange, but at least in PHP 5.3.8 it will raise an E_WARNING if the 4th parameter is null. | ||
* fopen() will be called only once with the correct arguments. | ||
* | ||
* The error suppressing is solely to determ whether the file exists. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo here |
||
* file_exists() is not used as not all wrappers support stat() to actually check for existing resources. | ||
*/ | ||
if (($this->context and @!fopen($name, 'r', null, $this->context)) || @!fopen($name, 'r')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, you should close the stream you just opened to avoid keeping an eventual lock |
||
throw new NotFoundHttpException('Source image not found.'); | ||
} | ||
|
||
$image = $this->imagine->load(file_get_contents($name, null, $this->context)); | ||
|
||
return $image; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to create |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resource
is not a class but a PHP type so you should remove the\