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

[WIP] Add ZF3 support #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 2 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ sudo: false

matrix:
include:
- php: 5.5
- php: 7
env:
- EXECUTE_CS_CHECK=true
- php: 5.6
- php: 7.1
env:
- EXECUTE_TEST_COVERALLS=true
- php: 7
- php: hhvm
allow_failures:
- php: 7
- php: hhvm

before_install:
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
Expand Down
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@
}
],
"require": {
"php": ">=5.5",
"zendframework/zend-mvc": "~2.5",
"zendframework/zend-modulemanager": "~2.5",
"zendframework/zend-servicemanager": "^2.7.5",
"zendframework/zend-http": "~2.5",
"zendframework/zend-stdlib": "~2.5",
"intervention/image": "~2.3"
"php": "^7.0",
"zendframework/zend-mvc": "^3.1.0",
"zendframework/zend-router": "^3.0",
"zendframework/zend-modulemanager": "^2.8.0",
"zendframework/zend-servicemanager": "^3.3.0",
"zendframework/zend-http": "^2.6.0",
"zendframework/zend-stdlib": "^3.1.0",
"intervention/image": "^2.4.0"
},
"require-dev": {
"ext-gd": "*",
"phpunit/phpunit": "4.*",
"squizlabs/php_codesniffer": "^2.0",
"scrutinizer/ocular": "~1.1",
"scrutinizer/ocular": "^1.3.2",
"league/flysystem": "^1.0"
},
"suggest": {
Expand Down
17 changes: 8 additions & 9 deletions src/Controller/Factory/ImageControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,33 @@

namespace SvImages\Controller\Factory;

use Psr\Container\ContainerInterface;
use SvImages\Controller\ImageController;
use SvImages\Options\ModuleOptions;
use SvImages\Service\CacheManager;
use SvImages\Service\ImageService;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* @author Vytautas Stankus <[email protected]>
* @license MIT
*/
class ImageControllerFactory implements FactoryInterface
class ImageControllerFactory
{
/**
* Create ImageController
*
* @param ServiceLocatorInterface $serviceLocator
* @param ContainerInterface $container
*
* @return ImageController
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container)
{
$sm = $serviceLocator->getServiceLocator();
/** @var ImageService $imageService */
$imageService = $sm->get(ImageService::class);
$imageService = $container->get(ImageService::class);
/** @var CacheManager $cacheManager */
$cacheManager = $sm->get(CacheManager::class);
$cacheManager = $container->get(CacheManager::class);
/** @var ModuleOptions $options */
$options = $sm->get(ModuleOptions::class);
$options = $container->get(ModuleOptions::class);

return new ImageController($imageService, $cacheManager, $options);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function imageAction()
$routeMatch = $this->getEvent()->getRouteMatch();

if (!$routeMatch instanceof RouteMatch) {
$this->notFoundAction(); // todo
return $this->notFoundAction(); // todo
}

$result = $routeMatch->getParserResult();
Expand All @@ -67,7 +67,7 @@ public function imageAction()
} catch (SvImagesException $exception) {
// TODO: maybe implement some kind of failure handling strategy?
// error image or 1px image would be better?
$this->notFoundAction();
return $this->notFoundAction();
}

if ($this->options->isCacheEnabled() && $contents) {
Expand Down
11 changes: 5 additions & 6 deletions src/ImageManager/InterventionImageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@
namespace SvImages\ImageManager;

use Intervention\Image\ImageManager;
use Psr\Container\ContainerInterface;
use SvImages\Options\ModuleOptions;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* @author Vytautas Stankus <[email protected]>
* @license MIT
*/
class InterventionImageManager implements FactoryInterface
class InterventionImageManager
{
/**
* Create ImageManager
*
* @param ServiceLocatorInterface $serviceLocator
* @param ContainerInterface $container
*
* @return ImageManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container)
{
/** @var ModuleOptions $options */
$options = $serviceLocator->get(ModuleOptions::class);
$options = $container->get(ModuleOptions::class);

return new ImageManager([
'driver' => $options->getDriver()
Expand Down
9 changes: 4 additions & 5 deletions src/Options/Factory/ModuleOptionsFactory.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?php
namespace SvImages\Options\Factory;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Psr\Container\ContainerInterface;
use SvImages\Options\ModuleOptions;

/**
* @author Vytautas Stankus <[email protected]>
* @license MIT
*/
class ModuleOptionsFactory implements FactoryInterface
class ModuleOptionsFactory
{
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container)
{
return new ModuleOptions($serviceLocator->get('Config')['sv_images']);
return new ModuleOptions($container->get('Config')['sv_images']);
}
}
30 changes: 5 additions & 25 deletions src/Router/Factory/RouteFactory.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
<?php
namespace SvImages\Router\Factory;

use Interop\Container\ContainerInterface;
use SvImages\Router\ImageRoute;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\MutableCreationOptionsInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\Factory\FactoryInterface;

/**
* @author Vytautas Stankus <[email protected]>
* @license MIT
*/
class RouteFactory implements FactoryInterface, MutableCreationOptionsInterface
class RouteFactory implements FactoryInterface
{
/**
* Options to use when creating an instance
*
* @var array
*/
protected $creationOptions = [];

public function createService(ServiceLocatorInterface $serviceLocator, $cName = null, $rName = null)
{
return new ImageRoute($this->creationOptions);
}

/**
* Set creation options
*
* @param array $options
*
* @return void
*/
public function setCreationOptions(array $options)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$this->creationOptions = $options;
return new ImageRoute($options);
}
}
4 changes: 2 additions & 2 deletions src/Router/ImageRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use SvImages\Exception\UnexpectedValueException;
use SvImages\Parser\Result;
use SvImages\Parser\UriParser;
use Zend\Mvc\Router\Http\RouteInterface;
use Zend\Router\Http\RouteInterface;
use Zend\Stdlib\RequestInterface as Request;
use Zend\Stdlib\ArrayUtils;
use Zend\Mvc\Router\Exception\InvalidArgumentException;
use Zend\Router\Exception\InvalidArgumentException;

/**
* @author Vytautas Stankus <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/Router/RouteMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace SvImages\Router;

use SvImages\Parser\Result;
use Zend\Mvc\Router\Http\RouteMatch as HttpRouteMatch;
use Zend\Router\Http\RouteMatch as HttpRouteMatch;

/**
* @author Vytautas Stankus <[email protected]>
Expand Down
16 changes: 7 additions & 9 deletions src/Service/Factory/CacheManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,36 @@

namespace SvImages\Service\Factory;

use SvImages\Cache\FlySystemStorage;
use Psr\Container\ContainerInterface;
use SvImages\Cache\StorageInterface;
use SvImages\Exception\InvalidArgumentException;
use SvImages\Options\ModuleOptions;
use SvImages\Service\CacheManager;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* @author Vytautas Stankus <[email protected]>
* @license MIT
*/
class CacheManagerFactory implements FactoryInterface
class CacheManagerFactory
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @param ContainerInterface $container
*
* @return CacheManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container)
{
/** @var ModuleOptions $options */
$options = $serviceLocator->get(ModuleOptions::class);
$options = $container->get(ModuleOptions::class);

if (!$serviceLocator->has($options->getCache())) {
if (!$container->has($options->getCache())) {
throw new InvalidArgumentException('Images cache storage is not set.');
}

/** @var StorageInterface $storage */
$storage = $serviceLocator->get($options->getCache());
$storage = $container->get($options->getCache());

return new CacheManager($storage);
}
Expand Down
17 changes: 8 additions & 9 deletions src/Service/Factory/ImageServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,40 @@

namespace SvImages\Service\Factory;

use Psr\Container\ContainerInterface;
use SvImages\Exception\InvalidArgumentException;
use SvImages\Filesystem\Filesystem;
use SvImages\Options\ModuleOptions;
use SvImages\Transformer\TransformersManager;
use SvImages\Service\ImageService;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* @author Vytautas Stankus <[email protected]>
* @license MIT
*/
class ImageServiceFactory implements FactoryInterface
class ImageServiceFactory
{
/**
* Create ImageService
*
* @param ServiceLocatorInterface $serviceLocator
* @param ContainerInterface $container
*
* @return ImageService
* @throws InvalidArgumentException
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container)
{
/** @var ModuleOptions $options */
$options = $serviceLocator->get(ModuleOptions::class);
$options = $container->get(ModuleOptions::class);

if (!$serviceLocator->has($options->getSource())) {
if (!$container->has($options->getSource())) {
throw new InvalidArgumentException('Images source filesystem is not set.');
}

/** @var Filesystem $filesystem */
$filesystem = $serviceLocator->get($options->getSource());
$filesystem = $container->get($options->getSource());
/** @var TransformersManager $transformersManager */
$transformersManager = $serviceLocator->get(TransformersManager::class);
$transformersManager = $container->get(TransformersManager::class);

return new ImageService($filesystem, $transformersManager);
}
Expand Down
10 changes: 4 additions & 6 deletions src/Transformer/Factory/CropTransformerFactory.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?php
namespace SvImages\Transformer\Factory;

use Psr\Container\ContainerInterface;
use SvImages\Transformer\Crop;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* @author Vytautas Stankus <[email protected]>
* @license MIT
*/
class CropTransformerFactory implements FactoryInterface
class CropTransformerFactory
{
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container)
{
$sm = $serviceLocator->getServiceLocator();
/** @var \Intervention\Image\ImageManager $manager */
$manager = $sm->get('SvImages\ImageManager\InterventionImageManager');
$manager = $container->get(\SvImages\ImageManager\InterventionImageManager::class);

return new Crop($manager);
}
Expand Down
10 changes: 4 additions & 6 deletions src/Transformer/Factory/FitTransformerFactory.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?php
namespace SvImages\Transformer\Factory;

use Psr\Container\ContainerInterface;
use SvImages\Transformer\Fit;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* @author Vytautas Stankus <[email protected]>
* @license MIT
*/
class FitTransformerFactory implements FactoryInterface
class FitTransformerFactory
{
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container)
{
$sm = $serviceLocator->getServiceLocator();
/** @var \Intervention\Image\ImageManager $manager */
$manager = $sm->get('SvImages\ImageManager\InterventionImageManager');
$manager = $container->get('SvImages\ImageManager\InterventionImageManager');

return new Fit($manager);
}
Expand Down
Loading