Completed
Push — master ( 801319...1033aa )
by Anton
14:25 queued 08:56
created

EncrypterManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A generateKey() 0 4 1
A createInjection() 0 4 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Encrypter;
9
10
use Spiral\Core\Container\InjectorInterface;
11
use Spiral\Core\Container\SingletonInterface;
12
use Spiral\Encrypter\Configs\EncrypterConfig;
13
14
/**
15
 * Only manages encrypter injections (factory).
16
 */
17
class EncrypterManager implements InjectorInterface, SingletonInterface
18
{
19
    /**
20
     * @var EncrypterConfig
21
     */
22
    protected $config = null;
23
24
    /**
25
     * @param EncrypterConfig $config
26
     */
27
    public function __construct(EncrypterConfig $config)
28
    {
29
        $this->config = $config;
30
    }
31
32
    /**
33
     * Generate new random encryption key (binary format).
34
     *
35
     * @return string
36
     */
37
    public function generateKey()
38
    {
39
        return \Crypto::CreateNewRandomKey();
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function createInjection(\ReflectionClass $class, $context = null)
46
    {
47
        return $class->newInstance($this->config->getKey());
48
    }
49
}