1 | <?php |
||
2 | /** |
||
3 | * Copyright (c) 2010–2019 Ryan Parman <http://ryanparman.com>. |
||
4 | * Copyright (c) 2016–2019 Contributors. |
||
5 | * |
||
6 | * http://opensource.org/licenses/Apache2.0 |
||
7 | */ |
||
8 | |||
9 | declare(strict_types=1); |
||
10 | |||
11 | namespace SimplePie\UtilityPack\Mixin; |
||
12 | |||
13 | use Psr\Log\LoggerInterface; |
||
14 | use SimplePie\UtilityPack\Util\Types; |
||
15 | |||
16 | /** |
||
17 | * Shared code for working with the logger. |
||
18 | */ |
||
19 | trait LoggerTrait |
||
20 | { |
||
21 | /** |
||
22 | * A PSR-3 logger. |
||
23 | * |
||
24 | * @var LoggerInterface |
||
25 | */ |
||
26 | protected $logger; |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
27 | |||
28 | /** |
||
29 | * Sets the PSR-3 logger. |
||
30 | * |
||
31 | * @param LoggerInterface $logger A PSR-3 compatible logger. |
||
32 | */ |
||
33 | 1 | public function setLogger(LoggerInterface $logger): self |
|
34 | { |
||
35 | 1 | $this->logger = $logger; |
|
36 | |||
37 | // What are we logging with? |
||
38 | 1 | $this->logger->debug(\sprintf( |
|
39 | 1 | 'Class `%s` configured to use `%s`.', |
|
40 | 1 | Types::getClassOrType($this), |
|
41 | 1 | Types::getClassOrType($this->logger) |
|
42 | )); |
||
43 | |||
44 | 1 | return $this; |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Retrieves the PSR-3 logger. |
||
49 | */ |
||
50 | 1 | public function getLogger(): LoggerInterface |
|
51 | { |
||
52 | 1 | return $this->logger; |
|
53 | } |
||
54 | } |
||
55 |