Completed
Push — master ( cac190...51e389 )
by WEBEWEB
01:21
created

AbstractProvider::setLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2020 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\Provider;
13
14
use Psr\Log\LoggerInterface;
15
use WBW\Library\Core\Model\Attribute\BooleanDebugTrait;
16
17
/**
18
 * Abstract provider.
19
 *
20
 * @author webeweb <https://github.com/webeweb>
21
 * @package WBW\Library\Core\Provider
22
 * @abstract
23
 */
24
abstract class AbstractProvider {
25
26
    use BooleanDebugTrait;
27
28
    /**
29
     * Logger.
30
     *
31
     * @var LoggerInterface
32
     */
33
    private $logger;
34
35
    /**
36
     * Constructor.
37
     *
38
     * @param LoggerInterface|null $logger The logger.
39
     */
40
    protected function __construct(LoggerInterface $logger = null) {
41
        $this->setLogger($logger);
42
    }
43
44
    /**
45
     * Get the logger.
46
     *
47
     * @return LoggerInterface Returns the logger.
48
     */
49
    public function getLogger() {
50
        return $this->logger;
51
    }
52
53
    /**
54
     * Log an info.
55
     *
56
     * @param string $message The message.
57
     * @param array $context The context.
58
     * @return AbstractProvider Returns this provider.
59
     */
60
    protected function logInfo($message, array $context) {
61
        if (null !== $this->getLogger()) {
62
            $this->getLogger()->info($message, $context);
63
        }
64
        return $this;
65
    }
66
67
    /**
68
     * Set the logger.
69
     *
70
     * @param LoggerInterface $logger The logger.
71
     * @return AbstractProvider Returns this provider.
72
     */
73
    protected function setLogger(LoggerInterface $logger = null) {
74
        $this->logger = $logger;
75
        return $this;
76
    }
77
78
}