summaryrefslogtreecommitdiff
path: root/vendor/open-telemetry/sdk/Common/Time/ClockFactory.php
blob: 33f4364f6d9acde2ffc9194a8594ba4a91f450f2 (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
<?php

declare(strict_types=1);

namespace OpenTelemetry\SDK\Common\Time;

final class ClockFactory implements ClockFactoryInterface
{
    private static ?ClockInterface $default = null;

    public static function create(): self
    {
        return new self();
    }

    public function build(): ClockInterface
    {
        return new SystemClock();
    }

    public static function getDefault(): ClockInterface
    {
        return self::$default ?? self::$default = self::create()->build();
    }

    public static function setDefault(?ClockInterface $clock): void
    {
        self::$default = $clock;
    }
}