ContainerAwareCacheAbstract::__invoke()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 1
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 3
    public function getContainer(): ContainerInterface
20
    {
21 3
        return $this->container;
22
    }
23
24 3
    public function setContainer(ContainerInterface $container)
25
    {
26 3
        $this->container = $container;
27 3
    }
28
29 2
    public function getService($serviceName)
30
    {
31 2
        if (empty($serviceName)
32 2
            || !$this->getContainer()->has($serviceName)
33
        ) {
34 1
            throw new MissingServiceException(
35 1
                'Unable to locate service '.$serviceName
36
            );
37
        }
38
39 1
        return $this->getContainer()->get($serviceName);
40
    }
41
}
42