Completed
Push — master ( fa3c04...692093 )
by Vitaly
02:57
created

XMLResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 61
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A resolve() 0 16 1
A xml2array() 0 8 3
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 14.08.16 at 15:55
5
 */
6
namespace samsonframework\container\resolver;
7
8
use samsonframework\container\metadata\ClassMetadata;
9
10
/**
11
 * XML dependency injection container configuration.
12
 *
13
 * @author Vitaly Iegorov <[email protected]>
14
 * @author Ruslan Molodyko  <[email protected]>
15
 */
16
class XMLResolver implements ResolverInterface
17
{
18
    /** @var ArrayClassResolver */
19
    protected $classResolver;
20
21
    /**
22
     * AnnotationResolver constructor.
23
     *
24
     * @param ArrayClassResolver $classResolver
25
     */
26
    public function __construct(ArrayClassResolver $classResolver)
27
    {
28
        $this->classResolver = $classResolver;
29
        //$this->propertyResolver = $propertyResolver;
30
        //$this->methodResolver = $methodResolver;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function resolve($xmlConfiguration, string $identifier = null) : ClassMetadata
37
    {
38
        $arrayData = $this->xml2array(new \SimpleXMLElement($xmlConfiguration));
39
40
        // Create and fill class metadata base fields
41
        $classMetadata = new ClassMetadata();
42
43
        // Resolve class definition annotations
44
        $this->classResolver->resolve($arrayData, $classMetadata);
45
        // Resolve class properties annotations
46
        //$this->propertyResolver->resolve($classData, $classMetadata);
47
        // Resolve class methods annotations
48
        //$this->methodResolver->resolve($classData, $classMetadata);
49
50
        return new ClassMetadata();
51
    }
52
53
    /**
54
     * function xml2array
55
     *
56
     * This function is part of the PHP manual.
57
     *
58
     * The PHP manual text and comments are covered by the Creative Commons
59
     * Attribution 3.0 License, copyright (c) the PHP Documentation Group
60
     *
61
     * @author  k dot antczak at livedata dot pl
62
     * @date    2011-04-22 06:08 UTC
63
     * @link    http://www.php.net/manual/en/ref.simplexml.php#103617
64
     * @license http://www.php.net/license/index.php#doc-lic
65
     * @license http://creativecommons.org/licenses/by/3.0/
66
     * @license CC-BY-3.0 <http://spdx.org/licenses/CC-BY-3.0>
67
     */
68
    protected function xml2array($xmlObject, $out = array())
69
    {
70
        foreach ((array)$xmlObject as $index => $node) {
71
            $out[$index] = (is_object($node)) ? $this->xml2array($node) : $node;
72
        }
73
74
        return $out;
75
    }
76
}
77