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\configurator\ClassConfiguratorInterface; |
9
|
|
|
use samsonframework\container\configurator\MethodConfiguratorInterface; |
10
|
|
|
use samsonframework\container\configurator\PropertyConfiguratorInterface; |
11
|
|
|
use samsonframework\container\metadata\AbstractMetadata; |
12
|
|
|
use samsonframework\container\metadata\ClassMetadata; |
13
|
|
|
use samsonframework\container\metadata\MethodMetadata; |
14
|
|
|
use samsonframework\container\metadata\PropertyMetadata; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Collection attribute resolver. |
18
|
|
|
* |
19
|
|
|
* @author Vitaly Egorov <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class CollectionAttributeResolver extends AbstractCollectionResolver |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* CollectionAttributeResolver constructor. |
25
|
|
|
* |
26
|
|
|
* @param array $configurators |
27
|
|
|
* |
28
|
|
|
* @throws \InvalidArgumentException |
29
|
|
|
*/ |
30
|
|
|
public function __construct(array $configurators) |
31
|
|
|
{ |
32
|
|
|
// Fill with key nested interface |
33
|
|
|
$this->configurators = $this->getConfiguratorsByInterface( |
|
|
|
|
34
|
|
|
$configurators, |
35
|
|
|
CollectionAttributeConfiguratorInterface::class |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritDoc} |
41
|
|
|
*/ |
42
|
|
|
public function resolveAttribute(string $key, string $value, AbstractMetadata $metadata) |
43
|
|
|
{ |
44
|
|
|
// If this is supported collection configurator |
45
|
|
|
if (array_key_exists($key, $this->configurators)) { |
|
|
|
|
46
|
|
|
/** @var CollectionAttributeConfiguratorInterface $configurator Create configurator */ |
47
|
|
|
$configurator = new $this->configurators[$key]($value); |
|
|
|
|
48
|
|
|
if ($configurator instanceof ClassConfiguratorInterface && $metadata instanceof ClassMetadata) { |
49
|
|
|
$configurator->toClassMetadata($metadata); |
50
|
|
|
} |
51
|
|
|
if ($configurator instanceof PropertyConfiguratorInterface && $metadata instanceof PropertyMetadata) { |
52
|
|
|
$configurator->toPropertyMetadata($metadata); |
53
|
|
|
} |
54
|
|
|
if ($configurator instanceof MethodConfiguratorInterface && $metadata instanceof MethodMetadata) { |
55
|
|
|
$configurator->toMethodMetadata($metadata); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $metadata; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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.