Skip to content
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

New way to load images #16

Merged
merged 3 commits into from
Aug 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/image-loaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions src/Factory/Imagine/Loader/SimpleFileSystemLoaderFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace HtImgModule\Factory\Imagine\Loader;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use HtImgModule\Imagine\Loader\SimpleFileSystemLoader;
use Zend\ServiceManager\MutableCreationOptionsInterface;
use HtImgModule\Exception;

class SimpleFileSystemLoaderFactory implements FactoryInterface, MutableCreationOptionsInterface
{
/**
* @var array
*/
protected $options = [];

/**
* {@inheritDoc}
*/
public function setCreationOptions(array $options)
{
$this->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']);
}
}
5 changes: 5 additions & 0 deletions src/Imagine/Loader/LoaderPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
namespace HtImgModuleTest\Factory\Imagine\Loader;

use Zend\ServiceManager\ServiceManager;
use HtImgModule\Factory\Imagine\Loader\SimpleFileSystemLoaderFactory;

class SimpleFileSystemLoaderFactoryTest extends \PHPUnit_Framework_TestCase
{
public function testCreateService()
{
$serviceManager = new ServiceManager();
$factory = new SimpleFileSystemLoaderFactory;
$factory->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);
}
}