-
Notifications
You must be signed in to change notification settings - Fork 0
/
ForbiddenHandlerFactory.php
56 lines (45 loc) · 1.81 KB
/
ForbiddenHandlerFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* @see https://github.com/dotkernel/dot-rbac-guard/ for the canonical source repository
* @copyright Copyright (c) 2017 Apidemia (https://www.apidemia.com)
* @license https://github.com/dotkernel/dot-rbac-guard/blob/master/LICENSE.md MIT License
*/
declare(strict_types = 1);
namespace Dot\Rbac\Guard\Factory;
use Dot\Authorization\AuthorizationInterface;
use Dot\Rbac\Guard\Middleware\ForbiddenHandler;
use Dot\Rbac\Guard\Options\RbacGuardOptions;
use Psr\Container\ContainerInterface;
use Mezzio\Template\TemplateRendererInterface;
/**
* Class ForbiddenHandlerFactory
* @package Dot\Rbac\Guard\Factory
*/
class ForbiddenHandlerFactory
{
use AttachAuthorizationEventListenersTrait;
/**
* @param ContainerInterface $container
* @param $requestedName
* @return ForbiddenHandler
*/
public function __invoke(ContainerInterface $container, $requestedName)
{
$config = $container->get('config');
$debug = (bool)$config['debug'] ?? false;
$authorizationService = $container->get(AuthorizationInterface::class);
$moduleOptions = $container->get(RbacGuardOptions::class);
$template = isset($config['mezzio']['error_handler']['template_403'])
? $config['mezzio']['error_handler']['template_403']
: ForbiddenHandler::TEMPLATE_DEFAULT;
$renderer = $container->has(TemplateRendererInterface::class)
? $container->get(TemplateRendererInterface::class)
: null;
/** @var ForbiddenHandler $handler */
$handler = new $requestedName($authorizationService, $moduleOptions, $renderer, $template);
$handler->setDebug($debug);
$handler->attach($handler->getEventManager(), 1000);
$this->attachListeners($container, $handler->getEventManager());
return $handler;
}
}