Completed
Push — master ( 4eea1d...c89067 )
by Hong
04:28
created

ContainerAwareTrait::getContainer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * Phoole (PHP7.2+)
5
 *
6
 * @category  Library
7
 * @package   Phoole\Di
8
 * @copyright Copyright (c) 2019 Hong Zhang
9
 */
10
declare(strict_types=1);
11
12
namespace Phoole\Di;
13
14
use Psr\Container\ContainerInterface;
15
16
/**
17
 * ContainerAwareTrait
18
 *
19
 * @package Phoole\Di
20
 */
21
trait ContainerAwareTrait
22
{
23
    /**
24
     * @var ContainerInterface
25
     */
26
    protected $container;
27
28
    /**
29
     * @param  ContainerInterface $container
30
     * @return $this
31
     */
32
    public function setContainer(ContainerInterface $container)
33
    {
34
        $this->container = $container;
35
        return $this;
36
    }
37
38
    /**
39
     * @return ContainerInterface
40
     * @throws \LogicException     if not set yet
41
     */
42
    public function getContainer(): ContainerInterface
43
    {
44
        if (is_null($this->container)) {
45
            throw new \LogicException("Container not set in " . get_class($this));
46
        }
47
        return $this->container;
48
    }
49
}