1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Query; |
4
|
|
|
|
5
|
|
|
use SMW\DIWikiPage; |
6
|
|
|
use SMW\Query\ProfileAnnotators\NullProfileAnnotator; |
7
|
|
|
use SMW\Query\ProfileAnnotators\DescriptionProfileAnnotator; |
8
|
|
|
use SMW\Query\ProfileAnnotators\FormatProfileAnnotator; |
9
|
|
|
use SMW\Query\ProfileAnnotators\ParametersProfileAnnotator; |
10
|
|
|
use SMW\Query\ProfileAnnotators\DurationProfileAnnotator; |
11
|
|
|
use SMW\Query\ProfileAnnotators\SourceProfileAnnotator; |
12
|
|
|
use SMWContainerSemanticData as ContainerSemanticData; |
13
|
|
|
use SMWDIContainer as DIContainer; |
14
|
|
|
use SMWQuery as Query; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @license GNU GPL v2+ |
18
|
|
|
* @since 2.1 |
19
|
|
|
* |
20
|
|
|
* @author mwjames |
21
|
|
|
*/ |
22
|
|
|
class ProfileAnnotatorFactory { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @since 2.5 |
26
|
|
|
* |
27
|
|
|
* @param Query $query |
28
|
|
|
* |
29
|
|
|
* @return DescriptionProfileAnnotator |
30
|
101 |
|
*/ |
31
|
|
|
public function newDescriptionProfileAnnotator( Query $query ) { |
32
|
101 |
|
|
33
|
101 |
|
$profileAnnotator = new NullProfileAnnotator( |
34
|
|
|
$this->newDIContainer( $query ) |
35
|
|
|
); |
36
|
101 |
|
|
37
|
|
|
$profileAnnotator = new DescriptionProfileAnnotator( |
38
|
101 |
|
$profileAnnotator, |
39
|
|
|
$query->getDescription() |
|
|
|
|
40
|
|
|
); |
41
|
101 |
|
|
42
|
|
|
return $profileAnnotator; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @since 2.1 |
47
|
|
|
* |
48
|
|
|
* @param Query $query |
49
|
|
|
* @param string $format |
50
|
|
|
* |
51
|
|
|
* @return ProfileAnnotator |
52
|
94 |
|
*/ |
53
|
|
|
public function newCombinedProfileAnnotator( Query $query, $format ) { |
54
|
94 |
|
|
55
|
|
|
$profileAnnotator = $this->newDescriptionProfileAnnotator( |
56
|
|
|
$query |
57
|
|
|
); |
58
|
94 |
|
|
59
|
|
|
$profileAnnotator = $this->newFormatProfileAnnotator( |
60
|
|
|
$profileAnnotator, |
61
|
|
|
$format |
62
|
|
|
); |
63
|
94 |
|
|
64
|
|
|
$profileAnnotator = $this->newParametersProfileAnnotator( |
65
|
94 |
|
$profileAnnotator, |
66
|
|
|
$query |
67
|
|
|
); |
68
|
94 |
|
|
69
|
|
|
$profileAnnotator = $this->newDurationProfileAnnotator( |
70
|
94 |
|
$profileAnnotator, |
71
|
|
|
$query->getOption( Query::PROC_QUERY_TIME ) |
72
|
|
|
); |
73
|
94 |
|
|
74
|
|
|
$profileAnnotator = $this->newSourceProfileAnnotator( |
75
|
|
|
$profileAnnotator, |
76
|
94 |
|
$query->getQuerySource() |
77
|
94 |
|
); |
78
|
|
|
|
79
|
|
|
return $profileAnnotator; |
80
|
94 |
|
} |
81
|
94 |
|
|
82
|
|
|
private function newFormatProfileAnnotator( $profileAnnotator, $format ) { |
83
|
|
|
return new FormatProfileAnnotator( $profileAnnotator, $format ); |
84
|
94 |
|
} |
85
|
|
|
|
86
|
94 |
|
private function newParametersProfileAnnotator( $profileAnnotator, $query ) { |
87
|
91 |
|
|
88
|
|
|
if ( $query->getOption( Query::OPT_PARAMETERS ) === false ) { |
89
|
|
|
return $profileAnnotator; |
90
|
3 |
|
} |
91
|
|
|
|
92
|
|
|
return new ParametersProfileAnnotator( $profileAnnotator, $query ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
private function newDurationProfileAnnotator( $profileAnnotator, $duration ) { |
96
|
|
|
return new DurationProfileAnnotator( $profileAnnotator, $duration ); |
97
|
101 |
|
} |
98
|
|
|
|
99
|
101 |
|
private function newSourceProfileAnnotator( $profileAnnotator, $querySource ) { |
100
|
|
|
|
101
|
101 |
|
if ( $querySource === '' ) { |
102
|
1 |
|
return $profileAnnotator; |
103
|
|
|
} |
104
|
100 |
|
|
105
|
100 |
|
return new SourceProfileAnnotator( $profileAnnotator, $querySource ); |
106
|
100 |
|
} |
107
|
100 |
|
|
108
|
100 |
|
/** |
109
|
|
|
* #1416 create container manually to avoid any issues that may arise from |
110
|
|
|
* a failed Title::makeTitleSafe. |
111
|
100 |
|
*/ |
112
|
|
|
private function newDIContainer( Query $query ) { |
113
|
|
|
|
114
|
101 |
|
$subject = $query->getContextPage(); |
115
|
|
|
|
116
|
|
|
if ( $subject === null ) { |
117
|
|
|
$containerSemanticData = ContainerSemanticData::makeAnonymousContainer(); |
118
|
|
|
} else { |
119
|
|
|
$subject = new DIWikiPage( |
120
|
|
|
$subject->getDBkey(), |
121
|
|
|
$subject->getNamespace(), |
122
|
|
|
$subject->getInterwiki(), |
123
|
|
|
$query->getQueryId() |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
$containerSemanticData = new ContainerSemanticData( $subject ); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return new DIContainer( |
130
|
|
|
$containerSemanticData |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.