Completed
Push — master ( 2254e1...62d7c6 )
by Henri
02:48
created

GlobalConfig::getSparqlGraphStore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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)) {
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 HTTP request timeout in seconds or the default value
69
     * of 20 seconds if not specified in the configuration.
70
     * @return integer
71
     */
72
    public function getSparqlTimeout() 
73
    {
74
        return $this->getConstant('SPARQL_TIMEOUT', 20);
75
    }
76
    
77
    /**
78
     * Returns the sparql endpoint address defined in the configuration. If
79
     * not then defaulting to http://localhost:3030/ds/sparql 
80
     * @return string
81
     */
82
    public function getDefaultEndpoint() 
83
    {
84
        return $this->getConstant('DEFAULT_ENDPOINT', 'http://localhost:3030/ds/sparql');
85
    }
86
    
87
    /**
88
     * @return string
89
     */
90
    public function getSparqlGraphStore() 
91
    {
92
        return $this->getConstant('SPARQL_GRAPH_STORE', null);
93
    }
94
    
95
    /**
96
     * Returns the maximum number of items to return in transitive queries if defined
97
     * in the configuration or the default value of 1000.
98
     * @return integer 
99
     */
100
    public function getDefaultTransitiveLimit() 
101
    {
102
        return $this->getConstant('DEFAULT_TRANSITIVE_LIMIT', 1000);
103
    }
104
    
105
    /**
106
     * Returns the maximum number of items to load at a time if defined
107
     * in the configuration or the default value of 20.
108
     * @return integer 
109
     */
110
    public function getSearchResultsSize() 
111
    {
112
        return $this->getConstant('SEARCH_RESULTS_SIZE', 20);
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
        return $this->getConstant('TEMPLATE_CACHE', '/tmp/skosmos-template-cache');
123
    }
124
    
125
    /**
126
     * Returns the defined sparql-query extension eg. "JenaText" or 
127
     * if not defined falling back to SPARQL 1.1
128
     * @return string
129
     */
130
    public function getDefaultSparqlDialect() 
131
    {
132
        return $this->getConstant('DEFAULT_SPARQL_DIALECT', 'Generic');
133
    }
134
135
    /**
136
     * Returns the feedback address defined in the configuration.
137
     * @return string
138
     */
139
    public function getFeedbackAddress() 
140
    {
141
        return $this->getConstant('FEEDBACK_ADDRESS', null);
142
    }
143
    
144
    /**
145
     * Returns true if exception logging has been configured.
146
     * @return boolean 
147
     */
148
    public function getLogCaughtExceptions() 
149
    {
150
        return $this->getConstant('LOG_CAUGHT_EXCEPTIONS', FALSE);
151
    }
152
    
153
    /**
154
     * Returns true if browser console logging has been enabled,
155
     * @return boolean
156
     */
157
    public function getLoggingBrowserConsole()
158
    {
159
        return $this->getConstant('LOG_BROWSER_CONSOLE', FALSE);
160
    }
161
162
    /**
163
     * Returns the name of a log file if configured, or NULL otherwise.
164
     * @return string
165
     */
166
    public function getLoggingFilename()
167
    {
168
        return $this->getConstant('LOG_FILE_NAME', null);
169
    }
170
171
    /**
172
     * @return string
173
     */
174
    public function getServiceName() 
175
    {
176
        return $this->getConstant('SERVICE_NAME', 'Skosmos');
177
    }
178
    
179
    /**
180
     * @return string
181
     */
182
    public function getServiceTagline() 
183
    {
184
        return $this->getConstant('SERVICE_TAGLINE', null);
185
    }
186
    
187
    /**
188
     * @return string
189
     */
190
    public function getServiceLogo() 
191
    {
192
        return $this->getConstant('SERVICE_LOGO', null);
193
    }
194
    
195
    /**
196
     * @return string
197
     */
198
    public function getCustomCss() 
199
    {
200
        return $this->getConstant('CUSTOM_CSS', null);
201
    }
202
    
203
    /**
204
     * @return boolean
205
     */
206
    public function getUiLanguageDropdown() 
207
    {
208
        return $this->getConstant('UI_LANGUAGE_DROPDOWN', FALSE);
209
    }
210
    
211
    /**
212
     * @return string
213
     */
214
    public function getBaseHref() 
215
    {
216
        return $this->getConstant('BASE_HREF', null);
217
    }
218
    
219
    /**
220
     * @return string
221
     */
222
    public function getGlobalPlugins() 
223
    {
224
        return explode(' ', $this->getConstant('GLOBAL_PLUGINS', null));
225
    }
226
    
227
    /**
228
     * @return boolean
229
     */
230
    public function getHoneypotEnabled()
231
    {
232
        return $this->getConstant('UI_HONEYPOT_ENABLED', TRUE);
233
    }
234
235
    /**
236
     * @return integer
237
     */
238
    public function getHoneypotTime()
239
    {
240
        return $this->getConstant('UI_HONEYPOT_TIME', 5);
241
    }
242
    
243
}
244