summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/api/Baggage/BaggageBuilder.php
blob: d4500eac5ccf2a5861d1d7b4041050515667ae31 (plain)
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
<?php

declare(strict_types=1);

namespace OpenTelemetry\API\Baggage;

final class BaggageBuilder implements BaggageBuilderInterface
{
    /** @var array<string, Entry> */
    private array $entries;

    /** @param array<string, Entry> $entries */
    public function __construct(array $entries = [])
    {
        $this->entries = $entries;
    }

    /** @inheritDoc */
    public function remove(string $key): BaggageBuilderInterface
    {
        unset($this->entries[$key]);

        return $this;
    }

    /** @inheritDoc */
    public function set(string $key, $value, MetadataInterface $metadata = null): BaggageBuilderInterface
    {
        $metadata ??= Metadata::getEmpty();

        $this->entries[$key] = new Entry($value, $metadata);

        return $this;
    }

    public function build(): BaggageInterface
    {
        return new Baggage($this->entries);
    }
}