1 | <?php |
||
5 | class Parser |
||
6 | { |
||
7 | /** |
||
8 | * parsed content of the dotenv file |
||
9 | */ |
||
10 | private $content = []; |
||
11 | |||
12 | /** |
||
13 | * Which parsing style is used |
||
14 | * |
||
15 | * @see http://php.net/parse_ini_file |
||
16 | */ |
||
17 | private $scannerMode; |
||
18 | |||
19 | /** |
||
20 | * Set the default parsing style |
||
21 | */ |
||
22 | 39 | public function __construct() |
|
34 | |||
35 | /** |
||
36 | * Set the scanner_mode used by the parse_ini_file function |
||
37 | */ |
||
38 | 39 | public function setScannerMode($scannerMode) |
|
42 | |||
43 | /** |
||
44 | * parse the .env file |
||
45 | * |
||
46 | * @param string $file file to parse |
||
47 | * |
||
48 | * @return string Returns the phrase passed in |
||
49 | */ |
||
50 | 39 | public function parse($file) |
|
51 | { |
||
52 | try { |
||
53 | 39 | $this->content = parse_ini_string( |
|
54 | 26 | file_get_contents($file), |
|
55 | 39 | false, |
|
56 | 39 | $this->scannerMode |
|
57 | 26 | ); |
|
58 | 28 | } catch (\Exception $e) { |
|
59 | 6 | throw new Exception\ParseException($e); |
|
60 | } |
||
61 | |||
62 | 33 | return $this; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * Transforme the boolean used as string in the env file to real boolean |
||
67 | */ |
||
68 | public function sanitizeValues() |
||
79 | |||
80 | /** |
||
81 | * Return the parsed content |
||
82 | * |
||
83 | * @return array content |
||
84 | */ |
||
85 | 33 | public function getContent() |
|
89 | } |
||
90 |