-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_MapFromAttribute.php
49 lines (40 loc) · 1.3 KB
/
_MapFromAttribute.php
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
<?php declare(strict_types = 1);
/*
* This file is part of the Vairogs package.
*
* (c) Dāvis Zālītis (k0d3r1s) <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Vairogs\Component\Mapper\Traits;
use ReflectionException;
use Vairogs\Bundle\Service\RequestCache;
use Vairogs\Component\Mapper\Constants\MapperContext;
trait _MapFromAttribute
{
/**
* @throws ReflectionException
*/
public function mapFromAttribute(
object|string $objectOrClass,
RequestCache $requestCache,
bool $skipGlobal = false,
): ?string {
static $_helper = null;
if (null === $_helper) {
$_helper = new class {
use _FindClassesWithAttribute;
use _MapMapped;
};
}
$mapped = $_helper->mapMapped($objectOrClass, $requestCache);
if (!$skipGlobal && null === $mapped) {
$foundClasses = $requestCache->memoize(MapperContext::CLASSES_WITH_ATTR, 'key', static fn () => $_helper->findClassesWithAttribute($requestCache));
foreach ($foundClasses as $item) {
$_helper->mapMapped($item, $requestCache);
}
}
return $mapped;
}
}