Skip to content

Commit

Permalink
Removing a lot of deprecated calls - mostly in Factories.
Browse files Browse the repository at this point in the history
  • Loading branch information
rarog committed Jul 24, 2020
1 parent a10dfa4 commit 1d296a0
Show file tree
Hide file tree
Showing 55 changed files with 474 additions and 4,430 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"laminas/laminas-console": "^2.8",
"laminas/laminas-db": "^2.5",
"doctrine/common": "^2.10",
"laminas/laminas-developer-tools": "^1.2.3"
"laminas/laminas-developer-tools": "^2.0",
"laminas-commons/lmc-user" : "^3.1"
},
"suggests": {
"laminas/laminas-developer-tools": "if you need to see current authorization details while developing",
Expand Down
3,838 changes: 0 additions & 3,838 deletions composer.lock

This file was deleted.

68 changes: 31 additions & 37 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace BjyAuthorize;

return [
'bjyauthorize' => [
// default role for unauthenticated users
Expand Down Expand Up @@ -52,65 +54,57 @@
// Key used by the cache for caching the acl
'cache_key' => 'bjyauthorize_acl'
],

'service_manager' => [
'factories' => [
'BjyAuthorize\Cache' => 'BjyAuthorize\Service\CacheFactory',
'BjyAuthorize\CacheKeyGenerator' => 'BjyAuthorize\Service\CacheKeyGeneratorFactory',
'BjyAuthorize\Config' => 'BjyAuthorize\Service\ConfigServiceFactory',
'BjyAuthorize\Guards' => 'BjyAuthorize\Service\GuardsServiceFactory',
'BjyAuthorize\RoleProviders' => 'BjyAuthorize\Service\RoleProvidersServiceFactory',
'BjyAuthorize\ResourceProviders' => 'BjyAuthorize\Service\ResourceProvidersServiceFactory',
'BjyAuthorize\RuleProviders' => 'BjyAuthorize\Service\RuleProvidersServiceFactory',
'BjyAuthorize\Guard\Controller' => 'BjyAuthorize\Service\ControllerGuardServiceFactory',
'BjyAuthorize\Guard\Route' => 'BjyAuthorize\Service\RouteGuardServiceFactory',
'BjyAuthorize\Provider\Role\Config' => 'BjyAuthorize\Service\ConfigRoleProviderServiceFactory',
'BjyAuthorize\Provider\Role\LaminasDb' => 'BjyAuthorize\Service\LaminasDbRoleProviderServiceFactory',
'BjyAuthorize\Provider\Rule\Config' => 'BjyAuthorize\Service\ConfigRuleProviderServiceFactory',
'BjyAuthorize\Provider\Resource\Config' => 'BjyAuthorize\Service\ConfigResourceProviderServiceFactory',
'BjyAuthorize\Service\Authorize' => 'BjyAuthorize\Service\AuthorizeFactory',
'BjyAuthorize\Provider\Identity\ProviderInterface'
=> 'BjyAuthorize\Service\IdentityProviderServiceFactory',
'BjyAuthorize\Provider\Identity\AuthenticationIdentityProvider'
=> 'BjyAuthorize\Service\AuthenticationIdentityProviderServiceFactory',
'BjyAuthorize\Provider\Role\ObjectRepositoryProvider'
=> 'BjyAuthorize\Service\ObjectRepositoryRoleProviderFactory',
'BjyAuthorize\Collector\RoleCollector' => 'BjyAuthorize\Service\RoleCollectorServiceFactory',
'BjyAuthorize\Provider\Identity\LmcUserLaminasDb'
=> 'BjyAuthorize\Service\LmcUserLaminasDbIdentityProviderServiceFactory',
'BjyAuthorize\View\UnauthorizedStrategy'
=> 'BjyAuthorize\Service\UnauthorizedStrategyServiceFactory',
'BjyAuthorize\Service\RoleDbTableGateway' => 'BjyAuthorize\Service\UserRoleServiceFactory',
'BjyAuthorize\Cache' => Service\CacheFactory::class,
'BjyAuthorize\CacheKeyGenerator' => Service\CacheKeyGeneratorFactory::class,
'BjyAuthorize\Config' => Service\ConfigServiceFactory::class,
'BjyAuthorize\Guards' => Service\GuardsServiceFactory::class,
'BjyAuthorize\RoleProviders' => Service\RoleProvidersServiceFactory::class,
'BjyAuthorize\ResourceProviders' => Service\ResourceProvidersServiceFactory::class,
'BjyAuthorize\RuleProviders' => Service\RuleProvidersServiceFactory::class,
'BjyAuthorize\Service\RoleDbTableGateway' => Service\UserRoleServiceFactory::class,
Collector\RoleCollector::class => Service\RoleCollectorServiceFactory::class,
Guard\Controller::class => Service\ControllerGuardServiceFactory::class,
Guard\Route::class => Service\RouteGuardServiceFactory::class,
Provider\Identity\AuthenticationIdentityProvider::class
=> Service\AuthenticationIdentityProviderServiceFactory::class,
Provider\Identity\LmcUserLaminasDb::class => Service\LmcUserLaminasDbIdentityProviderServiceFactory::class,
Provider\Identity\ProviderInterface::class => Service\IdentityProviderServiceFactory::class,
Provider\Resource\Config::class => Service\ConfigResourceProviderServiceFactory::class,
Provider\Role\Config::class => Service\ConfigRoleProviderServiceFactory::class,
Provider\Role\LaminasDb::class => Service\LaminasDbRoleProviderServiceFactory::class,
Provider\Role\ObjectRepositoryProvider::class => Service\ObjectRepositoryRoleProviderFactory::class,
Provider\Rule\Config::class => Service\ConfigRuleProviderServiceFactory::class,
Service\Authorize::class => Service\AuthorizeFactory::class,
View\UnauthorizedStrategy::class => Service\UnauthorizedStrategyServiceFactory::class,
],
'invokables' => [
'BjyAuthorize\View\RedirectionStrategy' => 'BjyAuthorize\View\RedirectionStrategy',
View\RedirectionStrategy::class,
],
'aliases' => [
'bjyauthorize_zend_db_adapter' => 'Laminas\Db\Adapter\Adapter',
'bjyauthorize_zend_db_adapter' => \Laminas\Db\Adapter\Adapter::class,
],
'initializers' => [
'BjyAuthorize\Service\AuthorizeAwareServiceInitializer'
=> 'BjyAuthorize\Service\AuthorizeAwareServiceInitializer'
Service\AuthorizeAwareServiceInitializer::class
],
],

'view_manager' => [
'template_map' => [
'error/403' => __DIR__ . '/../view/error/403.phtml',
'zend-developer-tools/toolbar/bjy-authorize-role'
=> __DIR__ . '/../view/zend-developer-tools/toolbar/bjy-authorize-role.phtml',
'laminas-developer-tools/toolbar/bjy-authorize-role'
=> __DIR__ . '/../view/laminas-developer-tools/toolbar/bjy-authorize-role.phtml',
],
],

'zenddevelopertools' => [
'laminas-developer-tools' => [
'profiler' => [
'collectors' => [
'bjy_authorize_role_collector' => 'BjyAuthorize\\Collector\\RoleCollector',
],
],
'toolbar' => [
'entries' => [
'bjy_authorize_role_collector' => 'zend-developer-tools/toolbar/bjy-authorize-role',
'bjy_authorize_role_collector' => 'laminas-developer-tools/toolbar/bjy-authorize-role',
],
],
],
Expand Down
4 changes: 2 additions & 2 deletions src/BjyAuthorize/Collector/RoleCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
namespace BjyAuthorize\Collector;

use BjyAuthorize\Provider\Identity\ProviderInterface;
use Serializable;
use Laminas\DeveloperTools\Collector\CollectorInterface;
use Laminas\Mvc\MvcEvent;
use Laminas\Permissions\Acl\Role\RoleInterface;
use ZendDeveloperTools\Collector\CollectorInterface;
use Serializable;

/**
* Role collector - collects the role during dispatch
Expand Down
3 changes: 2 additions & 1 deletion src/BjyAuthorize/Controller/Plugin/IsAllowedFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace BjyAuthorize\Controller\Plugin;

use BjyAuthorize\Service\Authorize;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\AbstractPluginManager;
use Laminas\ServiceManager\FactoryInterface;
Expand All @@ -27,7 +28,7 @@ public function createService(ServiceLocatorInterface $serviceLocator)
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$authorize = $container->get('BjyAuthorize\Service\Authorize');
$authorize = $container->get(Authorize::class);

return new IsAllowed($authorize);
}
Expand Down
8 changes: 4 additions & 4 deletions src/BjyAuthorize/Guard/AbstractGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class AbstractGuard extends AbstractListenerAggregate implements
/**
* @var ContainerInterface
*/
protected $serviceLocator;
protected $container;

/**
* @var array[]
Expand All @@ -32,11 +32,11 @@ abstract class AbstractGuard extends AbstractListenerAggregate implements
/**
*
* @param array $rules
* @param ContainerInterface $serviceLocator
* @param ContainerInterface $container
*/
public function __construct(array $rules, ContainerInterface $serviceLocator)
public function __construct(array $rules, ContainerInterface $container)
{
$this->serviceLocator = $serviceLocator;
$this->container = $container;

foreach ($rules as $rule) {
$rule['roles'] = (array)$rule['roles'];
Expand Down
3 changes: 2 additions & 1 deletion src/BjyAuthorize/Guard/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace BjyAuthorize\Guard;

use BjyAuthorize\Exception\UnAuthorizedException;
use BjyAuthorize\Service\Authorize;
use Laminas\Console\Request as ConsoleRequest;
use Laminas\EventManager\EventManagerInterface;
use Laminas\Http\Request as HttpRequest;
Expand Down Expand Up @@ -77,7 +78,7 @@ public function getResourceName($controller, $action = null)
public function onDispatch(MvcEvent $event)
{
/* @var $service \BjyAuthorize\Service\Authorize */
$service = $this->serviceLocator->get('BjyAuthorize\Service\Authorize');
$service = $this->container->get(Authorize::class);
$match = $event->getRouteMatch();
$controller = $match->getParam('controller');
$action = $match->getParam('action');
Expand Down
3 changes: 2 additions & 1 deletion src/BjyAuthorize/Guard/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace BjyAuthorize\Guard;

use BjyAuthorize\Exception\UnAuthorizedException;
use BjyAuthorize\Service\Authorize;
use Laminas\Console\Request as ConsoleRequest;
use Laminas\EventManager\EventManagerInterface;
use Laminas\Mvc\MvcEvent;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function attach(EventManagerInterface $events, $priority = 1)
public function onRoute(MvcEvent $event)
{
/* @var $service \BjyAuthorize\Service\Authorize */
$service = $this->serviceLocator->get('BjyAuthorize\Service\Authorize');
$service = $this->container->get(Authorize::class);
$match = $event->getRouteMatch();
$routeName = $match->getMatchedRouteName();

Expand Down
8 changes: 4 additions & 4 deletions src/BjyAuthorize/Provider/Role/ObjectRepositoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@

use BjyAuthorize\Acl\HierarchicalRoleInterface;
use BjyAuthorize\Acl\Role;
use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\Persistence\ObjectRepository;
use Laminas\Permissions\Acl\Role\RoleInterface;

/**
* Role provider based on a {@see \Doctrine\Common\Persistence\ObjectRepository}
* Role provider based on a {@see \Doctrine\Persistence\ObjectRepository}
*
* @author Tom Oram <[email protected]>
*/
class ObjectRepositoryProvider implements ProviderInterface
{
/**
* @var \Doctrine\Common\Persistence\ObjectRepository
* @var \Doctrine\Persistence\ObjectRepository
*/
protected $objectRepository;

/**
* @param \Doctrine\Common\Persistence\ObjectRepository $objectRepository
* @param \Doctrine\Persistence\ObjectRepository $objectRepository
*/
public function __construct(ObjectRepository $objectRepository)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

use BjyAuthorize\Provider\Identity\AuthenticationIdentityProvider;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;

/**
* Simple authentication provider factory
Expand All @@ -23,6 +22,7 @@ class AuthenticationIdentityProviderServiceFactory implements FactoryInterface
{
/**
* {@inheritDoc}
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
Expand All @@ -35,12 +35,4 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o

return $simpleIdentityProvider;
}

/**
* {@inheritDoc}
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, AuthenticationIdentityProvider::class);
}
}
14 changes: 3 additions & 11 deletions src/BjyAuthorize/Service/AuthorizeAwareServiceInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
namespace BjyAuthorize\Service;

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\InitializerInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\ServiceManager\Initializer\InitializerInterface;

/**
* Initializer that injects a {@see \BjyAuthorize\Service\Authorize} in
Expand All @@ -24,6 +23,7 @@ class AuthorizeAwareServiceInitializer implements InitializerInterface
{
/**
* {@inheritDoc}
* @see \Laminas\ServiceManager\Initializer\InitializerInterface::__invoke()
*/
public function __invoke(ContainerInterface $container, $instance)
{
Expand All @@ -32,16 +32,8 @@ public function __invoke(ContainerInterface $container, $instance)
}

/* @var $authorize \BjyAuthorize\Service\Authorize */
$authorize = $container->get('BjyAuthorize\Service\Authorize');
$authorize = $container->get(Authorize::class);

$instance->setAuthorizeService($authorize);
}

/**
* {@inheritDoc}
*/
public function initialize($instance, ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, $instance);
}
}
15 changes: 4 additions & 11 deletions src/BjyAuthorize/Service/AuthorizeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
namespace BjyAuthorize\Service;

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;

/**
* Factory responsible of building the {@see \BjyAuthorize\Service\Authorize} service
Expand All @@ -19,18 +18,12 @@
*/
class AuthorizeFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return new Authorize($container->get('BjyAuthorize\Config'), $container);
}

/**
* {@inheritDoc}
*
* @return \BjyAuthorize\Service\Authorize
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return $this($serviceLocator, Authorize::class);
return new Authorize($container->get('BjyAuthorize\Config'), $container);
}
}
16 changes: 2 additions & 14 deletions src/BjyAuthorize/Service/BaseProvidersServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
namespace BjyAuthorize\Service;

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;

/**
* Base factory responsible of instantiating providers
Expand All @@ -23,8 +22,7 @@ abstract class BaseProvidersServiceFactory implements FactoryInterface

/**
* {@inheritDoc}
*
* @return array
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
Expand All @@ -41,14 +39,4 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o

return $providers;
}

/**
* {@inheritDoc}
*
* @return array
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, '');
}
}
Loading

0 comments on commit 1d296a0

Please sign in to comment.