Completed
Push — master ( 193d10...49cd13 )
by Mike
10:55
created

Dripper::getUrlAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php namespace GeneaLabs\LaravelCaffeine;
2
3
use Jenssegers\Model\Model;
4
5
/**
6
 * @property string $url
7
 * @property string $interval
8
 */
9
class Dripper extends Model
10
{
11
    public function getUrlAttribute() : string
12
    {
13
        return trim(config('genealabs-laravel-caffeine.domain', url('/')), '/')
14
            . '/'
15
            . trim(config(
16
                'genealabs-laravel-caffeine.route',
17
                'genealabs/laravel-caffeine/drip'
18
            ), '/');
19
    }
20
21
    public function getIntervalAttribute() : string
22
    {
23
        return config(
24
            'genealabs-laravel-caffeine.dripIntervalInMilliSeconds',
25
            300000
26
        );
27
    }
28
29
    public function getHtmlAttribute() : string
30
    {
31
        return '<script>setInterval(function(){'
32
            . "var e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject('Microsoft.XMLHTTP');"
33
            . "e.open('GET','{$this->url}',!0);"
34
            . "e.setRequestHeader('X-Requested-With','XMLHttpRequest');"
35
            . "e.send();}, {$this->interval});</script>";
36
    }
37
}
38