Skip to content

Commit

Permalink
Merge pull request #37 from svycka/improvement/servicemanager-v3-and-…
Browse files Browse the repository at this point in the history
…eventmanager-v3-support

Added ServiceManager v3 and EventManager v3 support
  • Loading branch information
bakura10 authored Jul 8, 2016
2 parents 37ddd30 + 20b8cd0 commit 5f1c75b
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 38 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
language: php

php:
- 5.3.3
- 5.3
- 5.4
- 5.5
- 5.6
- 7
- hhvm

matrix:
allow_failures:
- php: hhvm

before_script:
- composer self-update
Expand Down
19 changes: 12 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@
}
],
"require": {
"php": ">=5.3.3",
"zendframework/zend-eventmanager": "~2.2",
"zendframework/zend-http": "~2.2",
"zendframework/zend-mvc": "~2.2",
"zendframework/zend-servicemanager": "~2.2"
"php": "^5.5 || ^7.0",
"zendframework/zend-eventmanager": "^2.6 || ^3.0",
"zendframework/zend-http": "^2.5.2",
"zendframework/zend-mvc": "^2.5.2",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3"
},
"require-dev": {
"zendframework/zendframework": "~2.2",
"phpunit/phpunit": "~3.7",
"zendframework/zend-modulemanager": "^2.6.1",
"zendframework/zend-config": "^2.6",
"zendframework/zend-view": "^2.5.2",
"zendframework/zend-serializer": "^2.6",
"zendframework/zend-log": "^2.5.2",
"zendframework/zend-i18n": "^2.6",
"phpunit/phpunit": "^4.8",
"squizlabs/php_codesniffer": "1.4.*",
"satooshi/php-coveralls": "~0.6"
},
Expand Down
11 changes: 6 additions & 5 deletions src/ZfrCors/Factory/CorsOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

namespace ZfrCors\Factory;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Interop\Container\ContainerInterface;
use ZfrCors\Options\CorsOptions;

/**
Expand All @@ -28,15 +27,17 @@
* @license MIT
* @author Florent Blaison <[email protected]>
*/
class CorsOptionsFactory implements FactoryInterface
class CorsOptionsFactory
{
/**
* {@inheritDoc}
*
* @return CorsOptions
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, $options = null)
{
/* @var $config array */
$config = $serviceLocator->get('Config');
$config = $container->get('Config');

return new CorsOptions($config['zfr_cors']);
}
Expand Down
10 changes: 5 additions & 5 deletions src/ZfrCors/Factory/CorsRequestListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

namespace ZfrCors\Factory;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Interop\Container\ContainerInterface;
use ZfrCors\Mvc\CorsRequestListener;
use ZfrCors\Service\CorsService;

Expand All @@ -29,16 +28,17 @@
* @license MIT
* @author Florent Blaison <[email protected]>
*/
class CorsRequestListenerFactory implements FactoryInterface
class CorsRequestListenerFactory
{
/**
* {@inheritDoc}
*
* @return CorsRequestListener
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, $options = null)
{
/* @var $corsService CorsService */
$corsService = $serviceLocator->get('ZfrCors\Service\CorsService');
$corsService = $container->get('ZfrCors\Service\CorsService');

return new CorsRequestListener($corsService);
}
Expand Down
10 changes: 5 additions & 5 deletions src/ZfrCors/Factory/CorsServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

namespace ZfrCors\Factory;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Interop\Container\ContainerInterface;
use ZfrCors\Options\CorsOptions;
use ZfrCors\Service\CorsService;

Expand All @@ -29,16 +28,17 @@
* @license MIT
* @author Florent Blaison <[email protected]>
*/
class CorsServiceFactory implements FactoryInterface
class CorsServiceFactory
{
/**
* {@inheritDoc}
*
* @return CorsService
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, $options = null)
{
/* @var $corsOptions CorsOptions */
$corsOptions = $serviceLocator->get('ZfrCors\Options\CorsOptions');
$corsOptions = $container->get('ZfrCors\Options\CorsOptions');

return new CorsService($corsOptions);
}
Expand Down
4 changes: 3 additions & 1 deletion src/ZfrCors/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public function onBootstrap(EventInterface $event)
$serviceManager = $application->getServiceManager();
$eventManager = $application->getEventManager();

$eventManager->attach($serviceManager->get('ZfrCors\Mvc\CorsRequestListener'));
/** @var \ZfrCors\Mvc\CorsRequestListener $listener */
$listener = $serviceManager->get('ZfrCors\Mvc\CorsRequestListener');
$listener->attach($eventManager);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ZfrCors/Mvc/CorsRequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(CorsService $corsService)
/**
* {@inheritDoc}
*/
public function attach(EventManagerInterface $events)
public function attach(EventManagerInterface $events, $priority = 1)
{
// Preflight can be handled during the route event, and should return early
$this->listeners[] = $events->attach(MvcEvent::EVENT_ROUTE, array($this, 'onCorsPreflight'), -1);
Expand Down
1 change: 0 additions & 1 deletion tests/ZfrCorsTest/Factory/CorsOptionsFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
namespace ZfrCorsTest\Factory;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\ServiceManager\ServiceManager;
use ZfrCorsTest\Util\ServiceManagerFactory;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
namespace ZfrCorsTest\Factory;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\ServiceManager\ServiceManager;
use ZfrCorsTest\Util\ServiceManagerFactory;

/**
Expand Down
1 change: 0 additions & 1 deletion tests/ZfrCorsTest/Factory/CorsServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
namespace ZfrCorsTest\Factory;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\ServiceManager\ServiceManager;
use ZfrCorsTest\Util\ServiceManagerFactory;

/**
Expand Down
5 changes: 1 addition & 4 deletions tests/ZfrCorsTest/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
namespace ZfrCorsTest;

use PHPUnit_Framework_TestCase;
use Zend\Mvc\Application;
use Zend\Mvc\MvcEvent;
use Zend\ServiceManager\ServiceManager;
use ZfrCors\Module;

/**
Expand Down Expand Up @@ -66,7 +63,7 @@ public function testAssertListenerIsCorrectlyRegistered()
->with('ZfrCors\Mvc\CorsRequestListener')
->will($this->returnValue($corsListener));

$eventManager->expects($this->once())->method('attach')->with($corsListener);
$corsListener->expects($this->once())->method('attach')->with($eventManager);

$module->onBootstrap($mvcEvent);
}
Expand Down
9 changes: 5 additions & 4 deletions tests/ZfrCorsTest/Util/ServiceManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ public static function getApplicationConfig()
public static function getServiceManager(array $config = null)
{
$config = $config ?: static::getApplicationConfig();
$serviceManager = new ServiceManager(
new ServiceManagerConfig(
isset($config['service_manager']) ? $config['service_manager'] : array()
)
$serviceManager = new ServiceManager();
$serviceManagerConfig = new ServiceManagerConfig(
isset($config['service_manager']) ? $config['service_manager'] : array()
);
$serviceManagerConfig->configureServiceManager($serviceManager);

$serviceManager->setService('ApplicationConfig', $config);

/* @var $moduleManager \Zend\ModuleManager\ModuleManagerInterface */
Expand Down

0 comments on commit 5f1c75b

Please sign in to comment.