| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\Sentry\Tracing; |
| 5 |
|
| 6 |
use WCPOS\Vendor\Sentry\Util\SentryUid; |
| 7 |
/** |
| 8 |
* This class represents an span ID. |
| 9 |
*/ |
| 10 |
final class SpanId implements \Stringable |
| 11 |
{ |
| 12 |
/** |
| 13 |
* @var string The ID |
| 14 |
*/ |
| 15 |
private $value; |
| 16 |
/** |
| 17 |
* Class constructor. |
| 18 |
* |
| 19 |
* @param string $value The ID |
| 20 |
*/ |
| 21 |
public function __construct(string $value) |
| 22 |
{ |
| 23 |
if (!\preg_match('/^[a-f0-9]{16}$/i', $value)) { |
| 24 |
throw new \InvalidArgumentException('The $value argument must be a 16 characters long hexadecimal string.'); |
| 25 |
} |
| 26 |
$this->value = $value; |
| 27 |
} |
| 28 |
/** |
| 29 |
* Generates a new span ID. |
| 30 |
*/ |
| 31 |
public static function generate() : self |
| 32 |
{ |
| 33 |
return new self(\substr(SentryUid::generate(), 0, 16)); |
| 34 |
} |
| 35 |
/** |
| 36 |
* Compares whether two objects are equals. |
| 37 |
* |
| 38 |
* @param SpanId $other The object to compare |
| 39 |
*/ |
| 40 |
public function isEqualTo(self $other) : bool |
| 41 |
{ |
| 42 |
return $this->value === $other->value; |
| 43 |
} |
| 44 |
public function __toString() : string |
| 45 |
{ |
| 46 |
return $this->value; |
| 47 |
} |
| 48 |
} |
| 49 |
|