Completed
Push — master ( 5fbb23...fd922b )
by Henri
123:35 queued 114:54
created

GlobalConfig::getConstant()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 7
rs 9.4285
cc 3
eloc 4
nc 2
nop 2
1
<?php
2
3
/**
4
 * GlobalConfig provides access to the Skosmos configuration in config.inc.
5
 */
6
class GlobalConfig {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
    private $languages;
8
9
    public function __construct($config_name='/../config.inc') 
10
    {
11
        try {
12
            $file_path = dirname(__FILE__) . $config_name;
13
            if (!file_exists($file_path)) {
14
                throw new Exception('config.inc file is missing, please provide one.');
15
            }
16
            require_once($file_path);
17
            if (isset($LANGUAGES)) {
1 ignored issue
show
Bug introduced by
The variable $LANGUAGES seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
18
                $this->languages = $LANGUAGES;
19
            }
20
        } catch (Exception $e) {
21
            echo "Error: " . $e->getMessage();
22
            return;
23
        }
24
    }
25
    
26
    private function getConstant($name, $default)
27
    {
28
        if (defined($name) && constant($name)) {
29
            return constant($name);
30
        }
31
        return $default;
32
    }
33
34
    /**
35
     * Returns the UI languages specified in the configuration or defaults to
36
     * only show English
37
     * @return array 
38
     */
39
    public function getLanguages() 
40
    {
41
        if ($this->languages) {
42
            return $this->languages;
43
        }
44
        return array('en' => 'en_GB.utf8');
45
    }
46
    
47
    /**
48
     * Returns the vocabulary configuration file specified the configuration
49
     * or vocabularies.ttl if not found.
50
     * @return string
51
     */
52
    public function getVocabularyConfigFile() 
53
    {
54
        return $this->getConstant('VOCABULARIES_FILE', 'vocabularies.ttl');
55
    }
56
    
57
    /**
58
     * Returns the external HTTP request timeout in seconds or the default value
59
     * of 5 seconds if not specified in the configuration.
60
     * @return integer
61
     */
62
    public function getHttpTimeout() 
63
    {
64
        return $this->getConstant('HTTP_TIMEOUT', 5);
65
    }
66
    
67
    /**
68
     * Returns the sparql endpoint address defined in the configuration. If
69
     * not then defaulting to http://localhost:3030/ds/sparql 
70
     * @return string
71
     */
72
    public function getDefaultEndpoint() 
73
    {
74
        return $this->getConstant('DEFAULT_ENDPOINT', 'http://localhost:3030/ds/sparql');
75
    }
76
    
77
    /**
78
     * @return string
79
     */
80
    public function getSparqlGraphStore() 
81
    {
82
        return $this->getConstant('SPARQL_GRAPH_STORE', null);
83
    }
84
    
85
    /**
86
     * Returns the maximum number of items to return in transitive queries if defined
87
     * in the configuration or the default value of 1000.
88
     * @return integer 
89
     */
90
    public function getDefaultTransitiveLimit() 
91
    {
92
        return $this->getConstant('DEFAULT_TRANSITIVE_LIMIT', 1000);
93
    }
94
    
95
    /**
96
     * Returns the maximum number of items to return in search queries if defined
97
     * in the configuration or the default value of 100.
98
     * @return integer 
99
     */
100
    public function getDefaultSearchLimit() 
101
    {
102
        return $this->getConstant('DEFAULT_SEARCH_LIMIT', 100);
103
    }
104
    
105
    /**
106
     * Returns the configured location for the twig template cache and if not
107
     * defined defaults to "/tmp/skosmos-template-cache"
108
     * @return string
109
     */
110
    public function getTemplateCache() 
111
    {
112
        return $this->getConstant('TEMPLATE_CACHE', '/tmp/skosmos-template-cache');
113
    }
114
    
115
    /**
116
     * Returns the defined sparql-query extension eg. "JenaText" or 
117
     * if not defined falling back to SPARQL 1.1
118
     * @return string
119
     */
120
    public function getDefaultSparqlDialect() 
121
    {
122
        return $this->getConstant('DEFAULT_SPARQL_DIALECT', 'Generic');
123
    }
124
125
    /**
126
     * Returns the feedback address defined in the configuration.
127
     * @return string
128
     */
129
    public function getFeedbackAddress() 
130
    {
131
        return $this->getConstant('FEEDBACK_ADDRESS', null);
132
    }
133
    
134
    /**
135
     * Returns true if exception logging has been configured.
136
     * @return boolean 
137
     */
138
    public function getLogCaughtExceptions() 
139
    {
140
        return $this->getConstant('LOG_CAUGHT_EXCEPTIONS', FALSE);
141
    }
142
    
143
    /**
144
     * @return string
145
     */
146
    public function getServiceName() 
147
    {
148
        return $this->getConstant('SERVICE_NAME', 'Skosmos');
149
    }
150
    
151
    /**
152
     * @return string
153
     */
154
    public function getServiceTagline() 
155
    {
156
        return $this->getConstant('SERVICE_TAGLINE', null);
157
    }
158
    
159
    /**
160
     * @return string
161
     */
162
    public function getServiceLogo() 
163
    {
164
        return $this->getConstant('SERVICE_LOGO', null);
165
    }
166
    
167
    /**
168
     * @return string
169
     */
170
    public function getCustomCss() 
171
    {
172
        return $this->getConstant('CUSTOM_CSS', null);
173
    }
174
    
175
    /**
176
     * @return boolean
177
     */
178
    public function getUiLanguageDropdown() 
179
    {
180
        return $this->getConstant('UI_LANGUAGE_DROPDOWN', FALSE);
181
    }
182
    
183
    /**
184
     * @return string
185
     */
186
    public function getBaseHref() 
187
    {
188
        return $this->getConstant('BASE_HREF', null);
189
    }
190
}
191