Completed
Push — master ( 6fb51e...94364b )
by Thierry
01:40
created

Yaml   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A read() 0 19 4
1
<?php
2
3
/**
4
 * Yaml.php - Jaxon config reader
5
 *
6
 * Read the config data from a YAML formatted config file.
7
 *
8
 * @package jaxon-core
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2016 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
14
15
namespace Jaxon\Config;
16
17
class Yaml
18
{
19
    /**
20
     * Read options from a YAML formatted config file
21
     *
22
     * @param string        $sConfigFile        The full path to the config file
23
     *
24
     * @return array
25
     */
26
    public static function read($sConfigFile)
27
    {
28
        $sConfigFile = realpath($sConfigFile);
29
        if(!extension_loaded('yaml'))
30
        {
31
            throw new \Jaxon\Config\Exception\Yaml(jaxon_trans('config.errors.yaml.install'));
32
        }
33
        if(!is_readable($sConfigFile))
34
        {
35
            throw new \Jaxon\Config\Exception\File(jaxon_trans('config.errors.file.access', array('path' => $sConfigFile)));
36
        }
37
        $aConfigOptions = yaml_parse_file($sConfigFile);
38
        if(!is_array($aConfigOptions))
39
        {
40
            throw new \Jaxon\Config\Exception\File(jaxon_trans('config.errors.file.content', array('path' => $sConfigFile)));
41
        }
42
43
        return $aConfigOptions;
44
    }
45
}
46