Completed
Pull Request — 1.x (#35)
by
unknown
18:26
created

AbstractCommand::setContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
nc 1
cc 1
eloc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of CacheTool.
5
 *
6
 * (c) Samuel Gordalina <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CacheTool\Command;
13
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
16
use Symfony\Component\DependencyInjection\ContainerInterface;
17
18
abstract class AbstractCommand extends Command implements ContainerAwareInterface
19
{
20
    /**
21
     * @var ContainerInterface
22
     */
23
    protected $container;
24
25
    /**
26
     * @return CacheTool
27
     */
28
    protected function getCacheTool()
29
    {
30
        return $this->container->get('cachetool');
31
    }
32
33
    /**
34
     * @param  string $extension
35
     */
36
    protected function ensureExtensionLoaded($extension)
37
    {
38
        if (!$this->getCacheTool()->extension_loaded($extension)) {
39
            throw new \Exception("Extension `{$extension}` is not loaded");
40
        }
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function setContainer(ContainerInterface $container = null)
47
    {
48
        $this->container = $container;
49
    }
50
}
51