-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleCommandLifecycle.php
More file actions
68 lines (57 loc) · 1.58 KB
/
ConsoleCommandLifecycle.php
File metadata and controls
68 lines (57 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Perfbase\Drupal\Lifecycle;
use Perfbase\Drupal\Config\ConfigResolver;
use Perfbase\Drupal\Runtime\PerfbaseFactoryInterface;
use Perfbase\Drupal\Support\ErrorHandler;
use Perfbase\Drupal\Support\FilterMatcher;
use Perfbase\Drupal\Support\SpanNaming;
/**
*
*/
class ConsoleCommandLifecycle extends AbstractDrupalProfiler {
private string $commandName;
public function __construct(
string $commandName,
PerfbaseFactoryInterface $factory,
ConfigResolver $configResolver,
ErrorHandler $errorHandler,
) {
$this->commandName = $commandName;
parent::__construct(
SpanNaming::forConsole($commandName),
$factory,
$configResolver,
$errorHandler
);
}
/**
*
*/
protected function shouldProfile(): bool {
if (!$this->configResolver->isEnabled($this->config)) {
return FALSE;
}
if (empty($this->config['profile_console']) || !$this->isProfilerAvailable()) {
return FALSE;
}
return FilterMatcher::passesFilters(
[$this->commandName],
is_array($this->config['include']) ? $this->config['include'] : [],
is_array($this->config['exclude']) ? $this->config['exclude'] : [],
'console'
);
}
/**
*
*/
protected function setDefaultAttributes(): void {
parent::setDefaultAttributes();
$this->setAttributes([
'source' => 'console',
'action' => $this->commandName,
'environment' => $this->getEnvironment(),
'app_version' => $this->getAppVersion(),
'drupal.command' => $this->commandName,
]);
}
}