VarnishableService::loadConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace RichanFongdasen\Varnishable;
4
5
use GuzzleHttp\Client;
6
use RichanFongdasen\Varnishable\Concerns\InvalidateVarnishCache;
7
use RichanFongdasen\Varnishable\Concerns\ManageEtagHeader;
8
use RichanFongdasen\Varnishable\Concerns\ManageLastModifiedHeader;
9
use RichanFongdasen\Varnishable\Concerns\ManipulateHttpResponse;
10
11
class VarnishableService
12
{
13
    use InvalidateVarnishCache;
14
    use ManageEtagHeader;
15
    use ManageLastModifiedHeader;
16
    use ManipulateHttpResponse;
17
18
    /**
19
     * Varnishable configurations.
20
     *
21
     * @var array
22
     */
23
    protected $config;
24
25
    /**
26
     * Guzzle client object.
27
     *
28
     * @var \GuzzleHttp\Client
29
     */
30
    protected $guzzle;
31
32
    /**
33
     * Class constructor.
34
     *
35
     * @param \GuzzleHttp\Client $guzzle
36
     */
37
    public function __construct(Client $guzzle)
38
    {
39
        $this->guzzle = $guzzle;
40
        $this->loadConfig();
41
    }
42
43
    /**
44
     * Get configuration value for a specific key.
45
     *
46
     * @param string|null $key
47
     *
48
     * @return mixed
49
     */
50
    public function getConfig($key = null)
51
    {
52
        if ($key === null) {
53
            return $this->config;
54
        }
55
56
        return data_get($this->config, $key);
57
    }
58
59
    /**
60
     * Get guzzle client object.
61
     *
62
     * @return \GuzzleHttp\Client
63
     */
64
    public function getGuzzle(): Client
65
    {
66
        return $this->guzzle;
67
    }
68
69
    /**
70
     * Load the configurations.
71
     *
72
     * @return void
73
     */
74
    public function loadConfig(): void
75
    {
76
        $this->config = app('config')->get('varnishable');
77
    }
78
79
    /**
80
     * Set configuration value for a specific key.
81
     *
82
     * @param string $key
83
     * @param mixed  $value
84
     *
85
     * @return void
86
     */
87
    public function setConfig($key, $value): void
88
    {
89
        $this->config[$key] = $value;
90
    }
91
92
    /**
93
     * Replace the guzzle http client object with
94
     * a new one.
95
     *
96
     * @param \GuzzleHttp\Client $guzzle
97
     *
98
     * @return void
99
     */
100
    public function setGuzzle(Client $guzzle): void
101
    {
102
        $this->guzzle = $guzzle;
103
    }
104
}
105