Completed
Push — master ( 9d13eb...060bbf )
by Antonio Carlos
06:41
created

ServiceInstances::dataRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace PragmaRX\Firewall\Support;
4
5
trait ServiceInstances
6
{
7
    public $instances = [];
8
9
    public function getInstance($binding)
10
    {
11
        if (is_null($instance = $this->getFromInstanceCache($binding))) {
12
            $instance = app('firewall.'.$binding);
13
        }
14
15
        $this->setInstance($binding, $instance);
16
17
        return $instance;
18
    }
19
20
    public function getFromInstanceCache($binding)
21
    {
22
        if (isset($this->instances[$binding])) {
23
            return $this->instances[$binding];
24
        }
25
26
        return null;
27
    }
28
29
    public function setInstance($binding, $instance)
30
    {
31
        $this->instances[$binding] = $instance;
32
    }
33
34
    public function countries()
35
    {
36
        return $this->getInstance('countries');
37
    }
38
39
    public function ipList()
40
    {
41
        return $this->getInstance('iplist');
42
    }
43
44
    public function messages()
45
    {
46
        return $this->getInstance('messages');
47
    }
48
49
    public function cache()
50
    {
51
        return $this->getInstance('cache');
52
    }
53
54
    public function config()
55
    {
56
        return $this->getInstance('config');
57
    }
58
59
    public function fileSystem()
60
    {
61
        return $this->getInstance('filesystem');
62
    }
63
64
    public function geoIp()
65
    {
66
        return $this->getInstance('geoip');
67
    }
68
69
    public function ipAddress()
70
    {
71
        return $this->getInstance('ipaddress');
72
    }
73
74
    public function dataRepository()
75
    {
76
        return $this->getInstance('datarepository');
77
    }
78
}
79