|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ZoiloMora\ElasticAPM\Events\Metadata; |
|
4
|
|
|
|
|
5
|
|
|
use ZoiloMora\ElasticAPM\Configuration\CoreConfiguration; |
|
6
|
|
|
use ZoiloMora\ElasticAPM\Events\Common\Service as ServiceBase; |
|
7
|
|
|
use ZoiloMora\ElasticAPM\Events\Common\Service\Framework; |
|
8
|
|
|
use ZoiloMora\ElasticAPM\Events\Common\Service\Language; |
|
9
|
|
|
use ZoiloMora\ElasticAPM\Events\Common\Service\Node; |
|
10
|
|
|
use ZoiloMora\ElasticAPM\Events\Common\Service\Runtime; |
|
11
|
|
|
|
|
12
|
|
|
final class Service extends ServiceBase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param string $name |
|
16
|
|
|
* @param Language $language |
|
17
|
|
|
* @param Runtime $runtime |
|
18
|
|
|
* @param Framework|null $framework |
|
19
|
|
|
* @param string|null $environment |
|
20
|
|
|
* @param string|null $version |
|
21
|
|
|
* @param Node|null $node |
|
22
|
|
|
*/ |
|
23
|
16 |
|
public function __construct( |
|
24
|
|
|
$name, |
|
25
|
|
|
Language $language, |
|
26
|
|
|
Runtime $runtime, |
|
27
|
|
|
Framework $framework = null, |
|
28
|
|
|
$environment = null, |
|
29
|
|
|
$version = null, |
|
30
|
|
|
Node $node = null |
|
31
|
|
|
) { |
|
32
|
16 |
|
parent::__construct(null, $framework, $language, $name, $environment, $runtime, $version, $node); |
|
33
|
|
|
|
|
34
|
16 |
|
$this->assertLanguage(); |
|
35
|
15 |
|
$this->assertRuntime(); |
|
36
|
13 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return void |
|
40
|
|
|
* |
|
41
|
|
|
* @throws \InvalidArgumentException |
|
42
|
|
|
*/ |
|
43
|
16 |
|
private function assertLanguage() |
|
44
|
|
|
{ |
|
45
|
16 |
|
if (null === $this->language()->name()) { |
|
46
|
1 |
|
throw new \InvalidArgumentException('The [name] of the language is mandatory in the service.'); |
|
47
|
|
|
} |
|
48
|
15 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return void |
|
52
|
|
|
* |
|
53
|
|
|
* @throws \InvalidArgumentException |
|
54
|
|
|
*/ |
|
55
|
15 |
|
private function assertRuntime() |
|
56
|
|
|
{ |
|
57
|
15 |
|
if (null === $this->runtime()->name()) { |
|
58
|
1 |
|
throw new \InvalidArgumentException('The [name] of the runtime is mandatory in the service.'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
14 |
|
if (null === $this->runtime()->version()) { |
|
62
|
1 |
|
throw new \InvalidArgumentException('The [version] of the runtime is mandatory in the service.'); |
|
63
|
|
|
} |
|
64
|
13 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param CoreConfiguration $coreConfiguration |
|
68
|
|
|
* |
|
69
|
|
|
* @return Service |
|
70
|
|
|
*/ |
|
71
|
12 |
|
public static function create(CoreConfiguration $coreConfiguration) |
|
72
|
|
|
{ |
|
73
|
12 |
|
return new self( |
|
74
|
12 |
|
$coreConfiguration->appName(), |
|
75
|
12 |
|
Language::discover(), |
|
76
|
12 |
|
Runtime::discover(), |
|
77
|
12 |
|
Framework::create($coreConfiguration), |
|
78
|
12 |
|
$coreConfiguration->environment(), |
|
79
|
12 |
|
$coreConfiguration->appVersion() |
|
80
|
12 |
|
); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|