|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2017, Matias De lellis <[email protected]> |
|
4
|
|
|
* @copyright Copyright (c) 2018, Branko Kokanovic <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* @author Branko Kokanovic <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU AGPL version 3 or any later version |
|
9
|
|
|
* |
|
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
13
|
|
|
* License, or (at your option) any later version. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
namespace OCA\FaceRecognition\BackgroundJob; |
|
25
|
|
|
|
|
26
|
|
|
use Psr\Log\LoggerInterface; |
|
27
|
|
|
|
|
28
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Logger class that encapsulates logging for background tasks. Reason for this |
|
32
|
|
|
* class is because background processing can be called as either command, as |
|
33
|
|
|
* well as background job, so we need a way to unify logging for both. |
|
34
|
|
|
*/ |
|
35
|
|
|
class FaceRecognitionLogger { |
|
36
|
|
|
/** @var LoggerInterface */ |
|
37
|
|
|
private $logger; |
|
38
|
|
|
|
|
39
|
|
|
/** @var OutputInterface */ |
|
40
|
|
|
private $output; |
|
41
|
|
|
|
|
42
|
28 |
|
public function __construct($logger) { |
|
43
|
28 |
|
if (method_exists($logger, 'info') && method_exists($logger, 'debug')) { |
|
44
|
28 |
|
$this->logger = $logger; |
|
|
|
|
|
|
45
|
|
|
} else if ($logger instanceof OutputInterface) { |
|
46
|
|
|
$this->output = $logger; |
|
47
|
|
|
} else { |
|
48
|
|
|
throw new \InvalidArgumentException("Logger must be either instance of LoggerInterface or OutputInterface"); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Returns logger, if it is set |
|
54
|
|
|
* |
|
55
|
|
|
* @return LoggerInterface|null Logger, if it is set. |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getLogger() { |
|
58
|
|
|
return $this->logger; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
12 |
|
public function logInfo(string $message): void { |
|
62
|
12 |
|
if (!is_null($this->logger)) { |
|
63
|
12 |
|
$this->logger->info($message); |
|
64
|
|
|
} else if (!is_null($this->output)) { |
|
65
|
|
|
$this->output->writeln($message); |
|
66
|
|
|
} else { |
|
67
|
|
|
throw new \RuntimeException("There are no configured loggers. Please file an issue at https://github.com/matiasdelellis/facerecognition/issues"); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function logDebug(string $message): void { |
|
72
|
|
|
if (!is_null($this->logger)) { |
|
73
|
|
|
$this->logger->debug($message); |
|
74
|
|
|
} else if (!is_null($this->output)) { |
|
75
|
|
|
$this->output->writeln($message); |
|
76
|
|
|
} else { |
|
77
|
|
|
throw new \RuntimeException("There are no configured loggers. Please file an issue at https://github.com/matiasdelellis/facerecognition/issues"); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.