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

allow zf3 #335

Merged
merged 31 commits into from
Aug 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c359ffe
allow zf3
prolic Jun 23, 2016
673874f
build on travis with zf2 & zf3. drop support php < 5.6
prolic Jun 24, 2016
aefc37f
fix typo in composer json
prolic Jun 24, 2016
ef117e1
other composer json formatting for or (||)
prolic Jun 24, 2016
d678102
update composer deps
prolic Jul 8, 2016
6a0b20a
update to work with ZF3
prolic Jul 8, 2016
a07ee7d
require newer versions of zf2/3
prolic Jul 8, 2016
a5ea04f
allow zf2 and zf3
prolic Jul 8, 2016
ad351c9
fix zf3 usage
prolic Jul 8, 2016
5f55b6c
fix usage with zf2
prolic Jul 8, 2016
3327195
enable switch for zf3 in tests
prolic Jul 8, 2016
1491665
allow zend-mvc 3.0
prolic Jul 8, 2016
52b2b23
php cs issues
prolic Jul 8, 2016
66b84db
update code sniffer
prolic Jul 8, 2016
aab9b71
update ZfcRbacTest/Util/ServiceManagerFactory
prolic Jul 8, 2016
191b454
update tests and srcs
prolic Jul 15, 2016
feb4aba
add v3 service manager tests
prolic Jul 15, 2016
03fca8e
remove test group
prolic Jul 15, 2016
2d856b8
apply php cs fixes
prolic Jul 15, 2016
284ba81
some last cleanups
prolic Jul 15, 2016
7894392
update doctrine orm module in composer json
prolic Jul 15, 2016
4dc3eb0
update AuthorizationServiceInitializer
prolic Jul 15, 2016
9e97ce3
Fixes #340 - EventManager::trigger() causes an event instance of the …
Jul 22, 2016
1c8dc25
make test modifications related to #340, zf2- and zf3-compatible
Jul 25, 2016
66466fc
Merge pull request #1 from nasko/zf3
prolic Jul 25, 2016
079e135
Revert "Fix for #340"
prolic Jul 25, 2016
c895f5f
Merge pull request #2 from prolic/revert-1-zf3
prolic Jul 25, 2016
f7e401a
switch triggerEvent/trigger methods depending on zf2/zf3
prolic Jul 25, 2016
4b970dd
update code again to be 100% backward compatible with zf2 components
prolic Jul 30, 2016
2b1ecb0
run all tests with zf3
prolic Jul 14, 2016
4afa493
fix route permissions guard factory
prolic Aug 11, 2016
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
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
language: php

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

env:
matrix:
- DEPENDENCIES=""
- DEPENDENCIES="--prefer-lowest --prefer-stable"

before_script:
- composer self-update
- composer update --prefer-source
- composer update --prefer-dist $DEPENDENCIES

script:
- ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml --exclude-group Functional
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ZfcRbac is an access control module for Zend Framework 2, based on the RBAC perm

## Requirements

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

Expand Down
25 changes: 16 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,27 @@
}
],
"require": {
"php": ">=5.4",
"zendframework/zend-mvc": "~2.2",
"zendframework/zend-servicemanager": "~2.2",
"php": "~5.6 || ~7.0",
"zendframework/zend-config": "~2.2",
"zendframework/zend-eventmanager": "^2.6.3 || ^3.0",
"zendframework/zend-mvc": "~2.7 || ^3.0",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
"zfr/rbac": "~1.2"
},
"require-dev": {
"zendframework/zendframework": "~2.2",
"zendframework/zend-developer-tools": "dev-master",
"phpunit/phpunit": "~3.7",
"squizlabs/php_codesniffer": "1.4.*",
"zendframework/zend-authentication": "~2.2",
"zendframework/zend-developer-tools": "~1.1",
"zendframework/zend-log": "~2.2",
"zendframework/zend-http": "~2.2",
"zendframework/zend-i18n": "~2.7.3",
"zendframework/zend-serializer": "~2.2",
"zendframework/zend-view": "~2.2",
"phpunit/phpunit": "~4.8.26",
"squizlabs/php_codesniffer": "2.6.*",
"satooshi/php-coveralls": "~0.6",
"doctrine/common": "~2.4",
"doctrine/doctrine-module": "~0.8",
"doctrine/doctrine-orm-module": "~0.8"
"doctrine/doctrine-module": "~1.1",
"doctrine/doctrine-orm-module": "^1.0"
},
"suggest": {
"zendframework/zend-developer-tools": "if you want to show information about the roles",
Expand Down
5 changes: 1 addition & 4 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@

return [
'service_manager' => [
'invokables' => [
'ZfcRbac\Collector\RbacCollector' => 'ZfcRbac\Collector\RbacCollector',
],

'factories' => [
/* Factories that do not map to a class */
'ZfcRbac\Guards' => 'ZfcRbac\Factory\GuardsFactory',

/* Factories that map to a class */
'Rbac\Rbac' => 'ZfcRbac\Factory\RbacFactory',
'ZfcRbac\Assertion\AssertionPluginManager' => 'ZfcRbac\Factory\AssertionPluginManagerFactory',
'ZfcRbac\Collector\RbacCollector' => \Zend\ServiceManager\Factory\InvokableFactory::class,
'ZfcRbac\Guard\GuardPluginManager' => 'ZfcRbac\Factory\GuardPluginManagerFactory',
'ZfcRbac\Identity\AuthenticationIdentityProvider' => 'ZfcRbac\Factory\AuthenticationIdentityProviderFactory',
'ZfcRbac\Options\ModuleOptions' => 'ZfcRbac\Factory\ModuleOptionsFactory',
Expand Down
12 changes: 10 additions & 2 deletions src/ZfcRbac/Assertion/AssertionPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
* Plugin manager to create assertions
*
*
* @author Aeneas Rekkas
* @license MIT
*
Expand All @@ -34,7 +34,7 @@ class AssertionPluginManager extends AbstractPluginManager
/**
* {@inheritDoc}
*/
public function validatePlugin($plugin)
public function validate($plugin)
{
if ($plugin instanceof AssertionInterface) {
return; // we're okay
Expand All @@ -46,6 +46,14 @@ public function validatePlugin($plugin)
));
}

/**
* {@inheritDoc}
*/
public function validatePlugin($plugin)
{
$this->validate($plugin);
}

/**
* {@inheritDoc}
*/
Expand Down
1 change: 0 additions & 1 deletion src/ZfcRbac/Collector/RbacCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,5 @@ public function unserialize($serialized)
$this->collectedRoles = $collection['roles'];
$this->collectedPermissions = $collection['permissions'];
$this->collectedOptions = $collection['options'];

}
}
23 changes: 16 additions & 7 deletions src/ZfcRbac/Factory/AssertionPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,39 @@

namespace ZfcRbac\Factory;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcRbac\Assertion\AssertionPluginManager;

/**
* Factory to create a assertion plugin manager
*
*
* @author Aeneas Rekkas
* @license MIT
*/
class AssertionPluginManagerFactory implements FactoryInterface
{
/**
* {@inheritDoc}
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return AssertionPluginManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $serviceLocator->get('Config')['zfc_rbac']['assertion_manager'];
$config = $container->get('Config')['zfc_rbac']['assertion_manager'];

$pluginManager = new AssertionPluginManager(new Config($config));
$pluginManager->setServiceLocator($serviceLocator);
return new AssertionPluginManager($container, $config);
}

return $pluginManager;
/**
* {@inheritDoc}
* @return AssertionPluginManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, AssertionPluginManager::class);
}
}
18 changes: 15 additions & 3 deletions src/ZfcRbac/Factory/AuthenticationIdentityProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace ZfcRbac\Factory;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcRbac\Identity\AuthenticationIdentityProvider;
Expand All @@ -31,14 +32,25 @@
class AuthenticationIdentityProviderFactory implements FactoryInterface
{
/**
* {@inheritDoc}
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return AuthenticationIdentityProvider
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/* @var \Zend\Authentication\AuthenticationService $authenticationProvider */
$authenticationProvider = $serviceLocator->get('Zend\Authentication\AuthenticationService');
$authenticationProvider = $container->get('Zend\Authentication\AuthenticationService');

return new AuthenticationIdentityProvider($authenticationProvider);
}

/**
* {@inheritDoc}
* @return AuthenticationIdentityProvider
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, AuthenticationIdentityProvider::class);
}
}
30 changes: 25 additions & 5 deletions src/ZfcRbac/Factory/AuthorizationServiceDelegatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace ZfcRbac\Factory;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\DelegatorFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
Expand All @@ -32,21 +33,40 @@
*/
class AuthorizationServiceDelegatorFactory implements DelegatorFactoryInterface
{
public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback)
/**
* @param ContainerInterface $container
* @param string $name
* @param callable $callback
* @param array|null $options
* @return mixed
*/
public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
{
$instanceToDecorate = call_user_func($callback);

if (!$instanceToDecorate instanceof AuthorizationServiceAwareInterface) {
throw new RuntimeException("The service $requestedName must implement AuthorizationServiceAwareInterface.");
throw new RuntimeException("The service $name must implement AuthorizationServiceAwareInterface.");
}

if ($serviceLocator instanceof AbstractPluginManager) {
$serviceLocator = $serviceLocator->getServiceLocator();
if ($container instanceof AbstractPluginManager) {
$container = $container->getServiceLocator();
}

$authorizationService = $serviceLocator->get('ZfcRbac\Service\AuthorizationService');
$authorizationService = $container->get('ZfcRbac\Service\AuthorizationService');
$instanceToDecorate->setAuthorizationService($authorizationService);

return $instanceToDecorate;
}

/**
* @param ServiceLocatorInterface $serviceLocator
* @param string $name
* @param string $requestedName
* @param callable $callback
* @return mixed
*/
public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback)
{
return $this($serviceLocator, $requestedName, $callback);
}
}
24 changes: 18 additions & 6 deletions src/ZfcRbac/Factory/AuthorizationServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace ZfcRbac\Factory;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcRbac\Service\AuthorizationService;
Expand All @@ -31,26 +32,37 @@
class AuthorizationServiceFactory implements FactoryInterface
{
/**
* {@inheritDoc}
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return AuthorizationService
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/* @var \Rbac\Rbac $rbac */
$rbac = $serviceLocator->get('Rbac\Rbac');
$rbac = $container->get('Rbac\Rbac');

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

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

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

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

return $authorizationService;
}

/**
* {@inheritDoc}
* @return AuthorizationService
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, AuthorizationService::class);
}
}
38 changes: 30 additions & 8 deletions src/ZfcRbac/Factory/ControllerGuardFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

namespace ZfcRbac\Factory;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\MutableCreationOptionsInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcRbac\Guard\ControllerGuard;

Expand All @@ -29,13 +29,21 @@
* @author Michaël Gallego <mic.gallego@gmail.com>
* @license MIT
*/
class ControllerGuardFactory implements FactoryInterface, MutableCreationOptionsInterface
class ControllerGuardFactory implements FactoryInterface
Copy link
Contributor

@svycka svycka Jul 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing MutableCreationOptionsInterface please look how servicemanager v2 keep compatibility: https://github.com/zendframework/zend-servicemanager/blob/release-2.7/src/AbstractPluginManager.php#L322-L328

basically instead of MutableCreationOptionsInterface it checks for setCreationOptions() not sure it works without it. Possible BC break unless this is handled somewhere else, but don't know if this is good idea.

can find more info here zendframework/zend-servicemanager#91 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll re-check that tomorrow

{
/**
* @var array
*/
protected $options = [];

/**
* {@inheritDoc}
*/
public function __construct(array $options = [])
{
$this->setCreationOptions($options);
}

/**
* {@inheritDoc}
*/
Expand All @@ -45,22 +53,36 @@ public function setCreationOptions(array $options)
}

/**
* {@inheritDoc}
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return ControllerGuard
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$parentLocator = $serviceLocator->getServiceLocator();
if (null === $options) {
$options = [];
}

/* @var \ZfcRbac\Options\ModuleOptions $moduleOptions */
$moduleOptions = $parentLocator->get('ZfcRbac\Options\ModuleOptions');
$moduleOptions = $container->get('ZfcRbac\Options\ModuleOptions');

/* @var \ZfcRbac\Service\RoleService $roleService */
$roleService = $parentLocator->get('ZfcRbac\Service\RoleService');
$roleService = $container->get('ZfcRbac\Service\RoleService');

$controllerGuard = new ControllerGuard($roleService, $this->options);
$controllerGuard = new ControllerGuard($roleService, $options);
$controllerGuard->setProtectionPolicy($moduleOptions->getProtectionPolicy());

return $controllerGuard;
}


/**
* {@inheritDoc}
* @return ControllerGuard
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator->getServiceLocator(), ControllerGuard::class, $this->options);
}
}
Loading