Completed
Push — master ( 665577...6c1e3b )
by Mikael
02:27
created

TLoadFile   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 3
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A loadFile() 0 14 3
1
<?php
2
3
namespace Anax;
4
5
/**
6
 * Trait implementing reading from config-file and storing options in
7
 * $this->config.
8
 *
9
 */
10
trait TLoadFile
11
{
12
    /**
13
     * Load config file from ANAX_APP_PATH or ANAX_INSTALL_PATH.
14
     *
15
     * @param string $filename to load.
16
     * @param array  $expose   array with variables to expose to included file,
17
     *                         defaults to en empty array.
18
     *
19
     * @throws Exception when $filename is not found.
20
     *
21
     * @return mixed from returned value in required file.
22
     */
23
    public function loadFile($filename, $expose = [])
24
    {
25
        $anaxInstallPath = ANAX_INSTALL_PATH . "/config/$filename";
26
        $anaxAppPath = ANAX_APP_PATH . "/config/$filename";
27
        extract($expose);
28
29
        if (is_readable($anaxAppPath)) {
30
            return require $anaxAppPath;
31
        } elseif (is_readable($anaxInstallPath)) {
32
            return require $anaxInstallPath;
33
        }
34
35
        throw new Exception("Configure item '$filename' is not a readable file.");
36
    }
37
}
38