Completed
Push — master ( 8b32e3...0b7def )
by Henri
180:56 queued 157:51
created

GlobalConfig::getHttpTimeout()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
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
    /**
27
     * Returns the UI languages specified in the configuration or defaults to
28
     * only show English
29
     * @return array 
30
     */
31
    public function getLanguages() 
32
    {
33
        if ($this->languages) {
34
            return $this->languages;
35
        }
36
        return array('en' => 'en_GB.utf8');
37
    }
38
    
39
    /**
40
     * Returns the vocabulary configuration file specified the configuration
41
     * or vocabularies.ttl if not found.
42
     * @return string
43
     */
44
    public function getVocabularyConfigFile() 
45
    {
46
        if (defined('VOCABULARIES_FILE')) {
47
            return VOCABULARIES_FILE;
48
        }
49
        return 'vocabularies.ttl';
50
    }
51
    
52
    /**
53
     * Returns the external HTTP request timeout in seconds or the default value
54
     * of 5 seconds if not specified in the configuration.
55
     * @return integer
56
     */
57
    public function getHttpTimeout() 
58
    {
59
        if (defined('HTTP_TIMEOUT')) {
60
            return HTTP_TIMEOUT;
61
        }
62
        return 5;
63
    }
64
    
65
    /**
66
     * Returns the sparql endpoint address defined in the configuration. If
67
     * not then defaulting to http://localhost:3030/ds/sparql 
68
     * @return string
69
     */
70
    public function getDefaultEndpoint() 
71
    {
72
        if (defined('DEFAULT_ENDPOINT')) {
73
            return DEFAULT_ENDPOINT;
74
        }
75
        return 'http://localhost:3030/ds/sparql';
76
    }
77
    
78
    /**
79
     * @return string
80
     */
81
    public function getSparqlGraphStore() 
82
    {
83
        if (defined('SPARQL_GRAPH_STORE')) {
84
            return SPARQL_GRAPH_STORE;
85
        }
86
        return null;
87
    }
88
    
89
    /**
90
     * Returns the maximum number of items to return in transitive queries if defined
91
     * in the configuration or the default value of 1000.
92
     * @return integer 
93
     */
94
    public function getDefaultTransitiveLimit() 
95
    {
96
        if (defined('DEFAULT_TRANSITIVE_LIMIT')) {
97
            return DEFAULT_TRANSITIVE_LIMIT;
98
        }
99
        return 1000;
100
    }
101
    
102
    /**
103
     * Returns the maximum number of items to return in search queries if defined
104
     * in the configuration or the default value of 100.
105
     * @return integer 
106
     */
107
    public function getDefaultSearchLimit() 
108
    {
109
        if (defined('DEFAULT_SEARCH_LIMIT')) {
110
            return DEFAULT_SEARCH_LIMIT;
111
        }
112
        return 100;
113
    }
114
    
115
    /**
116
     * Returns the configured location for the twig template cache and if not
117
     * defined defaults to "/tmp/skosmos-template-cache"
118
     * @return string
119
     */
120
    public function getTemplateCache() 
121
    {
122
        if (defined('TEMPLATE_CACHE')) {
123
            return TEMPLATE_CACHE;
124
        }
125
        return '/tmp/skosmos-template-cache';
126
    }
127
    
128
    /**
129
     * Returns the defined sparql-query extension eg. "JenaText" or 
130
     * if not defined falling back to SPARQL 1.1
131
     * @return string
132
     */
133
    public function getDefaultSparqlDialect() 
134
    {
135
        if (defined('DEFAULT_SPARQL_DIALECT')) {
136
            return DEFAULT_SPARQL_DIALECT;
137
        }
138
        return 'Generic';
139
    }
140
141
    /**
142
     * Returns the feedback address defined in the configuration.
143
     * @return string
144
     */
145
    public function getFeedbackAddress() 
146
    {
147
        if (defined('FEEDBACK_ADDRESS')) {
148
            return FEEDBACK_ADDRESS;
149
        }
150
        return null;
151
    }
152
    
153
    /**
154
     * Returns true if exception logging has been configured.
155
     * @return boolean 
156
     */
157
    public function getLogCaughtExceptions() 
158
    {
159
        if (defined('LOG_CAUGHT_EXCEPTIONS')) {
160
            return LOG_CAUGHT_EXCEPTIONS;
161
        }
162
        return FALSE;
163
    }
164
    
165
    /**
166
     * @return string
167
     */
168
    public function getServiceName() 
169
    {
170
        if (defined('SERVICE_NAME')) {
171
            return SERVICE_NAME;
172
        }
173
        return 'Skosmos';
174
    }
175
    
176
    /**
177
     * @return string
178
     */
179
    public function getServiceTagline() 
180
    {
181
        if (defined('SERVICE_TAGLINE')) {
182
            return SERVICE_TAGLINE;
183
        }
184
        return null;
185
    }
186
    
187
    /**
188
     * @return string
189
     */
190
    public function getServiceLogo() 
191
    {
192
        if (defined('SERVICE_LOGO')) {
193
            return SERVICE_LOGO;
194
        }
195
        return null;
196
    }
197
    
198
    /**
199
     * @return string
200
     */
201
    public function getCustomCss() 
202
    {
203
        if (defined('CUSTOM_CSS')) {
204
            return CUSTOM_CSS;
205
        }
206
        return null;
207
    }
208
    
209
    /**
210
     * @return boolean
211
     */
212
    public function getUiLanguageDropdown() 
213
    {
214
        if (defined('UI_LANGUAGE_DROPDOWN')) {
215
            return UI_LANGUAGE_DROPDOWN;
216
        }
217
        return FALSE;
218
    }
219
    
220
    /**
221
     * @return string
222
     */
223
    public function getBaseHref() 
224
    {
225
        if (defined('BASE_HREF')) {
226
            return BASE_HREF;
227
        }
228
        return null;
229
    }
230
}
231