-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleCommandLifecycle.php
More file actions
62 lines (52 loc) · 1.54 KB
/
ConsoleCommandLifecycle.php
File metadata and controls
62 lines (52 loc) · 1.54 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
<?php
declare(strict_types=1);
namespace Perfbase\Symfony\Lifecycle;
use Perfbase\Symfony\Profiling\AbstractProfiler;
use Perfbase\Symfony\Support\FilterMatcher;
use Perfbase\Symfony\Support\PerfbaseClientProvider;
use Perfbase\Symfony\Support\PerfbaseErrorHandler;
use Perfbase\Symfony\Support\SpanNaming;
class ConsoleCommandLifecycle extends AbstractProfiler
{
private string $command;
/**
* @param array<string, mixed> $config
*/
public function __construct(
string $command,
PerfbaseClientProvider $clientProvider,
PerfbaseErrorHandler $errorHandler,
array $config,
string $environment,
string $appVersion
) {
parent::__construct(
SpanNaming::forConsole($command),
$clientProvider,
$errorHandler,
$config,
$environment,
$appVersion
);
$this->command = $command;
}
protected function shouldProfile(): bool
{
if (!(bool) ($this->config['enabled'] ?? false)) {
return false;
}
return FilterMatcher::passesFilters(
[$this->command],
$this->normalizeFilters($this->config['include']['console'] ?? ['*']),
$this->normalizeFilters($this->config['exclude']['console'] ?? [])
);
}
protected function setDefaultAttributes(): void
{
parent::setDefaultAttributes();
$this->setAttributes([
'source' => 'console',
'action' => $this->command,
]);
}
}