These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Vectorface\Auth\Plugin; |
||
4 | |||
5 | use Psr\Log\LoggerTrait as PsrLoggerTrait; |
||
6 | |||
7 | /** |
||
8 | * Plugins wishing to perform their own logging may do so using this trait. |
||
9 | */ |
||
10 | trait SharedLoggerTrait { |
||
11 | /** |
||
12 | * Use the PSR logger trait, but make the methods protected so they aren't exposed via the Auth object. |
||
13 | */ |
||
14 | use PsrLoggerTrait { |
||
15 | emergency as protected; |
||
16 | alert as protected; |
||
17 | critical as protected; |
||
18 | error as protected; |
||
19 | warning as protected; |
||
20 | notice as protected; |
||
21 | info as protected; |
||
22 | debug as protected; |
||
23 | log as protected; |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Logs with an arbitrary level, or don't if no logger has been set. |
||
28 | * |
||
29 | * @param mixed $level The log level. A LogLevel::* constant (usually) |
||
30 | * @param string $message The message to log. |
||
31 | * @param array $context Further information about the context of the log message. |
||
32 | */ |
||
33 | 2 | protected function log($level, $message, array $context = array()) { |
|
34 | 2 | $logger = null; |
|
35 | 2 | if (isset($this->logger)) { |
|
36 | 1 | $logger = $this->logger; |
|
0 ignored issues
–
show
|
|||
37 | 2 | } elseif ($auth = $this->getAuth()) { |
|
38 | 2 | $logger = $auth->getLogger(); |
|
39 | 2 | } |
|
40 | |||
41 | 2 | if ($logger) { |
|
42 | 1 | $logger->log($level, $message, $context); |
|
43 | 1 | } |
|
44 | 2 | } |
|
45 | |||
46 | /** |
||
47 | * Get the Auth class instance |
||
48 | * |
||
49 | * @return Auth |
||
50 | */ |
||
51 | abstract protected function getAuth(); |
||
52 | } |
||
53 | |||
54 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: