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

Commit

Permalink
Merge pull request #335 from prolic/zf3
Browse files Browse the repository at this point in the history
allow zf3
  • Loading branch information
danizord authored Aug 11, 2016
2 parents 4937bc4 + 4afa493 commit b47e9a2
Show file tree
Hide file tree
Showing 68 changed files with 913 additions and 294 deletions.
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 <[email protected]>
* @license MIT
*/
class ControllerGuardFactory implements FactoryInterface, MutableCreationOptionsInterface
class ControllerGuardFactory implements FactoryInterface
{
/**
* @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

0 comments on commit b47e9a2

Please sign in to comment.