1 | <?php |
||
15 | final class Converter implements ConverterInterface |
||
16 | { |
||
17 | /** |
||
18 | * The key to search for in the INI file to find the browscap settings |
||
19 | */ |
||
20 | const BROWSCAP_VERSION_KEY = 'GJK_Browscap_Version'; |
||
21 | |||
22 | /** |
||
23 | * @var \Psr\Log\LoggerInterface |
||
24 | */ |
||
25 | private $logger = null; |
||
26 | |||
27 | /** |
||
28 | * The cache instance |
||
29 | * |
||
30 | * @var \BrowscapPHP\Cache\BrowscapCacheInterface |
||
31 | */ |
||
32 | private $cache = null; |
||
33 | |||
34 | /** |
||
35 | * a filesystem patternHelper instance |
||
36 | * |
||
37 | * @var Filesystem |
||
38 | */ |
||
39 | private $filessystem = null; |
||
40 | |||
41 | /** |
||
42 | * version of the ini file |
||
43 | * |
||
44 | * @var int |
||
45 | */ |
||
46 | private $iniVersion = 0; |
||
47 | |||
48 | /** |
||
49 | * Converter constructor. |
||
50 | * |
||
51 | * @param LoggerInterface $logger |
||
52 | * @param BrowscapCacheInterface $cache |
||
53 | */ |
||
54 | 6 | public function __construct(LoggerInterface $logger, BrowscapCacheInterface $cache) |
|
55 | { |
||
56 | 6 | $this->logger = $logger; |
|
57 | 6 | $this->cache = $cache; |
|
58 | 6 | } |
|
59 | |||
60 | /** |
||
61 | * Sets a filesystem instance |
||
62 | * |
||
63 | * @param Filesystem $file |
||
64 | */ |
||
65 | 6 | public function setFilesystem(Filesystem $file) : void |
|
66 | { |
||
67 | 6 | $this->filessystem = $file; |
|
68 | 6 | } |
|
69 | |||
70 | /** |
||
71 | * Returns a filesystem instance |
||
72 | * |
||
73 | * @return Filesystem |
||
74 | */ |
||
75 | 3 | public function getFilesystem() : Filesystem |
|
76 | { |
||
77 | 3 | if (null === $this->filessystem) { |
|
78 | 1 | $this->filessystem = new Filesystem(); |
|
79 | } |
||
80 | |||
81 | 3 | return $this->filessystem; |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * converts a file |
||
86 | * |
||
87 | * @param string $iniFile |
||
88 | * |
||
89 | * @throws FileNotFoundException |
||
90 | */ |
||
91 | 2 | public function convertFile(string $iniFile) : void |
|
105 | |||
106 | /** |
||
107 | * converts the string content |
||
108 | * |
||
109 | * @param string $iniString |
||
110 | */ |
||
111 | 2 | public function convertString(string $iniString) : void |
|
163 | |||
164 | /** |
||
165 | * Parses the ini data to get the version of loaded ini file |
||
166 | * |
||
167 | * @param string $iniString The loaded ini data |
||
168 | * |
||
169 | * @return int |
||
170 | */ |
||
171 | 1 | public function getIniVersion(string $iniString) : int |
|
184 | |||
185 | /** |
||
186 | * sets the version |
||
187 | * |
||
188 | * @param int $version |
||
189 | */ |
||
190 | public function setVersion(int $version) : void |
||
194 | |||
195 | /** |
||
196 | * stores the version of the ini file into cache |
||
197 | */ |
||
198 | public function storeVersion() : void |
||
206 | |||
207 | /** |
||
208 | * Parses the ini data to get the releaseDate of loaded ini file |
||
209 | * |
||
210 | * @param string $iniString The loaded ini data |
||
211 | * @return string|null |
||
212 | */ |
||
213 | 2 | private function getIniReleaseDate(string $iniString) : ?string |
|
223 | |||
224 | /** |
||
225 | * Parses the ini data to get the releaseDate of loaded ini file |
||
226 | * |
||
227 | * @param string $iniString The loaded ini data |
||
228 | * @return string|null |
||
229 | */ |
||
230 | 2 | private function getIniType(string $iniString) : ?string |
|
240 | } |
||
241 |