• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aplus-framework / config / 10034566442

28 Jun 2024 10:04PM UTC coverage: 100.0%. Remained the same
10034566442

push

github

natanfelles
Merge branch 'refs/heads/4.x' into development

206 of 206 relevant lines covered (100.0%)

2.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/Parsers/EnvParser.php
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of Aplus Framework Config Library.
4
 *
5
 * (c) Natan Felles <natanfelles@gmail.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Framework\Config\Parsers;
11

12
/**
13
 * Class EnvParser.
14
 *
15
 * @package config
16
 */
17
class EnvParser extends Parser
18
{
19
    /**
20
     * Parses an .ENV file.
21
     *
22
     * @param mixed $config Path to the .ENV file.
23
     *
24
     * @throws ParserException
25
     *
26
     * @return array<mixed> The .ENV parsed data
27
     */
28
    public static function parse(mixed $config) : array
29
    {
30
        static::checkConfig($config);
1✔
31
        return static::parseOrThrow(static function () use ($config) : array {
1✔
32
            $contents = \file_get_contents($config);
1✔
33
            $contents = \explode(\PHP_EOL, $contents); // @phpstan-ignore-line
1✔
34
            $data = [];
1✔
35
            foreach ($contents as $line) {
1✔
36
                $line = \trim($line);
1✔
37
                if ($line === '' || \str_starts_with($line, '#')) {
1✔
38
                    continue;
1✔
39
                }
40
                [$key, $value] = \explode('=', $line, 2);
1✔
41
                $key = \trim($key);
1✔
42
                $key = \explode('.', $key);
1✔
43
                $value = static::getValue($value);
1✔
44
                $parent = [];
1✔
45
                static::addChild($parent, $key, $value);
1✔
46
                $data = \array_replace_recursive($data, $parent);
1✔
47
            }
48
            return static::ksortRecursive($data);
1✔
49
        });
1✔
50
    }
51
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc