@@ -30,13 +30,26 @@ class GlobalConfig extends BaseConfig {
3030 */
3131 private $ configModifiedTime = null ;
3232
33+ const HTTP_URL_PREFIX = 'http:// ' ;
34+ const HTTPS_URL_PREFIX = 'https:// ' ;
35+
3336 public function __construct ($ config_name ='/../config.ttl ' )
3437 {
38+ // if present, use value from env instead
39+ $ config_name_env = getenv ('SKOSMOS_CONFIG ' );
40+ if ($ config_name_env ) {
41+ $ config_name = $ config_name_env ;
42+ }
43+
3544 $ this ->cache = new Cache ();
3645 try {
37- $ this ->filePath = realpath ( dirname (__FILE__ ) . $ config_name );
38- if (!file_exists ($ this ->filePath )) {
39- throw new Exception ('config.ttl file is missing, please provide one. ' );
46+ if (str_starts_with ($ config_name , self ::HTTP_URL_PREFIX ) || str_starts_with ($ config_name , self ::HTTPS_URL_PREFIX )) {
47+ $ this ->filePath = $ config_name ;
48+ } else {
49+ $ this ->filePath = realpath ( dirname (__FILE__ ) . $ config_name );
50+ if (!file_exists ($ this ->filePath )) {
51+ throw new Exception ($ config_name . ' is missing, please provide a config.ttl. ' );
52+ }
4053 }
4154 $ this ->initializeConfig ();
4255 } catch (Exception $ e ) {
@@ -66,10 +79,12 @@ public function getConfigModifiedTime()
6679 private function initializeConfig ()
6780 {
6881 try {
69- // retrieve last modified time for config file (filemtime returns int|bool!)
70- $ configModifiedTime = filemtime ($ this ->filePath );
71- if (!is_bool ($ configModifiedTime )) {
72- $ this ->configModifiedTime = $ configModifiedTime ;
82+ if (!str_starts_with ($ this ->filePath , self ::HTTP_URL_PREFIX ) && !str_starts_with ($ this ->filePath , self ::HTTPS_URL_PREFIX )) {
83+ // retrieve last modified time for config file (filemtime returns int|bool!)
84+ $ configModifiedTime = filemtime ($ this ->filePath );
85+ if (!is_bool ($ configModifiedTime )) {
86+ $ this ->configModifiedTime = $ configModifiedTime ;
87+ }
7388 }
7489 // use APC user cache to store parsed config.ttl configuration
7590 if ($ this ->cache ->isAvailable () && !is_null ($ this ->configModifiedTime )) {
@@ -107,9 +122,18 @@ private function initializeConfig()
107122 */
108123 private function parseConfig ($ filename )
109124 {
125+ if (str_starts_with ($ filename , self ::HTTP_URL_PREFIX ) || str_starts_with ($ filename , self ::HTTPS_URL_PREFIX )) {
126+ $ ch = curl_init ($ filename );
127+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
128+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , array ('Content-type: text/turtle ' ));
129+ $ contents = curl_exec ($ ch );
130+ curl_close ($ ch );
131+ } else {
132+ $ contents = file_get_contents ($ filename );
133+ }
110134 $ this ->graph = new EasyRdf \Graph ();
111135 $ parser = new SkosmosTurtleParser ();
112- $ parser ->parse ($ this ->graph , file_get_contents ( $ filename ) , 'turtle ' , $ filename );
136+ $ parser ->parse ($ this ->graph , $ contents , 'turtle ' , $ filename );
113137 $ this ->namespaces = $ parser ->getNamespaces ();
114138 }
115139
0 commit comments