diff --git a/composer.json b/composer.json index 7b626fd..782a080 100644 --- a/composer.json +++ b/composer.json @@ -15,16 +15,17 @@ "mezzio/mezzio-twigrenderer": "^2.2", "laminas/laminas-view": "^2.10", "ocramius/proxy-manager": "^2.1", - "laminas/laminas-dependency-plugin": "^1.0" + "laminas/laminas-authentication": "^2.7" }, "require-dev": { "phpunit/phpunit": "^4.8", "squizlabs/php_codesniffer": "^2.3", - "dotkernel/dot-authorization": "^2.0", - "dotkernel/dot-authentication": "^2.0", "dotkernel/dot-navigation": "^2.0", "dotkernel/dot-flashmessenger": "^2.0", - "laminas/laminas-form": "^2.9" + "laminas/laminas-form": "^2.9", + "doctrine/doctrine-module": "^3.0", + "laminas/laminas-dependency-plugin": "^1.0", + "mezzio/mezzio-authorization": "^1.0" }, "autoload": { "psr-4": { diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 75e7cf9..b565f50 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -9,6 +9,7 @@ namespace Dot\Twig; +use DoctrineModule\Service\Authentication\AuthenticationServiceFactory; use Dot\FlashMessenger\View\FlashMessengerRenderer; use Dot\Navigation\View\NavigationRenderer; use Dot\Twig\Extension\AuthenticationExtension; @@ -21,6 +22,8 @@ use Dot\Twig\Factory\FlashMessengerExtensionFactory; use Dot\Twig\Factory\NavigationExtensionFactory; use Dot\Twig\Laminas\View\HelperPluginManagerFactory; +use Laminas\Authentication\AuthenticationService; +use Laminas\Authentication\AuthenticationServiceInterface; use Laminas\ServiceManager\Factory\InvokableFactory; use Laminas\ServiceManager\Proxy\LazyServiceFactory; use Laminas\View\HelperPluginManager; @@ -52,6 +55,7 @@ public function getDependencyConfig(): array NavigationExtension::class => NavigationExtensionFactory::class, FlashMessengerExtension::class => FlashMessengerExtensionFactory::class, FormElementsExtension::class => InvokableFactory::class, + AuthenticationService::class => AuthenticationServiceFactory::class ], 'delegators' => [ @@ -79,6 +83,7 @@ public function getDependencyConfig(): array 'aliases' => [ 'ViewHelperManager' => HelperPluginManager::class, + AuthenticationServiceInterface::class => AuthenticationService::class ], ]; } diff --git a/src/Extension/AuthenticationExtension.php b/src/Extension/AuthenticationExtension.php index 68dd8cf..fe3c368 100644 --- a/src/Extension/AuthenticationExtension.php +++ b/src/Extension/AuthenticationExtension.php @@ -9,8 +9,7 @@ namespace Dot\Twig\Extension; -use Dot\Authentication\AuthenticationInterface; -use Dot\Authentication\Identity\IdentityInterface; +use Laminas\Authentication\AuthenticationServiceInterface; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; @@ -20,14 +19,14 @@ */ class AuthenticationExtension extends AbstractExtension { - /** @var AuthenticationInterface */ + /** @var AuthenticationServiceInterface */ protected $authentication; /** * AuthenticationExtension constructor. - * @param AuthenticationInterface $authentication + * @param AuthenticationServiceInterface $authentication */ - public function __construct(AuthenticationInterface $authentication) + public function __construct(AuthenticationServiceInterface $authentication) { $this->authentication = $authentication; } @@ -53,7 +52,7 @@ public function hasIdentity(): bool return $this->authentication->hasIdentity(); } - public function getIdentity(): IdentityInterface + public function getIdentity() { return $this->authentication->getIdentity(); } diff --git a/src/Extension/AuthorizationExtension.php b/src/Extension/AuthorizationExtension.php index 70ba0e3..a45b4cd 100644 --- a/src/Extension/AuthorizationExtension.php +++ b/src/Extension/AuthorizationExtension.php @@ -9,7 +9,8 @@ namespace Dot\Twig\Extension; -use Dot\Authorization\AuthorizationInterface; +use Mezzio\Authorization\AuthorizationInterface; +use Psr\Http\Message\ServerRequestInterface; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; @@ -45,13 +46,12 @@ public function getFunctions(): array } /** - * @param $permission - * @param array $roles - * @param mixed $context - * @return bool + * @param ServerRequestInterface $request + * @param string $role + * @return mixed */ - public function isGranted(string $permission, array $roles = [], $context = null) + public function isGranted(ServerRequestInterface $request, string $role = '') { - return $this->authorization->isGranted($permission, $roles, $context); + return $this->authorization->isGranted($role, $request); } } diff --git a/src/Factory/AuthenticationExtensionFactory.php b/src/Factory/AuthenticationExtensionFactory.php index 2bae4db..ec8c4af 100644 --- a/src/Factory/AuthenticationExtensionFactory.php +++ b/src/Factory/AuthenticationExtensionFactory.php @@ -9,8 +9,8 @@ namespace Dot\Twig\Factory; -use Dot\Authentication\AuthenticationInterface; use Dot\Twig\Extension\AuthenticationExtension; +use Laminas\Authentication\AuthenticationServiceInterface; use Psr\Container\ContainerInterface; /** @@ -25,6 +25,6 @@ class AuthenticationExtensionFactory */ public function __invoke(ContainerInterface $container) { - return new AuthenticationExtension($container->get(AuthenticationInterface::class)); + return new AuthenticationExtension($container->get(AuthenticationServiceInterface::class)); } } diff --git a/src/Factory/AuthorizationExtensionFactory.php b/src/Factory/AuthorizationExtensionFactory.php index 34686e4..a085f7d 100644 --- a/src/Factory/AuthorizationExtensionFactory.php +++ b/src/Factory/AuthorizationExtensionFactory.php @@ -9,7 +9,7 @@ namespace Dot\Twig\Factory; -use Dot\Authorization\AuthorizationInterface; +use Mezzio\Authorization\AuthorizationInterface; use Dot\Twig\Extension\AuthorizationExtension; use Psr\Container\ContainerInterface; diff --git a/src/TwigEnvironmentDelegator.php b/src/TwigEnvironmentDelegator.php index 9429807..f60796f 100644 --- a/src/TwigEnvironmentDelegator.php +++ b/src/TwigEnvironmentDelegator.php @@ -9,8 +9,7 @@ namespace Dot\Twig; -use Dot\Authentication\AuthenticationInterface; -use Dot\Authorization\AuthorizationInterface; +use Mezzio\Authorization\AuthorizationInterface; use Dot\FlashMessenger\View\RendererInterface as FlashMessengerRendererInterface; use Dot\Navigation\View\RendererInterface as NavigationRendererInterface; use Dot\Twig\Extension\AuthenticationExtension; @@ -18,6 +17,7 @@ use Dot\Twig\Extension\FlashMessengerExtension; use Dot\Twig\Extension\FormElementsExtension; use Dot\Twig\Extension\NavigationExtension; +use Laminas\Authentication\AuthenticationServiceInterface; use Psr\Container\ContainerInterface; use Twig\Environment; use Twig\TwigFunction; @@ -58,7 +58,7 @@ function ($name) use ($viewHelperManager, $zfRenderer) { ); //add our default extensions, if dependencies are present - if ($container->has(AuthenticationInterface::class)) { + if ($container->has(AuthenticationServiceInterface::class)) { $environment->addExtension($container->get(AuthenticationExtension::class)); }