diff --git a/Imagine/Data/Loader/AbstractDoctrineLoader.php b/Imagine/Data/Loader/AbstractDoctrineLoader.php index 4113aaf48..42f4f7e2b 100644 --- a/Imagine/Data/Loader/AbstractDoctrineLoader.php +++ b/Imagine/Data/Loader/AbstractDoctrineLoader.php @@ -23,18 +23,29 @@ abstract class AbstractDoctrineLoader implements LoaderInterface */ protected $class; + /** + * @var array + */ + protected $formats; + /** * Constructor. * * @param ImagineInterface $imagine * @param ObjectManager $manager * @param string $class + * @param array $formats possible image formats to look up file ids */ - public function __construct(ImagineInterface $imagine, ObjectManager $manager, $class = null) - { + public function __construct( + ImagineInterface $imagine, + ObjectManager $manager, + $class = null, + array $formats = array() + ) { $this->imagine = $imagine; $this->manager = $manager; $this->class = $class; + $this->formats = $formats; } /** @@ -64,6 +75,24 @@ public function find($path) { $image = $this->manager->find($this->class, $this->mapPathToId($path)); + if (!$image) { + // try to find the image without extension + $info = pathinfo($path); + $name = $info['dirname'].'/'.$info['filename']; + + // attempt to determine available format + foreach ($this->formats as $format) { + if ($image = $this->manager->find($this->class, $this->mapPathToId($name.'.'.$format))) { + break; + } + } + + // maybe the image has an id without extension + if (!$image) { + $image = $this->manager->find($this->class, $this->mapPathToId($name)); + } + } + if (!$image) { throw new NotFoundHttpException(sprintf('Source image not found with id "%s"', $path)); }