SetCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpCache\Commands;
4
5
use PhpCache\CacheClient\CacheClient;
6
use PhpCache\ServiceManager\ServiceManager;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
10
/**
11
 * Description of SetCommand.
12
 *
13
 * @author dude920228
14
 */
15
class SetCommand extends Command
16
{
17
    private $serviceManager;
18
19
    public function __construct($config, $name = null)
20
    {
21
        parent::__construct($name);
22
        $this->serviceManager = new ServiceManager($config);
23
    }
24
25
    protected function configure()
26
    {
27
        $this->setName('set');
28
        $this->setHelp('This command allows you to create entries in the cache pool');
29
        $this->addArgument('key', InputArgument::REQUIRED, 'The key assigned to the cache entry');
30
        $this->addArgument('value', InputArgument::REQUIRED, 'The value of the cache entry');
31
    }
32
33
    protected function execute($input, $output)
34
    {
35
        $this->set($input);
36
    }
37
38
    private function set($input)
39
    {
40
        /* @var $client CacheClient */
41
        $client = $this->serviceManager->get(CacheClient::class);
42
        $client->set($input->getArgument('key'), $input->getArgument('value'));
43
    }
44
}
45