summaryrefslogtreecommitdiff
path: root/vendor/opentracing/opentracing/src/OpenTracing/Reference.php
blob: 7dadf17854941bf46f10dae054230059f6c2e05f (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
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
69
70
71
72
73
74
75
76
77
<?php

declare(strict_types=1);

namespace OpenTracing;

use OpenTracing\InvalidReferenceArgumentException;

final class Reference
{
    /**
     * A Span may be the ChildOf a parent Span. In a ChildOf reference,
     * the parent Span depends on the child Span in some capacity.
     */
    public const CHILD_OF = 'child_of';

    /**
     * Some parent Spans do not depend in any way on the result of their
     * child Spans. In these cases, we say merely that the child Span
     * FollowsFrom the parent Span in a causal sense.
     */
    public const FOLLOWS_FROM = 'follows_from';

    /**
     * @var string
     */
    private $type;

    /**
     * @var SpanContext
     */
    private $spanContext;

    /**
     * @param string $type
     * @param SpanContext $spanContext
     */
    public function __construct(string $type, SpanContext $spanContext)
    {
        if (empty($type)) {
            throw InvalidReferenceArgumentException::forEmptyType();
        }

        $this->type = $type;
        $this->spanContext = $spanContext;
    }

    /**
     * @param string $type
     * @param Span $span
     * @return Reference when context is invalid
     * @throws InvalidReferenceArgumentException on empty type
     */
    public static function createForSpan(string $type, Span $span): Reference
    {
        return new self($type, $span->getContext());
    }

    /**
     * @return SpanContext
     */
    public function getSpanContext(): SpanContext
    {
        return $this->spanContext;
    }

    /**
     * Checks whether a Reference is of one type.
     *
     * @param string $type the type for the reference
     * @return bool
     */
    public function isType(string $type): bool
    {
        return $this->type === $type;
    }
}