Completed
Push — master ( c83b26...4d419a )
by Biao
04:28
created

SessionCleaner::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Hhxsv5\LaravelS\Illuminate\Cleaners;
4
5
6
use Illuminate\Container\Container;
7
use Illuminate\Routing\Redirector;
8
use Illuminate\Support\Facades\Facade;
9
10
class SessionCleaner extends BaseCleaner
11
{
12
    private $drivers;
13
14
    public function __construct(Container $currentApp, Container $snapshotApp)
15
    {
16
        parent::__construct($currentApp, $snapshotApp);
17
18
        if (!isset($this->currentApp['session'])) {
19
            return;
20
        }
21
        $ref = new \ReflectionObject($this->currentApp['session']);
22
        $this->drivers = $ref->getProperty('drivers');
23
        $this->drivers->setAccessible(true);
24
25
    }
26
27
    public function clean()
28
    {
29
        if (!$this->drivers) {
30
            return;
31
        }
32
33
        $this->drivers->setValue($this->currentApp['session'], []);
34
        $this->currentApp->forgetInstance('session.store');
35
        Facade::clearResolvedInstance('session.store');
36
37
        if (isset($this->currentApp['redirect'])) {
38
            /**@var Redirector $redirect */
39
            $redirect = $this->currentApp['redirect'];
40
            $redirect->setSession($this->currentApp->make('session.store'));
41
        }
42
    }
43
}