Completed
Pull Request — develop (#129)
by Leo
13:46
created

Toml::getSupportedExtensions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Noodlehaus\Parser;
4
5
use Noodlehaus\Exception\ParseException;
6
use Yosymfony\Toml\Toml as TomlParser;
7
8
/**
9
 * TOML parser
10
 *
11
 * @package    Config
12
 * @author     Jesus A. Domingo <[email protected]>
13
 * @author     Hassan Khan <[email protected]>
14
 * @author     Filip Š <[email protected]>
15
 * @link       https://github.com/noodlehaus/config
16
 * @license    MIT
17
 */
18
class Toml implements ParserInterface
19
{
20
    /**
21
     * {@inheritDoc}
22
     */
23
    public static function getSupportedExtensions()
24
    {
25
        return ['toml'];
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     * Loads a TOML file as an array
31
     *
32
     * @throws ParseException If there is an error parsing the TOML file
33
     */
34
    public function parseFile($filename)
35
    {
36
        try {
37
            return TomlParser::parseFile($filename);
38
        } catch (\Exception $exception) {
39
            throw new ParseException(
40
                [
41
                    'message' => 'Error parsing TOML file',
42
                    'exception' => $exception,
43
                ]
44
            );
45
        }
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     * Loads a TOML string as an array
51
     *
52
     * @throws ParseException If there is an error parsing the TOML string
53
     */
54
    public function parseString($config)
55
    {
56
        try {
57
            return TomlParser::parse($config);
58
        } catch (\Exception $exception) {
59
            throw new ParseException(
60
                [
61
                    'message' => 'Error parsing TOML string',
62
                    'exception' => $exception,
63
                ]
64
            );
65
        }
66
    }
67
}