Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Encryption;
4
 
5
use Illuminate\Support\ServiceProvider;
6
use Illuminate\Support\Str;
7
use Laravel\SerializableClosure\SerializableClosure;
8
 
9
class EncryptionServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Register the service provider.
13
     *
14
     * @return void
15
     */
16
    public function register()
17
    {
18
        $this->registerEncrypter();
19
        $this->registerSerializableClosureSecurityKey();
20
    }
21
 
22
    /**
23
     * Register the encrypter.
24
     *
25
     * @return void
26
     */
27
    protected function registerEncrypter()
28
    {
29
        $this->app->singleton('encrypter', function ($app) {
30
            $config = $app->make('config')->get('app');
31
 
32
            return new Encrypter($this->parseKey($config), $config['cipher']);
33
        });
34
    }
35
 
36
    /**
37
     * Configure Serializable Closure signing for security.
38
     *
39
     * @return void
40
     */
41
    protected function registerSerializableClosureSecurityKey()
42
    {
43
        $config = $this->app->make('config')->get('app');
44
 
45
        if (! class_exists(SerializableClosure::class) || empty($config['key'])) {
46
            return;
47
        }
48
 
49
        SerializableClosure::setSecretKey($this->parseKey($config));
50
    }
51
 
52
    /**
53
     * Parse the encryption key.
54
     *
55
     * @param  array  $config
56
     * @return string
57
     */
58
    protected function parseKey(array $config)
59
    {
60
        if (Str::startsWith($key = $this->key($config), $prefix = 'base64:')) {
61
            $key = base64_decode(Str::after($key, $prefix));
62
        }
63
 
64
        return $key;
65
    }
66
 
67
    /**
68
     * Extract the encryption key from the given configuration.
69
     *
70
     * @param  array  $config
71
     * @return string
72
     *
73
     * @throws \Illuminate\Encryption\MissingAppKeyException
74
     */
75
    protected function key(array $config)
76
    {
77
        return tap($config['key'], function ($key) {
78
            if (empty($key)) {
79
                throw new MissingAppKeyException;
80
            }
81
        });
82
    }
83
}