Completed
Push — master ( 5e6300...bf0ac0 )
by Anton
05:37
created

Autowire   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolve() 0 4 1
A __set_state() 0 4 1
1
<?php
2
/**
3
 * components
4
 *
5
 * @author    Wolfy-J
6
 */
7
8
namespace Spiral\Core\Container;
9
10
use Interop\Container\ContainerInterface;
11
12
/**
13
 * Provides ability to delegate option to container.
14
 */
15
final class Autowire
16
{
17
    /**
18
     * Delegation target
19
     *
20
     * @var mixed
21
     */
22
    private $alias;
23
24
    /**
25
     * Autowire constructor.
26
     *
27
     * @param string $alias
28
     */
29
    public function __construct(string $alias)
30
    {
31
        $this->alias = $alias;
32
    }
33
34
    /**
35
     * @param \Interop\Container\ContainerInterface $container
36
     *
37
     * @return mixed
38
     *
39
     * @throws \Interop\Container\Exception\NotFoundException  No entry was found for this
40
     *                                                         identifier.
41
     * @throws \Interop\Container\Exception\ContainerException Error while retrieving the entry.
42
     */
43
    public function resolve(ContainerInterface $container)
44
    {
45
        return $container->get($this->alias);
46
    }
47
48
    /**
49
     * @param $an_array
50
     *
51
     * @return static
52
     */
53
    public static function __set_state($an_array)
54
    {
55
        return new static($an_array['alias']);
56
    }
57
}