1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Drupal\mongodb_watchdog; |
6
|
|
|
|
7
|
|
|
use Drupal\Core\ParamConverter\ParamConverterInterface; |
|
|
|
|
8
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
9
|
|
|
use Symfony\Component\Routing\Route; |
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class EventTemplateConverter load MongoDB watchdog event templates by id. |
13
|
|
|
*/ |
14
|
|
|
class EventTemplateConverter implements ParamConverterInterface { |
15
|
|
|
const PARAM_TYPE = 'mongodb_watchdog_event_template'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The core logger channel service. |
19
|
|
|
* |
20
|
|
|
* @var \Psr\Log\LoggerInterface |
21
|
|
|
*/ |
22
|
|
|
protected $logger; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The MongoDB logger service, to load events. |
26
|
|
|
* |
27
|
|
|
* @var \Drupal\mongodb_watchdog\Logger |
28
|
|
|
*/ |
29
|
|
|
protected $watchdog; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* EventTemplateConverter constructor. |
33
|
|
|
* |
34
|
|
|
* @param \Psr\Log\LoggerInterface $logger |
35
|
|
|
* The logger service, to log intervening events. |
36
|
|
|
* @param \Drupal\mongodb_watchdog\Logger $watchdog |
37
|
|
|
* The MongoDB logger, to load event templates. |
38
|
|
|
*/ |
39
|
|
|
public function __construct(LoggerInterface $logger, Logger $watchdog) { |
40
|
|
|
$this->logger = $logger; |
41
|
|
|
$this->watchdog = $watchdog; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function convert($value, $definition, $name, array $defaults): ?EventTemplate { |
48
|
|
|
if (!is_string($value)) { |
49
|
|
|
$this->logger->notice('Non-string event template id: %id', [ |
50
|
|
|
'%id' => var_export($value, TRUE), |
51
|
|
|
]); |
52
|
|
|
return NULL; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$selector = [ |
56
|
|
|
'_id' => $value, |
57
|
|
|
]; |
58
|
|
|
$options = [ |
59
|
|
|
'typeMap' => [ |
60
|
|
|
'array' => 'array', |
61
|
|
|
'document' => 'array', |
62
|
|
|
'root' => 'Drupal\mongodb_watchdog\EventTemplate', |
63
|
|
|
], |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
// Returns null if there is no match, as expected by ParamConverter. |
67
|
|
|
// Never returns an array as findOne() could, because of $options. |
68
|
|
|
$template = $this->watchdog->templateCollection()->findOne($selector, $options); |
69
|
|
|
if (empty($template)) { |
70
|
|
|
$this->logger->notice('Invalid event template id: %id', ['%id' => $value]); |
71
|
|
|
} |
72
|
|
|
assert(is_null($template) || $template instanceof EventTemplate); |
73
|
|
|
return $template; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
|
|
public function applies($definition, $name, Route $route): bool { |
80
|
|
|
return $definition['type'] === static::PARAM_TYPE; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths