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 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..fac85fd 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\SimpleFileSystemLoaderFactory', + ]; + + 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); + } +}