From dfa699fecb042a1143f4647baa9c6c2c00226773 Mon Sep 17 00:00:00 2001 From: Benoit Sagols Date: Thu, 31 Mar 2016 16:59:00 +0700 Subject: [PATCH 1/2] Adding possibilty to define / instanciate Templates with arguments --- src/Intervention/Image/ImageCacheController.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Intervention/Image/ImageCacheController.php b/src/Intervention/Image/ImageCacheController.php index 7fca05d..dace138 100644 --- a/src/Intervention/Image/ImageCacheController.php +++ b/src/Intervention/Image/ImageCacheController.php @@ -26,7 +26,7 @@ public function getResponse($template, $filename) case 'download': return $this->getDownload($filename); - + default: return $this->getImage($template, $filename); } @@ -55,7 +55,7 @@ public function getImage($template, $filename) // build from filter template $image->make($path)->filter($template); } - + }, config('imagecache.lifetime')); return $this->buildResponse($content); @@ -106,9 +106,14 @@ private function getTemplate($template) return $template; // filter template found - case class_exists($template): + case is_string($template) && class_exists($template): return new $template; - + + // filter template is a class with arguments + case is_array($template): + $rc = new \ReflectionClass(array_shift($template)); + return $rc->newInstanceArgs($template); + default: // template not found abort(404); @@ -141,7 +146,7 @@ private function getImagePath($filename) /** * Builds HTTP response from given image data * - * @param string $content + * @param string $content * @return Illuminate\Http\Response */ private function buildResponse($content) From f9ab1dbefa27b081e3fe1fbf7913ea7139cf7a89 Mon Sep 17 00:00:00 2001 From: Benoit Sagols Date: Thu, 31 Mar 2016 17:00:12 +0700 Subject: [PATCH 2/2] typo --- src/Intervention/Image/ImageCacheController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Intervention/Image/ImageCacheController.php b/src/Intervention/Image/ImageCacheController.php index dace138..9680adf 100644 --- a/src/Intervention/Image/ImageCacheController.php +++ b/src/Intervention/Image/ImageCacheController.php @@ -109,7 +109,7 @@ private function getTemplate($template) case is_string($template) && class_exists($template): return new $template; - // filter template is a class with arguments + // filter with arguments template found case is_array($template): $rc = new \ReflectionClass(array_shift($template)); return $rc->newInstanceArgs($template);