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

EncrypterManager::createInjection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
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
}