Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit b47e9a2

Browse files
authored
Merge pull request #335 from prolic/zf3
allow zf3
2 parents 4937bc4 + 4afa493 commit b47e9a2

File tree

68 files changed

+913
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+913
-294
lines changed

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
language: php
22

33
php:
4-
- 5.4
5-
- 5.5
64
- 5.6
5+
- 7
76
- hhvm
87

8+
env:
9+
matrix:
10+
- DEPENDENCIES=""
11+
- DEPENDENCIES="--prefer-lowest --prefer-stable"
12+
913
before_script:
1014
- composer self-update
11-
- composer update --prefer-source
15+
- composer update --prefer-dist $DEPENDENCIES
1216

1317
script:
1418
- ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml --exclude-group Functional

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ZfcRbac is an access control module for Zend Framework 2, based on the RBAC perm
1111

1212
## Requirements
1313

14-
- PHP 5.4 or higher
14+
- PHP 5.6, PHP 7.0 or higher
1515
- [Rbac component](https://github.com/zf-fr/rbac): this is actually a prototype for the ZF3 Rbac component.
1616
- [Zend Framework 2.2 or higher](http://www.github.com/zendframework/zf2)
1717

composer.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,27 @@
2727
}
2828
],
2929
"require": {
30-
"php": ">=5.4",
31-
"zendframework/zend-mvc": "~2.2",
32-
"zendframework/zend-servicemanager": "~2.2",
30+
"php": "~5.6 || ~7.0",
31+
"zendframework/zend-config": "~2.2",
32+
"zendframework/zend-eventmanager": "^2.6.3 || ^3.0",
33+
"zendframework/zend-mvc": "~2.7 || ^3.0",
34+
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
3335
"zfr/rbac": "~1.2"
3436
},
3537
"require-dev": {
36-
"zendframework/zendframework": "~2.2",
37-
"zendframework/zend-developer-tools": "dev-master",
38-
"phpunit/phpunit": "~3.7",
39-
"squizlabs/php_codesniffer": "1.4.*",
38+
"zendframework/zend-authentication": "~2.2",
39+
"zendframework/zend-developer-tools": "~1.1",
40+
"zendframework/zend-log": "~2.2",
41+
"zendframework/zend-http": "~2.2",
42+
"zendframework/zend-i18n": "~2.7.3",
43+
"zendframework/zend-serializer": "~2.2",
44+
"zendframework/zend-view": "~2.2",
45+
"phpunit/phpunit": "~4.8.26",
46+
"squizlabs/php_codesniffer": "2.6.*",
4047
"satooshi/php-coveralls": "~0.6",
4148
"doctrine/common": "~2.4",
42-
"doctrine/doctrine-module": "~0.8",
43-
"doctrine/doctrine-orm-module": "~0.8"
49+
"doctrine/doctrine-module": "~1.1",
50+
"doctrine/doctrine-orm-module": "^1.0"
4451
},
4552
"suggest": {
4653
"zendframework/zend-developer-tools": "if you want to show information about the roles",

config/module.config.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@
1818

1919
return [
2020
'service_manager' => [
21-
'invokables' => [
22-
'ZfcRbac\Collector\RbacCollector' => 'ZfcRbac\Collector\RbacCollector',
23-
],
24-
2521
'factories' => [
2622
/* Factories that do not map to a class */
2723
'ZfcRbac\Guards' => 'ZfcRbac\Factory\GuardsFactory',
2824

2925
/* Factories that map to a class */
3026
'Rbac\Rbac' => 'ZfcRbac\Factory\RbacFactory',
3127
'ZfcRbac\Assertion\AssertionPluginManager' => 'ZfcRbac\Factory\AssertionPluginManagerFactory',
28+
'ZfcRbac\Collector\RbacCollector' => \Zend\ServiceManager\Factory\InvokableFactory::class,
3229
'ZfcRbac\Guard\GuardPluginManager' => 'ZfcRbac\Factory\GuardPluginManagerFactory',
3330
'ZfcRbac\Identity\AuthenticationIdentityProvider' => 'ZfcRbac\Factory\AuthenticationIdentityProviderFactory',
3431
'ZfcRbac\Options\ModuleOptions' => 'ZfcRbac\Factory\ModuleOptionsFactory',

src/ZfcRbac/Assertion/AssertionPluginManager.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* Plugin manager to create assertions
26-
*
26+
*
2727
* @author Aeneas Rekkas
2828
* @license MIT
2929
*
@@ -34,7 +34,7 @@ class AssertionPluginManager extends AbstractPluginManager
3434
/**
3535
* {@inheritDoc}
3636
*/
37-
public function validatePlugin($plugin)
37+
public function validate($plugin)
3838
{
3939
if ($plugin instanceof AssertionInterface) {
4040
return; // we're okay
@@ -46,6 +46,14 @@ public function validatePlugin($plugin)
4646
));
4747
}
4848

49+
/**
50+
* {@inheritDoc}
51+
*/
52+
public function validatePlugin($plugin)
53+
{
54+
$this->validate($plugin);
55+
}
56+
4957
/**
5058
* {@inheritDoc}
5159
*/

src/ZfcRbac/Collector/RbacCollector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,5 @@ public function unserialize($serialized)
232232
$this->collectedRoles = $collection['roles'];
233233
$this->collectedPermissions = $collection['permissions'];
234234
$this->collectedOptions = $collection['options'];
235-
236235
}
237236
}

src/ZfcRbac/Factory/AssertionPluginManagerFactory.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,39 @@
1818

1919
namespace ZfcRbac\Factory;
2020

21+
use Interop\Container\ContainerInterface;
2122
use Zend\ServiceManager\Config;
2223
use Zend\ServiceManager\FactoryInterface;
2324
use Zend\ServiceManager\ServiceLocatorInterface;
2425
use ZfcRbac\Assertion\AssertionPluginManager;
2526

2627
/**
2728
* Factory to create a assertion plugin manager
28-
*
29+
*
2930
* @author Aeneas Rekkas
3031
* @license MIT
3132
*/
3233
class AssertionPluginManagerFactory implements FactoryInterface
3334
{
3435
/**
35-
* {@inheritDoc}
36+
* @param ContainerInterface $container
37+
* @param string $requestedName
38+
* @param array|null $options
3639
* @return AssertionPluginManager
3740
*/
38-
public function createService(ServiceLocatorInterface $serviceLocator)
41+
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
3942
{
40-
$config = $serviceLocator->get('Config')['zfc_rbac']['assertion_manager'];
43+
$config = $container->get('Config')['zfc_rbac']['assertion_manager'];
4144

42-
$pluginManager = new AssertionPluginManager(new Config($config));
43-
$pluginManager->setServiceLocator($serviceLocator);
45+
return new AssertionPluginManager($container, $config);
46+
}
4447

45-
return $pluginManager;
48+
/**
49+
* {@inheritDoc}
50+
* @return AssertionPluginManager
51+
*/
52+
public function createService(ServiceLocatorInterface $serviceLocator)
53+
{
54+
return $this($serviceLocator, AssertionPluginManager::class);
4655
}
4756
}

src/ZfcRbac/Factory/AuthenticationIdentityProviderFactory.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
namespace ZfcRbac\Factory;
2020

21+
use Interop\Container\ContainerInterface;
2122
use Zend\ServiceManager\FactoryInterface;
2223
use Zend\ServiceManager\ServiceLocatorInterface;
2324
use ZfcRbac\Identity\AuthenticationIdentityProvider;
@@ -31,14 +32,25 @@
3132
class AuthenticationIdentityProviderFactory implements FactoryInterface
3233
{
3334
/**
34-
* {@inheritDoc}
35+
* @param ContainerInterface $container
36+
* @param string $requestedName
37+
* @param array|null $options
3538
* @return AuthenticationIdentityProvider
3639
*/
37-
public function createService(ServiceLocatorInterface $serviceLocator)
40+
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
3841
{
3942
/* @var \Zend\Authentication\AuthenticationService $authenticationProvider */
40-
$authenticationProvider = $serviceLocator->get('Zend\Authentication\AuthenticationService');
43+
$authenticationProvider = $container->get('Zend\Authentication\AuthenticationService');
4144

4245
return new AuthenticationIdentityProvider($authenticationProvider);
4346
}
47+
48+
/**
49+
* {@inheritDoc}
50+
* @return AuthenticationIdentityProvider
51+
*/
52+
public function createService(ServiceLocatorInterface $serviceLocator)
53+
{
54+
return $this($serviceLocator, AuthenticationIdentityProvider::class);
55+
}
4456
}

src/ZfcRbac/Factory/AuthorizationServiceDelegatorFactory.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
namespace ZfcRbac\Factory;
2020

21+
use Interop\Container\ContainerInterface;
2122
use Zend\ServiceManager\AbstractPluginManager;
2223
use Zend\ServiceManager\DelegatorFactoryInterface;
2324
use Zend\ServiceManager\ServiceLocatorInterface;
@@ -32,21 +33,40 @@
3233
*/
3334
class AuthorizationServiceDelegatorFactory implements DelegatorFactoryInterface
3435
{
35-
public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback)
36+
/**
37+
* @param ContainerInterface $container
38+
* @param string $name
39+
* @param callable $callback
40+
* @param array|null $options
41+
* @return mixed
42+
*/
43+
public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
3644
{
3745
$instanceToDecorate = call_user_func($callback);
3846

3947
if (!$instanceToDecorate instanceof AuthorizationServiceAwareInterface) {
40-
throw new RuntimeException("The service $requestedName must implement AuthorizationServiceAwareInterface.");
48+
throw new RuntimeException("The service $name must implement AuthorizationServiceAwareInterface.");
4149
}
4250

43-
if ($serviceLocator instanceof AbstractPluginManager) {
44-
$serviceLocator = $serviceLocator->getServiceLocator();
51+
if ($container instanceof AbstractPluginManager) {
52+
$container = $container->getServiceLocator();
4553
}
4654

47-
$authorizationService = $serviceLocator->get('ZfcRbac\Service\AuthorizationService');
55+
$authorizationService = $container->get('ZfcRbac\Service\AuthorizationService');
4856
$instanceToDecorate->setAuthorizationService($authorizationService);
4957

5058
return $instanceToDecorate;
5159
}
60+
61+
/**
62+
* @param ServiceLocatorInterface $serviceLocator
63+
* @param string $name
64+
* @param string $requestedName
65+
* @param callable $callback
66+
* @return mixed
67+
*/
68+
public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback)
69+
{
70+
return $this($serviceLocator, $requestedName, $callback);
71+
}
5272
}

src/ZfcRbac/Factory/AuthorizationServiceFactory.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
namespace ZfcRbac\Factory;
2020

21+
use Interop\Container\ContainerInterface;
2122
use Zend\ServiceManager\FactoryInterface;
2223
use Zend\ServiceManager\ServiceLocatorInterface;
2324
use ZfcRbac\Service\AuthorizationService;
@@ -31,26 +32,37 @@
3132
class AuthorizationServiceFactory implements FactoryInterface
3233
{
3334
/**
34-
* {@inheritDoc}
35+
* @param ContainerInterface $container
36+
* @param string $requestedName
37+
* @param array|null $options
3538
* @return AuthorizationService
3639
*/
37-
public function createService(ServiceLocatorInterface $serviceLocator)
40+
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
3841
{
3942
/* @var \Rbac\Rbac $rbac */
40-
$rbac = $serviceLocator->get('Rbac\Rbac');
43+
$rbac = $container->get('Rbac\Rbac');
4144

4245
/* @var \ZfcRbac\Service\RoleService $roleService */
43-
$roleService = $serviceLocator->get('ZfcRbac\Service\RoleService');
46+
$roleService = $container->get('ZfcRbac\Service\RoleService');
4447

4548
/* @var \ZfcRbac\Assertion\AssertionPluginManager $assertionPluginManager */
46-
$assertionPluginManager = $serviceLocator->get('ZfcRbac\Assertion\AssertionPluginManager');
49+
$assertionPluginManager = $container->get('ZfcRbac\Assertion\AssertionPluginManager');
4750

4851
/* @var \ZfcRbac\Options\ModuleOptions $moduleOptions */
49-
$moduleOptions = $serviceLocator->get('ZfcRbac\Options\ModuleOptions');
52+
$moduleOptions = $container->get('ZfcRbac\Options\ModuleOptions');
5053

5154
$authorizationService = new AuthorizationService($rbac, $roleService, $assertionPluginManager);
5255
$authorizationService->setAssertions($moduleOptions->getAssertionMap());
5356

5457
return $authorizationService;
5558
}
59+
60+
/**
61+
* {@inheritDoc}
62+
* @return AuthorizationService
63+
*/
64+
public function createService(ServiceLocatorInterface $serviceLocator)
65+
{
66+
return $this($serviceLocator, AuthorizationService::class);
67+
}
5668
}

0 commit comments

Comments
 (0)