AbstractApiAction.php
1.95 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Ekyna\Component\Payum\Payzen\Action\Api;
use Ekyna\Component\Payum\Payzen\Api\Api;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\Exception\UnsupportedApiException;
use Payum\Core\GatewayAwareInterface;
use Payum\Core\GatewayAwareTrait;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
/**
* Class AbstractApiAction
* @package Ekyna\Component\Payum\Payzen\Action\Api
* @author Etienne Dauvergne <contact@ekyna.com>
*/
abstract class AbstractApiAction implements ActionInterface, GatewayAwareInterface, ApiAwareInterface, LoggerAwareInterface
{
use GatewayAwareTrait;
/**
* @var Api
*/
protected $api;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @inheritDoc
*/
public function setApi($api)
{
if (false == $api instanceof Api) {
throw new UnsupportedApiException('Not supported.');
}
$this->api = $api;
}
/**
* {@inheritDoc}
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* Logs the given message.
*
* @param string $message
*/
protected function log($message)
{
if (!$this->logger) {
return;
}
$this->logger->debug($message);
}
/**
* Logs the given message and data.
*
* @param string $message
* @param array $data
* @param array $filterKeys
*/
protected function logData($message, array $data, array $filterKeys = [])
{
if (!$this->logger) {
return;
}
if (!empty($filterKeys)) {
$data = array_intersect_key($data, array_flip($filterKeys));
}
$data = array_map(function($key, $value) {
return "$key: $value";
}, array_keys($data), $data);
$this->logger->debug($message . ': ' . implode(', ', $data));
}
}