1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
/** |
3
|
|
|
* Created by Vitaly Iegorov <[email protected]>. |
4
|
|
|
* on 17.08.16 at 10:14 |
5
|
|
|
*/ |
6
|
|
|
namespace samsonframework\container\collection; |
7
|
|
|
|
8
|
|
|
use samsonframework\container\metadata\ClassMetadata; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Collection key resolver. |
12
|
|
|
* |
13
|
|
|
* @author Vitaly Egorov <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class CollectionKeyResolver extends AbstractCollectionResolver |
16
|
|
|
{ |
17
|
|
|
/** @var CollectionAttributeResolver */ |
18
|
|
|
protected $attributeResolver; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* CollectionKeyResolver constructor. |
22
|
|
|
* |
23
|
|
|
* @param array $configurators |
24
|
|
|
* |
25
|
|
|
* @param CollectionAttributeResolver $attributeResolver |
26
|
|
|
*/ |
27
|
|
|
public function __construct(array $configurators, CollectionAttributeResolver $attributeResolver) |
28
|
|
|
{ |
29
|
|
|
$this->attributeResolver = $attributeResolver; |
30
|
|
|
|
31
|
|
|
// Fill with key nested interface |
32
|
|
|
$this->configurators = $this->getConfiguratorsByInterface( |
|
|
|
|
33
|
|
|
$configurators, |
34
|
|
|
CollectionKeyConfiguratorInterface::class |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritDoc} |
40
|
|
|
*/ |
41
|
|
|
public function resolveKey(string $key, array $data, ClassMetadata $classMetadata = null) |
42
|
|
|
{ |
43
|
|
|
// If this is supported collection key configurator |
44
|
|
|
if (array_key_exists($key, $this->configurators)) { |
|
|
|
|
45
|
|
|
// Create configurator and retrieve metadata |
46
|
|
|
$metadata = (new $this->configurators[$key]($data))->resolve($data, $classMetadata); |
|
|
|
|
47
|
|
|
|
48
|
|
|
// If we have parsed metadata |
49
|
|
|
if ($metadata !== null) { |
50
|
|
|
// And we have attributes for this key |
51
|
|
|
if (array_key_exists('@attributes', $data)) { |
52
|
|
|
// Resolve attributes |
53
|
|
|
foreach ($data['@attributes'] as $attributeKey => $attributeValue) { |
54
|
|
|
$this->attributeResolver->resolveAttribute($attributeKey, $attributeValue, $metadata); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $classMetadata; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.