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

EventCleaner::clean()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 2
b 0
f 1
nc 2
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Hhxsv5\LaravelS\Illuminate\Cleaners;
4
5
6
use Illuminate\Container\Container;
7
8
class EventCleaner extends BaseCleaner
9
{
10
    private $listeners;
11
    private $wildcards;
12
    private $wildcardsCache;
13
14
    public function __construct(Container $currentApp, Container $snapshotApp)
15
    {
16
        parent::__construct($currentApp, $snapshotApp);
17
18
        $ref = new \ReflectionObject($this->currentApp['events']);
19
        $this->listeners = $ref->getProperty('listeners');
20
        $this->listeners->setAccessible(true);
21
22
        $this->wildcards = $ref->getProperty('wildcards');
23
        $this->wildcards->setAccessible(true);
24
25
        if ($ref->hasProperty('wildcardsCache')) { // Laravel 5.6+
26
            $this->wildcardsCache = $ref->getProperty('wildcardsCache');
27
            $this->wildcardsCache->setAccessible(true);
28
        }
29
    }
30
31
    public function clean()
32
    {
33
        $this->listeners->setValue($this->currentApp['events'], []);
34
        $this->wildcards->setValue($this->currentApp['events'], []);
35
        if ($this->wildcardsCache) {
36
            $this->wildcardsCache->setValue($this->currentApp['events'], []);
37
        }
38
    }
39
}