Intraface_Shared::addPreloadFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
/**
3
 * Shared components
4
 *
5
 * @author Sune Jensen <[email protected]>
6
 * @example SharedExample.php
7
 */
8
class Intraface_Shared
9
{
10
    protected $active;
11
    protected $preload_file = array();
12
    protected $shared_name;
13
    protected $setting;
14
    protected $controlpanel_files;
15
    protected $frontpage_files; // til brug p� forsiden
16
    protected $translation;
17
18
    public function __construct()
19
    {
20
        // init
21
        $this->shared_name = '';
22
        $this->active = 0;
23
    }
24
25
    /**
26
     * Is run by kernel when loading a shared module
27
     */
28 63
    public function load()
29
    {
30
        // Inkluder preload filerne
31 63
        for ($i = 0, $max = count($this->preload_file); $i<$max; $i++) {
32 63
            $this->includeFile($this->preload_file[$i]);
33 63
        }
34 63
    }
35
36
    /**
37
     * Denne funktion bruges af SharedNavn.php til at fort�lle, hvor includefilen til
38
   * det enkelte modul ligger.
39
     */
40
    function addFrontpageFile($filename)
41
    {
42
        $this->frontpage_files[] = $filename;
43
    }
44
45
    function getFrontpageFiles()
46
    {
47
        return $this->frontpage_files;
48
    }
49
50
    function addControlpanelFile($title, $url)
51
    {
52
        $this->controlpanel_files[] = array(
53
            'title' => $title,
54
            'url' => $url
55
        );
56
    }
57
58
    function getControlpanelFiles()
59
    {
60
        return $this->controlpanel_files;
61
    }
62
63 63
    function addPreloadFile($file)
64
    {
65 63
        $this->preload_file[] = $file;
66 63
    }
67
68
    /**
69
     * Bruges til at inkludere fil
70
     *
71
     * @todo why is this not using getPath?
72
     */
73 63
    function includeFile($file)
74
    {
75 63
        $file = dirname(__FILE__) . '/shared/' . $this->shared_name . '/' . $file;
76 63
        if (!file_exists($file)) {
77
            return 0;
78
        }
79 63
        require_once($file);
80 63
        return 1;
81
    }
82
83
    /**
84
     * @todo why is this not using getPath()
85
     */
86 32
    function includeSettingFile($file)
87
    {
88 32
        global $_setting; // this is also globalized other places
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
89 32
        require(PATH_INCLUDE_SHARED . $this->shared_name . '/' . $file);
90 32
    }
91
92
    /**
93
     * Returns the www path for the shared modules; always ends on a slash
94
     *
95
     * @return string
96
     */
97
    public function getPath()
98
    {
99
        return url('/shared/' . $this->shared_name) . '/';
100
    }
101
102
    /**
103
     * Bruges til at tilf�je en setting til et modul, som skal v�re hardcoded ind i Main[Modulnavn]
104
     */
105
    function addSetting($key, $value)
106
    {
107
        $this->setting[$key] = $value;
108
    }
109
110
    function getSetting($key)
111
    {
112
        if (isset($this->setting[$key])) {
113
            return($this->setting[$key]);
114
        }
115
    }
116
}
117