blob: 237e70ba5bee0a211622757e3e022e136de67f7f (
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
|
<?php
declare(strict_types=1);
namespace OpenTelemetry\SDK\Common\Util;
use LogicException;
class ClassConstantAccessor
{
public static function requireValue(string $className, string $constantName)
{
$constant = self::getFullName($className, $constantName);
if (!defined($constant)) {
throw new LogicException(
sprintf('The class "%s" does not have a constant "%s"', $className, $constantName)
);
}
return constant($constant);
}
public static function getValue(string $className, string $constantName)
{
$constant = self::getFullName($className, $constantName);
return defined($constant) ? constant($constant) : null;
}
private static function getFullName(string $className, string $constantName): string
{
return sprintf('%s::%s', $className, $constantName);
}
}
|