forked from nemiah/phpFinTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDegDescriptor.php
More file actions
48 lines (43 loc) · 1.51 KB
/
DegDescriptor.php
File metadata and controls
48 lines (43 loc) · 1.51 KB
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
<?php
namespace Fhp\Segment;
/**
* Contains meta information about a data element group, i.e. anything that can be statically known about a sub-class of
* {@link BaseDeg} through reflection.
*/
class DegDescriptor extends BaseDescriptor
{
/** @var DegDescriptor[] */
private static array $descriptors = [];
/**
* @param string $class The name of a sub-class of {@link BaseDeg}.
* @return DegDescriptor The descriptor for the class.
*/
public static function get(string $class): DegDescriptor
{
if (!array_key_exists($class, static::$descriptors)) {
static::$descriptors[$class] = new DegDescriptor($class);
}
return static::$descriptors[$class];
}
/**
* Please use the factory above.
* @param string $class The name of a sub-class of {@link BaseDeg}.
*/
protected function __construct(string $class)
{
$this->class = $class;
try {
$clazz = new \ReflectionClass($class);
if (!$clazz->isSubclassOf(BaseDeg::class)) {
throw new \InvalidArgumentException("Must inherit from BaseDeg: $class");
}
parent::__construct($clazz);
// Check if the name ends in V2 or so, implicitly assume V1.
if (preg_match('/^[A-Z]+[vV]([0-9]+)$/', $clazz->getShortName(), $match) === 1) {
$this->version = intval($match[1]);
}
} catch (\ReflectionException $e) {
throw new \RuntimeException($e);
}
}
}