Issues (30)

src/ContainerAwareTrait.php (1 issue)

Severity
1
<?php
2
3
namespace Nip\Container;
4
5
/**
6
 * Class ContainerAwareTrait
7
 * @package Nip\Container
8
 */
9
trait ContainerAwareTrait
10
{
11
    /**
12
     * @var \Nip\Container\ContainerInterface
13
     */
14
    protected $container;
15
16
    /**
17
     * Get the container.
18
     *
19
     * @return \Nip\Container\ContainerInterface
20
     */
21 3
    public function getContainer()
22
    {
23 3
        return $this->container;
24
    }
25
26
    /**
27
     * Set a container.
28
     *
29
     * @param \Nip\Container\ContainerInterface $container
30
     * @return $this
31
     */
32 2
    public function setContainer(ContainerInterface $container)
33
    {
34 2
        $this->container = $container;
35 2
        return $this;
36
    }
37
38 1
    public function initContainer()
39
    {
40 1
        $container = Container::getInstance();
41 1
        if ($container instanceof Container) {
0 ignored issues
show
$container is always a sub-type of Nip\Container\Container.
Loading history...
42 1
            $this->container = $container;
43
        } else {
44
            $this->container = $this->newContainer();
45
            Container::setInstance($this->container);
46
        }
47 1
    }
48
49
    /**
50
     * @return Container
51
     */
52
    public function newContainer()
53
    {
54
        return new Container();
55
    }
56
57
    /**
58
     * @return bool
59
     */
60
    public function hasContainer()
61
    {
62
        return $this->container instanceof ContainerInterface;
63
    }
64
}
65