forked from voku/Arrayy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayyMeta.php
More file actions
54 lines (44 loc) · 1.27 KB
/
ArrayyMeta.php
File metadata and controls
54 lines (44 loc) · 1.27 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
49
50
51
52
53
54
<?php
declare(strict_types=1);
namespace Arrayy;
final class ArrayyMeta
{
/** @noinspection MagicMethodsValidityInspection */
/**
* @param string $name
*
* @return string
*/
public function __get($name): string
{
return '';
}
/**
* @param string $className
*
* @return $this
*
* @psalm-param class-string<\Arrayy\Arrayy<int|string,mixed>> $className
*/
public function getMetaObject(string $className): self
{
static $STATIC_CACHE = [];
$cacheKey = $className;
if (!empty($STATIC_CACHE[$cacheKey])) {
return $STATIC_CACHE[$cacheKey];
}
$reflector = new \ReflectionClass($className);
$factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
$docComment = $reflector->getDocComment();
if ($docComment) {
$docblock = $factory->create($docComment);
/** @var \phpDocumentor\Reflection\DocBlock\Tags\Property $tag */
foreach ($docblock->getTagsByName('property') as $tag) {
$PropertyName = $tag->getVariableName();
$this->{$PropertyName} = $PropertyName;
}
}
$STATIC_CACHE[$cacheKey] = $this;
return $this;
}
}