forked from machbarmacher/gdpr-dump
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfigParser.php
54 lines (46 loc) · 1.1 KB
/
ConfigParser.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
<?php
namespace machbarmacher\GdprDump;
use bomoko\MysqlCnfParser\MysqlCnfParser;
/**
* Class ConfParser
*
* Parses key/value lines from mysql .cnf files.
*
* @package machbarmacher\GdprDump
*/
class ConfigParser
{
/** @var array */
private $config = [];
/**
* @return array
*/
public function getConfig()
{
return $this->config;
}
public function getFiltered($sections, $keys = null)
{
$result = [];
foreach ($this->config as $section => $values) {
foreach ($values as $key => $value) {
if (in_array($section,
$sections) && (!isset($keys) || in_array($key, $keys))
) {
$result[$key] = $value;
}
}
}
return $result;
}
/**
* Takes a .cnf file and adds its configuration settings to internal state
*
* @param $file
*/
public function addFile($file)
{
$sections = MysqlCnfParser::parse($file);
$this->config = array_replace_recursive($this->config, $sections);
}
}