-
Notifications
You must be signed in to change notification settings - Fork 30
/
Configuration.php
154 lines (126 loc) · 3.38 KB
/
Configuration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/*
* This file is part of SeAT
*
* Copyright (C) 2015 to 2022 Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Seat\Eseye;
use Seat\Eseye\Cache\CacheInterface;
use Seat\Eseye\Containers\EsiConfiguration;
use Seat\Eseye\Exceptions\InvalidConfigurationException;
use Seat\Eseye\Log\LogInterface;
/**
* Class Configuration.
*
* @package Seat\Eseye
*/
class Configuration
{
/**
* @var Configuration
*/
private static $instance;
/**
* @var LogInterface
*/
protected $logger;
/**
* @var CacheInterface
*/
protected $cache;
/**
* @var EsiConfiguration
*/
protected $configuration;
/**
* Configuration constructor.
*
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public function __construct()
{
$this->configuration = new EsiConfiguration;
}
/**
* @return \Seat\Eseye\Configuration
*
* @throws \Seat\Eseye\Exceptions\InvalidContainerDataException
*/
public static function getInstance(): self
{
if (is_null(self::$instance))
self::$instance = new self();
return self::$instance;
}
/**
* @return \Seat\Eseye\Containers\EsiConfiguration
*/
public function getConfiguration()
{
return $this->configuration;
}
/**
* @param \Seat\Eseye\Containers\EsiConfiguration $configuration
*
* @throws \Seat\Eseye\Exceptions\InvalidConfigurationException
*/
public function setConfiguration(EsiConfiguration $configuration)
{
if (! $configuration->valid())
throw new InvalidConfigurationException(
'The configuration is empty/invalid values');
$this->configuration = $configuration;
}
/**
* @return \Seat\Eseye\Log\LogInterface
*/
public function getLogger(): LogInterface
{
if (! $this->logger)
$this->logger = new $this->configuration->logger;
return $this->logger;
}
/**
* @return \Seat\Eseye\Cache\CacheInterface
*/
public function getCache(): CacheInterface
{
if (! $this->cache)
$this->cache = new $this->configuration->cache;
return $this->cache;
}
/**
* Magic method to get the configuration from the configuration
* property.
*
* @param $name
* @return mixed
*/
public function __get(string $name)
{
return $this->configuration->$name;
}
/**
* @param string $name
* @param string $value
* @return string
*/
public function __set(string $name, string $value)
{
return $this->configuration->$name = $value;
}
}