Completed
Push — master ( 7a0906...3ff6f8 )
by Ryan
02:30
created

UpdateMaintenanceMode::handle()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 8.8571
cc 6
eloc 8
nc 5
nop 1
1
<?php namespace Anomaly\SettingsModule\Setting\Listener;
2
3
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
4
use Anomaly\SettingsModule\Setting\Event\SettingsWereSaved;
5
use Illuminate\Contracts\Foundation\Application;
6
7
/**
8
 * Class UpdateMaintenanceMode
9
 *
10
 * @link          http://pyrocms.com/
11
 * @author        PyroCMS, Inc. <[email protected]>
12
 * @author        Ryan Thompson <[email protected]>
13
 * @package       Anomaly\SettingsModule\Setting\Listener
14
 */
15
class UpdateMaintenanceMode
16
{
17
18
    /**
19
     * The settings repository.
20
     *
21
     * @var SettingRepositoryInterface
22
     */
23
    protected $settings;
24
25
    /**
26
     * The application instance.
27
     *
28
     * @var Application
29
     */
30
    protected $application;
31
32
    /**
33
     * Create a new UpdateMaintenanceMode instance.
34
     *
35
     * @param Application                $application
36
     * @param SettingRepositoryInterface $settings
37
     */
38
    public function __construct(Application $application, SettingRepositoryInterface $settings)
39
    {
40
        $this->settings    = $settings;
41
        $this->application = $application;
42
    }
43
44
    /**
45
     * Handle the command.
46
     *
47
     * @param SettingsWereSaved $event
48
     */
49
    public function handle(SettingsWereSaved $event)
50
    {
51
        if (!($namespace = $event->getNamespace()) == 'streams') {
52
            return;
53
        }
54
55
        $maintenance = $this->settings->value('streams::maintenance', false);
56
57
        if ($maintenance && !$this->application->isDownForMaintenance()) {
58
            touch(storage_path('framework/down'));
59
        }
60
61
        if (!$maintenance && $this->application->isDownForMaintenance()) {
62
            unlink(storage_path('framework/down'));
63
        }
64
    }
65
}
66