From f53575d4e46400ffecc016a6220a89cca359d821 Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Sun, 24 Aug 2014 22:14:35 +0545 Subject: [PATCH 1/3] factory for simple image loader factory --- .../Loader/SimpleFileSystemLoaderFactory.php | 33 +++++++++++++++++++ src/Imagine/Loader/LoaderPluginManager.php | 5 +++ .../SimpleFileSystemLoaderFactoryTest.php | 24 ++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/Factory/Imagine/Loader/SimpleFileSystemLoaderFactory.php create mode 100644 tests/HtImgModuleTest/Factory/Imagine/Loader/SimpleFileSystemLoaderFactoryTest.php diff --git a/src/Factory/Imagine/Loader/SimpleFileSystemLoaderFactory.php b/src/Factory/Imagine/Loader/SimpleFileSystemLoaderFactory.php new file mode 100644 index 0000000..c42250d --- /dev/null +++ b/src/Factory/Imagine/Loader/SimpleFileSystemLoaderFactory.php @@ -0,0 +1,33 @@ +options = $options; + } + + public function createService(ServiceLocatorInterface $loaders) + { + if (!isset($this->options['root_path'])) { + throw new Exception\InvalidArgumentException('Missing "root_path" in options array'); + } + + return new SimpleFileSystemLoader($this->options['root_path']); + } +} diff --git a/src/Imagine/Loader/LoaderPluginManager.php b/src/Imagine/Loader/LoaderPluginManager.php index 5ccd093..9476d57 100644 --- a/src/Imagine/Loader/LoaderPluginManager.php +++ b/src/Imagine/Loader/LoaderPluginManager.php @@ -8,6 +8,11 @@ class LoaderPluginManager extends AbstractPluginManager { protected $factories = [ 'filesystem' => 'HtImgModule\Factory\Imagine\Loader\FileSystemLoaderFactory', + 'simple' => 'HtImgModule\Factory\Imagine\Loader\SimpleFileSystemLoaderFactoryTest', + ]; + + protected $shared = [ + 'simple' => false ]; public function validatePlugin($plugin) diff --git a/tests/HtImgModuleTest/Factory/Imagine/Loader/SimpleFileSystemLoaderFactoryTest.php b/tests/HtImgModuleTest/Factory/Imagine/Loader/SimpleFileSystemLoaderFactoryTest.php new file mode 100644 index 0000000..8cf43ff --- /dev/null +++ b/tests/HtImgModuleTest/Factory/Imagine/Loader/SimpleFileSystemLoaderFactoryTest.php @@ -0,0 +1,24 @@ +setCreationOptions(['root_path' => 'data/images']); + $this->assertInstanceOf('HtImgModule\Imagine\Loader\SimpleFileSystemLoader', $factory->createService($serviceManager)); + } + + public function testGetExceptionWhenRootPathOptionIsMissing() + { + $serviceManager = new ServiceManager(); + $factory = new SimpleFileSystemLoaderFactory; + $this->setExpectedException('HtImgModule\Exception\InvalidArgumentException'); + $factory->createService($serviceManager); + } +} From d67d33ad5cfa96d516b1f6f9978bb431283d3a64 Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Sun, 24 Aug 2014 22:19:10 +0545 Subject: [PATCH 2/3] fixed typo --- src/Imagine/Loader/LoaderPluginManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Imagine/Loader/LoaderPluginManager.php b/src/Imagine/Loader/LoaderPluginManager.php index 9476d57..fac85fd 100644 --- a/src/Imagine/Loader/LoaderPluginManager.php +++ b/src/Imagine/Loader/LoaderPluginManager.php @@ -8,7 +8,7 @@ class LoaderPluginManager extends AbstractPluginManager { protected $factories = [ 'filesystem' => 'HtImgModule\Factory\Imagine\Loader\FileSystemLoaderFactory', - 'simple' => 'HtImgModule\Factory\Imagine\Loader\SimpleFileSystemLoaderFactoryTest', + 'simple' => 'HtImgModule\Factory\Imagine\Loader\SimpleFileSystemLoaderFactory', ]; protected $shared = [ From a8230ad4a9169b37a061dcf08cb1c9c0e3f82675 Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Sun, 24 Aug 2014 22:24:09 +0545 Subject: [PATCH 3/3] update docs --- docs/image-loaders.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/image-loaders.md b/docs/image-loaders.md index 36a60a5..1050d57 100644 --- a/docs/image-loaders.md +++ b/docs/image-loaders.md @@ -34,6 +34,27 @@ $imageLoader = new HtImgModule\Imagine\Loader\SimpleFileSystemLoader('data/path/ $binary = $imageLoader->load('my-image.png'); ``` +This module can be used to load images by configuring like this: + +```php +return [ + 'htimg' => [ + 'filters' => [ + 'my_filter' => [ + 'type' => 'filter_type', + 'options' => [ + // ..... + 'image_loader' => 'simple', + 'loader_options' => [ + 'root_path' => 'data/images/uploads', + ] + ] + ] + ] + ] +] +``` + #### HtImgModule\Imagine\Loader\FileSystemLoader This image loaders resolves full path of image using image resolver and loads the image. ```php