|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SG; |
|
4
|
|
|
|
|
5
|
|
|
use SG\Cache\ElementsCacheBuilder; |
|
6
|
|
|
use SG\Cache\GlossaryCache; |
|
7
|
|
|
|
|
8
|
|
|
use SMW\StoreFactory; |
|
9
|
|
|
|
|
10
|
|
|
use Lingo\Backend; |
|
11
|
|
|
use Lingo\MessageLog; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @ingroup SG |
|
15
|
|
|
* @ingroup SemanticGlossary |
|
16
|
|
|
* |
|
17
|
|
|
* @license GNU GPL v2+ |
|
18
|
|
|
* @since 1.1 |
|
19
|
|
|
* |
|
20
|
|
|
* @author mwjames |
|
21
|
|
|
*/ |
|
22
|
|
|
class LingoBackendAdapter extends Backend { |
|
23
|
|
|
|
|
24
|
|
|
/* @var ElementsCacheBuilder */ |
|
25
|
|
|
protected $elementsCacheBuilder = null; |
|
26
|
|
|
|
|
27
|
|
|
protected $elements = array(); |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @since 1.1 |
|
31
|
|
|
* |
|
32
|
|
|
* @param MessageLog|null &$messages |
|
33
|
|
|
* @param ElementsCacheBuilder|null $elementsCacheBuilder |
|
34
|
|
|
*/ |
|
35
|
2 |
|
public function __construct( MessageLog &$messages = null, ElementsCacheBuilder $elementsCacheBuilder = null ) { |
|
36
|
2 |
|
parent::__construct( $messages ); |
|
37
|
2 |
|
$this->elementsCacheBuilder = $elementsCacheBuilder; |
|
38
|
|
|
|
|
39
|
2 |
|
if ( $this->elementsCacheBuilder === null ) { |
|
40
|
1 |
|
$this->elementsCacheBuilder = new ElementsCacheBuilder( |
|
41
|
1 |
|
StoreFactory::getStore(), |
|
42
|
1 |
|
new GlossaryCache() |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
2 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* This function returns the next element. The element is an array of four |
|
49
|
|
|
* strings: Term, Definition, Link, Source, Style. If there is no next element |
|
50
|
|
|
* the function returns null. |
|
51
|
|
|
* |
|
52
|
|
|
* @since 1.1 |
|
53
|
|
|
* |
|
54
|
|
|
* @return array|null the next element or null |
|
55
|
|
|
*/ |
|
56
|
1 |
|
public function next() { |
|
57
|
|
|
|
|
58
|
1 |
|
if ( $this->elements === array() ) { |
|
59
|
1 |
|
$this->elements = $this->elementsCacheBuilder->getElements(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
return array_pop( $this->elements ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* This backend is cache-enabled so this function returns true. |
|
67
|
|
|
* |
|
68
|
|
|
* Actual caching is done by the parser, the backend just calls |
|
69
|
|
|
* Parser::purgeCache when necessary. |
|
70
|
|
|
* |
|
71
|
|
|
* @since 1.1 |
|
72
|
|
|
* |
|
73
|
|
|
* @return boolean |
|
74
|
|
|
*/ |
|
75
|
1 |
|
public function useCache() { |
|
76
|
1 |
|
return true; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|