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

Autowire::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
}