1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: root |
5
|
|
|
* Date: 29.07.2016 |
6
|
|
|
* Time: 21:38. |
7
|
|
|
*/ |
8
|
|
|
namespace samsonframework\container\collection; |
9
|
|
|
|
10
|
|
|
use samsonframework\container\configurator\ConfiguratorInterface; |
11
|
|
|
use samsonframework\container\metadata\ClassMetadata; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Array class resolver class. |
15
|
|
|
* @author Vitaly Iegorov <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class CollectionClassResolver implements CollectionResolverInterface |
18
|
|
|
{ |
19
|
|
|
/** Array key name for searching class cofiguration sections */ |
20
|
|
|
const KEY_CLASS = 'dependencies'; |
21
|
|
|
/** @var array Collection of supported array keys */ |
22
|
|
|
protected $keys = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* ArrayClassResolver constructor. |
26
|
|
|
*/ |
27
|
|
|
public function __construct() |
28
|
|
|
{ |
29
|
|
|
// Gather all supported configuration keys |
30
|
|
|
$this->keys = []; |
31
|
|
|
foreach (get_declared_classes() as $className) { |
32
|
|
|
if (in_array(ConfiguratorInterface::class, class_implements($className), true)) { |
33
|
|
|
$annotationName = substr($className, strrpos($className, '\\') + 1); |
34
|
|
|
$this->keys[strtolower($annotationName)] = $className; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritDoc} |
41
|
|
|
*/ |
42
|
|
|
public function resolve(array $classDataArray, ClassMetadata $classMetadata) |
43
|
|
|
{ |
44
|
|
|
foreach ($classDataArray as $item => $configuration) { |
45
|
|
|
// If we have class resolving key |
46
|
|
|
foreach ($this->keys as $key => $className) { |
47
|
|
|
if (array_key_exists($key, $configuration)) { |
48
|
|
|
(new $className(['value' => $configuration[$key]]))->toClassMetadata($classMetadata); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $classMetadata; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function resolveArrayKeys() |
57
|
|
|
{ |
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|