Completed
Push — master ( 74d8c1...00f6f4 )
by Westin
08:22
created

ContainerAwareCacheAbstract::getContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace WShafer\PSR11FlySystem\Cache;
5
6
use League\Flysystem\Cached\Storage\Psr6Cache;
7
use Psr\Container\ContainerInterface;
8
use WShafer\PSR11FlySystem\ContainerAwareInterface;
9
use WShafer\PSR11FlySystem\Exception\MissingServiceException;
10
use WShafer\PSR11FlySystem\FactoryInterface;
11
12
abstract class ContainerAwareCacheAbstract implements FactoryInterface, ContainerAwareInterface
13
{
14
    /** @var ContainerInterface */
15
    protected $container;
16
17
    abstract public function __invoke(array $options);
18
19
    public function getContainer(): ContainerInterface
20
    {
21
        return $this->container;
22
    }
23
24
    public function setContainer(ContainerInterface $container)
25
    {
26
        $this->container = $container;
27
    }
28
29
    public function getService($serviceName)
30
    {
31
        if (empty($serviceName)
32
            || !$this->getContainer()->has($serviceName)
33
        ) {
34
            throw new MissingServiceException(
35
                'Unable to locate service '.$serviceName
36
            );
37
        }
38
39
        return $this->getContainer()->get($serviceName);
40
    }
41
}
42