Completed
Push — develop ( 0935d6...5677b3 )
by Fabian
02:21
created

HandlerManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cakasim\Payone\Sdk\Notification\Handler;
6
7
use Cakasim\Payone\Sdk\Notification\Context\ContextInterface;
8
use Psr\Log\LoggerInterface;
9
10
/**
11
 * Implementation of the HandlerManagerInterface.
12
 *
13
 * @author Fabian Böttcher <[email protected]>
14
 * @since 0.1.0
15
 */
16
class HandlerManager implements HandlerManagerInterface
17
{
18
    /**
19
     * @var LoggerInterface The SDK logger.
20
     */
21
    protected $logger;
22
23
    /**
24
     * @var HandlerInterface[] The notification handlers.
25
     */
26
    protected $handlers = [];
27
28
    /**
29
     * @param LoggerInterface $logger The SDK logger.
30
     */
31
    public function __construct(LoggerInterface $logger)
32
    {
33
        $this->logger = $logger;
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function registerHandler(HandlerInterface $handler): void
40
    {
41
        $this->logger->info(sprintf("Register PAYONE notification message handler '%s'.", get_class($handler)));
42
        $this->handlers[] = $handler;
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public function forwardMessage(ContextInterface $context): void
49
    {
50
        foreach ($this->handlers as $handler) {
51
            $this->logger->info(sprintf("Forward PAYONE notification message to handler '%s'.", get_class($handler)));
52
            $handler->handleNotification($context);
53
        }
54
    }
55
}
56