Completed
Branch 2.0 (13ec26)
by Anton
05:17
created

SessionBootloader   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A boot() 0 16 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Spiral\Session\Bootloaders;
10
11
use Spiral\Config\ModifierInterface;
12
use Spiral\Config\Patches\AppendPatch;
13
use Spiral\Core\Bootloaders\Bootloader;
14
use Spiral\Core\ConfiguratorInterface;
15
use Spiral\Session\Configs\SessionConfig;
16
use Spiral\Session\Middleware\SessionMiddleware;
17
use Spiral\Session\SectionInterface;
18
use Spiral\Session\Session;
19
use Spiral\Session\SessionInterface;
20
use Spiral\Session\SessionSection;
21
22
class SessionBootloader extends Bootloader
23
{
24
    const BOOT = true;
25
26
    const BINDINGS = [
27
        SessionInterface::class => Session::class,
28
        SectionInterface::class => SessionSection::class
29
    ];
30
31
    /**
32
     * Automatically registers session starter middleware and excludes session cookie from
33
     * cookie protection.
34
     *
35
     * @param ConfiguratorInterface $configurator
36
     * @param ModifierInterface     $modifier
37
     */
38
    public function boot(ConfiguratorInterface $configurator, ModifierInterface $modifier)
39
    {
40
        $session = $configurator->getConfig('session');
41
42
        $modifier->modify('http', new AppendPatch(
43
            'cookies.excluded',
44
            null,
45
            $session['cookie']
46
        ));
47
48
        $modifier->modify('http', new AppendPatch(
49
            'middleware',
50
            null,
51
            SessionMiddleware::class
52
        ));
53
    }
54
}