-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from hrevert/feature/simple-image-loader-factory
New way to load images
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Factory/Imagine/Loader/SimpleFileSystemLoaderFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/HtImgModuleTest/Factory/Imagine/Loader/SimpleFileSystemLoaderFactoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |