/
App.php
1235 lines (1062 loc) · 38 KB
/
App.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* This file is part of the {@link http://erfurt-framework.org Erfurt} project.
*
* @copyright Copyright (c) 2012, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
/**
* The Erfurt application class.
*
* This class acts as the central class of an Erfurt application.
* It provides access to a large number of objects that provide functionality an
* application may use. It's also the place where an Erfurt application gets started
* and initialized.
*
* @category Erfurt
* @package Erfurt
* @author Philipp Frischmuth <pfrischmuth@googlemail.com>
*/
class Erfurt_App
{
static $httpAdapter = null;
// ------------------------------------------------------------------------
// --- Class constants ----------------------------------------------------
// ------------------------------------------------------------------------
/**
* Constant that contains the minimum required php version.
* @var string
*/
const EF_MIN_PHP_VERSION = '5.2.0';
/**
* Constant that contains the minimum required zend framework version.
* @var string
*/
const EF_MIN_ZEND_VERSION = '1.5.0';
// ------------------------------------------------------------------------
// --- Private properties -------------------------------------------------
// ------------------------------------------------------------------------
/**
* The instance of this class which is returned on request, for this class
* acts as a singleton.
*
* @var Erfurt_App
*/
private static $_instance = null;
/**
* Contains an instance of the Erfurt access control class.
* @var Erfurt_Ac_Default
*/
private $_ac = null;
/**
* Contains an instanciated access control model.
* @var Erfurt_Rdf_Model
*/
private $_acModel = null;
private $_acModelUri = null;
/**
* Contains a reference to Zend_Auth singleton.
*/
private $_auth = null;
/**
* Contains the cache object.
* @var Zend_Cache_Core
*/
private $_cache = null;
/**
* Contains the cache backend.
* @var Zend_Cache_Backend
*/
private $_cacheBackend = null;
/**
* Contains an instance of the configuration object.
* @var Zend_Config
*/
private $_config = null;
/**
* Holds whether app was started.
* @var boolean
*/
private $_isStarted = false;
/**
* Contains an array of Zend_Log instances.
* @var array
*/
private $_logObjects = array();
/**
* Namespace management module
* @var Erfurt_Namespaces
*/
protected $_namespaces = null;
/**
* Contains an instance of the Erfurt plugin manager.
* @var Erfurt_Plugin_Manager
*/
private $_pluginManager = null;
/**
* Contains the query cache object.
* @var Erfurt_Cache_Frontend_QueryCache
*/
private $_queryCache = null;
/**
* Contains the query cache backend.
* @var Erfurt_Cache_Backend_QueryCache_Backend
*/
private $_queryCacheBackend = null;
/**
* Contains an instance of the store.
* @var Erfurt_Store
*/
private $_store = null;
/**
* Contains an instanciated system ontology model.
* @var Erfurt_Rdf_Model
*/
private $_sysOntModel = null;
/**
* Contains an instance of the Erfurt versioning class.
* @var Erfurt_Versioning
*/
private $_versioning = null;
/**
* Contains an instance of the Erfurt wrapper manager.
* @var Erfurt_Wrapper_Manager
*/
private $_wrapperManager = null;
// ------------------------------------------------------------------------
// --- Magic methods ------------------------------------------------------
// ------------------------------------------------------------------------
/**
* The constructor of this class.
*
* @throws Erfurt_Exception Throws an exception if wrong PHP or wrong Zend
* Framework version is used.
*/
private function __construct()
{
// Check the PHP version.
if (!version_compare(self::_getPhpVersion(), self::EF_MIN_PHP_VERSION, '>=')) {
throw new Erfurt_Exception('Erfurt requires at least PHP version ' . self::EF_MIN_PHP_VERSION);
}
// Check whether Zend is loaded with the right version.
if (!version_compare(self::_getZendVersion(), self::EF_MIN_ZEND_VERSION, '>=')) {
throw new Erfurt_Exception(
'Erfurt requires at least Zend Framework in version ' . self::EF_MIN_ZEND_VERSION
);
}
// Define Erfurt base constant.
if (!defined('EF_BASE')) {
define('EF_BASE', rtrim(dirname(__FILE__), '\\/') . '/');
}
// Include the vocabulary file.
require_once EF_BASE . 'include/vocabulary.php';
}
// ------------------------------------------------------------------------
// --- Public methods -----------------------------------------------------
// ------------------------------------------------------------------------
/**
* Returns the instance of this class.
*
* @param boolean $autoStart Whether the application should be started automatically
* when this method is called the first time. If this parameter is set to false, an
* application needs to call the start method explicit.
* @return Erfurt_App
*/
public static function getInstance($autoStart = true)
{
if (null === self::$_instance) {
self::$_instance = new Erfurt_App();
if ($autoStart === true) {
self::$_instance->start();
}
}
return self::$_instance;
}
public static function reset()
{
self::$_instance = null;
}
/**
* Starts the application, which initializes it.
*
* @param Zend_Config|null $config An optional config object that will be merged with
* the Erfurt config.
*
* @return Erfurt_App
* @throws Erfurt_Exception Throws an exception if the connection to the backend server fails.
*/
public function start(Zend_Config $config = null)
{
// If already started just return the object.
if ($this->_isStarted === true) {
return $this;
}
// Stop the time for debugging purposes.
$start = microtime(true);
// Load the configuration first.
$this->loadConfig($config);
// Check for debug mode.
$config = $this->getConfig();
if ((boolean)$config->debug === true) {
error_reporting(E_ALL | E_STRICT);
if (!defined('_EFDEBUG')) {
define('_EFDEBUG', 1);
}
// In debug mode log level is set to the highest value automatically.
$config->log->level = 7;
}
// Set the configured time zone.
if (isset($config->timezone) && ((boolean)$config->timezone !== false)) {
date_default_timezone_set($config->timezone);
} else {
date_default_timezone_set('Europe/Berlin');
}
// Starting Versioning
try {
$versioning = $this->getVersioning();
if ($versioning instanceof Erfurt_Versioning) {
if ((bool)$config->versioning === true) {
$versioning->enableVersioning(true);
} else {
$versioning->enableVersioning(false);
}
}
} catch (Erfurt_Exception $e) {
require_once 'Erfurt/Exception.php';
throw new Erfurt_Exception($e->getMessage());
}
// Write time to the log, if enabled.
$time = (microtime(true) - $start)*1000;
$this->getLog()->debug('Erfurt_App started in ' . $time . ' ms.');
$this->_isStarted = true;
return $this;
}
/**
* Adds a new OpenID user to the store.
*
* @param string $openid
* @param string $email
* @param string $label
* @param string|null $group
* @return boolean
*/
public function addOpenIdUser($openid, $email = '', $label = '', $group = '')
{
$acModel = $this->getAcModel();
$acModelUri = $acModel->getModelUri();
$store = $acModel->getStore();
$userUri = urldecode($openid);
// uri rdf:type sioc:User
$store->addStatement(
$acModelUri,
$userUri,
EF_RDF_TYPE,
array(
'value' => $this->_config->ac->user->class,
'type' => 'uri'
),
false
);
if (!empty($email)) {
// Check whether email already starts with mailto:
if (substr($email, 0, 7) !== 'mailto:') {
$email = 'mailto:' . $email;
}
// uri sioc:mailbox email
$store->addStatement(
$acModelUri,
$userUri,
$this->_config->ac->user->mail,
array(
'value' => $email,
'type' => 'uri'
),
false
);
}
if (!empty($label)) {
// uri rdfs:label $label
$store->addStatement(
$acModelUri,
$userUri,
EF_RDFS_LABEL,
array(
'value' => $label,
'type' => 'literal'
),
false
);
}
if (!empty($group)) {
$store->addStatement(
$acModelUri,
$group,
$this->_config->ac->group->membership,
array(
'value' => $userUri,
'type' => 'uri'
),
false
);
}
return true;
}
/**
* Adds a new user to the store.
*
* @param string $username
* @param string $password
* @param string $email
* @param string|null $userGroupUri
* @return boolean
*/
public function addUser($username, $password, $email, $userGroupUri = '')
{
$acModel = $this->getAcModel();
$acModelUri = $acModel->getModelUri();
$store = $acModel->getStore();
$userUri = $acModelUri . urlencode($username);
$store->addStatement(
$acModelUri,
$userUri,
EF_RDF_TYPE,
array(
'value' => $this->_config->ac->user->class,
'type' => 'uri'
),
false
);
$store->addStatement(
$acModelUri,
$userUri,
$this->_config->ac->user->name,
array(
'value' => $username,
'type' => 'literal',
'datatype' => EF_XSD_NS . 'string'
),
false
);
// Check whether email already starts with mailto:
if (substr($email, 0, 7) !== 'mailto:') {
$email = 'mailto:' . $email;
}
$store->addStatement(
$acModelUri,
$userUri,
$this->_config->ac->user->mail,
array(
'value' => $email,
'type' => 'uri'
),
false
);
$store->addStatement(
$acModelUri,
$userUri,
$this->_config->ac->user->pass,
array(
'value' => sha1($password),
'type' => 'literal'
),
false
);
if (!empty($userGroupUri)) {
$store->addStatement(
$acModelUri,
$userGroupUri,
$this->_config->ac->group->membership,
array(
'value' => $userUri,
'type' => 'uri'
),
false
);
}
return true;
}
/**
* Authenticates a user with a given username and password.
*
* @param string $username
* @param string $password
* @return Zend_Auth_Result
*/
public function authenticate($username = 'Anonymous', $password = '')
{
// Set up the authentication adapter.
$config = $this->getConfig();
$type = strtolower($config->ac->type);
$adapter = null;
if ($type === 'rdf') {
require_once 'Erfurt/Auth/Adapter/Rdf.php';
$adapter = new Erfurt_Auth_Adapter_Rdf($username, $password);
} else if ($type === 'none') {
require_once 'Erfurt/Auth/Adapter/None.php';
$adapter = new Erfurt_Auth_Adapter_None($username, $password);
} else {
require_once 'Erfurt/Exception.php';
throw new Erfurt_Exception("Auth type '$type' not supported");
}
// Attempt authentication, saving the result.
$result = $this->getAuth()->authenticate($adapter);
// If the result is not valid, make sure the identity is cleared.
if (!$result->isValid()) {
$this->getAuth()->clearIdentity();
}
return $result;
}
public function authenticateWithFoafSsl($get = null, $redirectUrl = null)
{
// Set up the authentication adapter.
require_once 'Erfurt/Auth/Adapter/FoafSsl.php';
$adapter = new Erfurt_Auth_Adapter_FoafSsl($get, $redirectUrl);
// Attempt authentication, saving the result.
$result = $this->getAuth()->authenticate($adapter);
// If the result is not valid, make sure the identity is cleared.
if (!$result->isValid()) {
$this->getAuth()->clearIdentity();
}
return $result;
}
/**
* The second step of the OpenID authentication process.
* Authenticates a user with a given OpenID. On success this
* method will not return but instead redirect the user to the
* specified URL.
*
* @param string $openId
* @param string $redirectUrl
* @return Zend_Auth_Result
*/
public function authenticateWithOpenId($openId, $verifyUrl, $redirectUrl)
{
require_once 'Erfurt/Auth/Adapter/OpenId.php';
$adapter = new Erfurt_Auth_Adapter_OpenId($openId, $verifyUrl, $redirectUrl);
$result = $this->getAuth()->authenticate($adapter);
// If we reach this point, something went wrong with the authentication process...
// So we always clear the identity.
$this->getAuth()->clearIdentity();
return $result;
}
/**
* Returns an instance of the access control class.
*
* @return Erfurt_Ac_Default
*/
public function getAc()
{
if (null === $this->_ac) {
$config = $this->getConfig();
$type = strtolower($config->ac->type);
if ($type === 'rdf') {
require_once 'Erfurt/Ac/Default.php';
$this->_ac = new Erfurt_Ac_Default();
} else if ($type === 'none') {
require_once 'Erfurt/Ac/None.php';
$this->_ac = new Erfurt_Ac_None();
} else {
require_once 'Erfurt/Exception.php';
throw new Erfurt_Exception("AC type '$type' not supported.");
}
}
return $this->_ac;
}
public function setAc($ac)
{
$this->_ac = $ac;
}
/**
* Returns an instance of the access control model.
*
* @return Erfurt_Rdf_Model
*/
public function getAcModel()
{
if (null === $this->_acModel) {
$config = $this->getConfig();
$this->_acModel = $this->getStore()->getModel($this->getAcModelUri(), false);
}
return $this->_acModel;
}
public function getAcModelUri()
{
if (null === $this->_acModelUri) {
$config = $this->getConfig();
$this->_acModelUri = $config->ac->modelUri;
}
return $this->_acModelUri;
}
/**
* Convenience shortcut for Ac_Default::getActionConfig().
*
* @param string $actionSpec The action to get the configuration for.
* @return array Returns the configuration for the given action.
*/
public function getActionConfig($actionSpec)
{
return $this->getAc()->getActionConfig($actionSpec);
}
/**
* Returns the auth instance.
*
* @return Zend_Auth
*/
public function getAuth()
{
if (null === $this->_auth) {
require_once 'Erfurt/Auth.php';
$auth = Erfurt_Auth::getInstance();
$config = $this->getConfig();
if (isset($config->session->identifier)) {
$sessionNamespace = 'Erfurt_Auth' . $config->session->identifier;
require_once 'Zend/Auth/Storage/Session.php';
$auth->setStorage(new Zend_Auth_Storage_Session($sessionNamespace));
}
$this->_auth = $auth;
}
return $this->_auth;
}
public function setAuth(Erfurt_Auth $auth)
{
$this->_auth = $auth;
}
/**
* Returns a caching instance.
*
* @return Zend_Cache_Core
*/
public function getCache()
{
if (null === $this->_cache) {
$config = $this->getConfig();
if (!isset($config->cache->lifetime) || ($config->cache->lifetime == -1)) {
$lifetime = null;
} else {
$lifetime = $config->cache->lifetime;
}
$frontendOptions = array(
'lifetime' => $lifetime,
'automatic_serialization' => true
);
require_once 'Zend/Cache.php'; // workaround, for zend actually does not include it itself
require_once 'Erfurt/Cache/Frontend/ObjectCache.php';
$this->_cache = new Erfurt_Cache_Frontend_ObjectCache($frontendOptions);
$backend = $this->_getCacheBackend();
$this->_cache->setBackend($backend);
}
return $this->_cache;
}
/**
* Returns a directory, which can be used for file-based caching.
* If no such (writable) directory is found, false is returned.
*
* @return string|false
*/
public function getCacheDir()
{
$config = $this->getConfig();
if (isset($config->cache->path)) {
$matches = array();
if (!(preg_match('/^(\w:[\/|\\\\]|\/)/', $config->cache->path, $matches) === 1)) {
$baseDir = realpath(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR;
$config->cache->path = $baseDir . $config->cache->path;
}
if (is_writable($config->cache->path)) {
return $config->cache->path;
} else {
throw new Erfurt_App_Exception('Cache path is not writable:' . $config->cache->path);
}
} else {
$cacheDir = realpath(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
if (is_writable($cacheDir)) {
return $cacheDir;
} else {
throw new Erfurt_App_Exception('Cache path is not writable:' . $cacheDir);
}
}
}
/**
* Returns the configuration object.
*
* @return Zend_Config
* @throws Erfurt_Exception Throws an exception if no config is loaded.
*/
public function getConfig()
{
if (null === $this->_config) {
require_once 'Erfurt/Exception.php';
throw new Erfurt_Exception('Configuration was not loaded.');
} else {
return $this->_config;
}
}
/**
* Returns the event dispatcher instance.
*
* @return Erfurt_Event_Dispatcher
*/
public function getEventDispatcher()
{
require_once 'Erfurt/Event/Dispatcher.php';
$ed = Erfurt_Event_Dispatcher::getInstance();
return $ed;
}
/**
*
*/
public function getHttpClient($uri, $options = array())
{
if (null !== self::$httpAdapter) {
return new Zend_Http_Client($uri, array('adapter' => self::$httpAdapter));
}
$config = $this->getConfig();
$defaultOptions = array();
if (isset($config->proxy)) {
$proxy = $config->proxy;
if (isset($proxy->host)) {
$defaultOptions['proxy_host'] = $proxy->host;
$defaultOptions['adapter'] = 'Zend_Http_Client_Adapter_Proxy';
if (isset($proxy->port)) {
$defaultOptions['proxy_port'] = (int)$proxy->port;
}
if (isset($proxy->username)) {
$defaultOptions['proxy_user'] = $proxy->username;
}
if (isset($proxy->password)) {
$defaultOptions['proxy_pass'] = $proxy->password;
}
}
}
$finalOptions = array_merge($defaultOptions, $options);
$client = new Zend_Http_Client($uri, $finalOptions);
return $client;
}
/**
* Returns a logging instance. If logging is disabled Zend_Log_Writer_Null is returned,
* so it is save to use this object without further checkings. It is possible to use
* different logging files for different contexts. Just use an additional identifier.
*
* @param string $logIdentifier Identifies the logfile (filename without extension).
* @return Zend_Log
*/
public function getLog($logIdentifier = 'erfurt' )
{
if (!isset($this->_logObjects[$logIdentifier])) {
$config = $this->getConfig();
if ((boolean)$config->log->level !== false) {
$logDir = $this->getLogDir();
if ($logDir === false) {
require_once 'Zend/Log/Writer/Null.php';
$logWriter = new Zend_Log_Writer_Null();
} else {
require_once 'Zend/Log/Writer/Stream.php';
$logName = $logDir . $logIdentifier;
// Check whether log can be created with $logName... otherwise append a number.
// This needs to be done, since logs may be created by other processes (e.g. with
// testing) and thus can't be opened anymore.
for ($i = 0; $i<10; ++$i) {
try {
$fullLogName = $logName;
if ($i > 0) {
$fullLogName .= '_' . $i;
}
$fullLogName .= '.log';
$logWriter = new Zend_Log_Writer_Stream($fullLogName);
if (null !== $logWriter) {
break;
}
} catch (Zend_Log_Exception $e) {
// Nothing to do... just continue
}
}
if (null === $logWriter) {
require_once 'Zend/Log/Writer/Null.php';
$logWriter = new Zend_Log_Writer_Null();
}
}
} else {
require_once 'Zend/Log/Writer/Null.php';
$logWriter = new Zend_Log_Writer_Null();
}
require_once 'Zend/Log.php';
$logger = new Zend_Log($logWriter);
// filter according to the given log level
if ((boolean) $config->log->level !== false) {
require_once 'Zend/Log/Filter/Priority.php';
$levelFilter = new Zend_Log_Filter_Priority((int) $config->log->level, '<=');
$logger->addFilter($levelFilter);
}
$this->_logObjects[$logIdentifier] = $logger;
}
return $this->_logObjects[$logIdentifier];
}
/**
* Returns the configured log directory. If no such directory is configured
* a logs folder under the Erfurt tree is used iff available.
*
* @return string|false
*/
public function getLogDir()
{
$config = $this->getConfig();
if (isset($config->log->path)) {
$matches = array();
if (!(preg_match('/^(\w:[\/|\\\\]|\/)/', $config->log->path, $matches) === 1)) {
$config->log->path = realpath(EF_BASE . '../../' . $config->log->path);
}
$config->log->path = rtrim($config->log->path, '/\\') . '/';
if (is_writable($config->log->path)) {
return $config->log->path;
} else {
error_log('Attention : Erfurt log.path ('. $config->log->path .') not writable.');
return false;
}
} else {
return false;
}
}
/**
* Returns the namespace management module.
*
* @return Erfurt_Namespaces
*/
public function getNamespaces()
{
if (null === $this->_namespaces) {
$config = $this->getConfig();
// options
$namespacesOptions = array(
'standard_prefixes' => isset($config->namespaces) ? $config->namespaces->toArray() : array(),
'reserved_names' => isset($config->uri->schemata) ? $config->uri->schemata->toArray() : array()
);
require_once 'Erfurt/Namespaces.php';
$this->_namespaces = new Erfurt_Namespaces($namespacesOptions);
}
return $this->_namespaces;
}
/**
* Returns a plugin manager instance
*
* @param boolean $addDefaultPluginPath Whether to add the default plugin path
* on first call of this method (When the class is instanciated).
* @return Erfurt_Plugin_Manager
*/
public function getPluginManager($addDefaultPluginPath = true)
{
if (null === $this->_pluginManager) {
$config = $this->getConfig();
require_once 'Erfurt/Plugin/Manager.php';
$this->_pluginManager = new Erfurt_Plugin_Manager();
if ($addDefaultPluginPath && isset($config->extensions->plugins)) {
$this->_pluginManager->addPluginPath(EF_BASE . $config->extensions->plugins);
}
}
return $this->_pluginManager;
}
/**
* Returns a query cache instance.
*
* @return Erfurt_Cache_Frontend_QueryCache
*/
public function getQueryCache()
{
if (null === $this->_queryCache) {
$config = $this->getConfig();
require_once 'Erfurt/Cache/Frontend/QueryCache.php';
$this->_queryCache = new Erfurt_Cache_Frontend_QueryCache();
$backend = $this->_getQueryCacheBackend();
$this->_queryCache->setBackend($backend);
}
return $this->_queryCache;
}
/**
* Returns a instance of the store.
*
* @return Erfurt_Store
* @throws Erfurt_Exception Throws an exception if the store is not configured right.
*/
public function getStore()
{
if (null === $this->_store) {
$config = $this->getConfig();
// Backend must be set, else throw an exception.
if (isset($config->store->backend)) {
$backend = strtolower($config->store->backend);
} else {
require_once 'Erfurt/Exception.php';
throw new Erfurt_Exception('Backend must be set in configuration.');
}
// Check configured schema and if not set set it as empty (e.g. virtuoso needs no special schema.
if (isset($config->store->schema)) {
$schema = $config->store->schema;
} else {
$schema = null;
}
// fetch backend specific options from config.
$backendOptions = array();
if ($backendConfig = $config->store->get($backend)) {
$backendOptions = $backendConfig->toArray();
}
// store config options
if (isset($config->sysont)) {
$storeOptions = $config->sysont->toArray();
} else {
$storeOptions = array();
}
require_once 'Erfurt/Store.php';
$this->_store = new Erfurt_Store($storeOptions, $backend, $backendOptions, $schema);
}
return $this->_store;
}
public function setStore(Erfurt_Store $store)
{
$this->_store = $store;
}
/**
* Returns an instance of the system ontology model.
*
* @return Erfurt_Rdf_Model
*/
public function getSysOntModel()
{
if (null === $this->_sysOntModel) {
$config = $this->getConfig();
$this->_sysOntModel = $this->getStore()->getModel($config->sysont->modelUri, false);
}
return $this->_sysOntModel;
}
/**
* Returns a valid tmp folder depending on the OS used.
*
* @return string
*/
public function getTmpDir()
{
// We use a Zend method here, for it already checks the OS.
require_once 'Zend/Cache/Backend.php';
$temp = new Zend_Cache_Backend();
return $temp->getTmpDir();
}
/**
* Convenience shortcut for Auth_Adapter_Rdf::getUsers().
*
* @return array Returns a list of users.
*/
public function getUsers()
{
require_once 'Erfurt/Auth/Adapter/Rdf.php';
$tempAdapter = new Erfurt_Auth_Adapter_Rdf();
return $tempAdapter->getUsers();
}