1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Scribunto; |
4
|
|
|
|
5
|
|
|
use SMWQueryProcessor as QueryProcessor; |
6
|
|
|
use SMWQuery as Query; |
7
|
|
|
use SMW\Store; |
8
|
|
|
use SMW\ApplicationFactory; |
9
|
|
|
use SMW\ParameterProcessorFactory; |
10
|
|
|
use Parser; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @license GNU GPL v2+ |
14
|
|
|
* @since 1.0 |
15
|
|
|
* |
16
|
|
|
* @author mwjames |
17
|
|
|
*/ |
18
|
|
|
class LibraryFactory { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
*@var Store |
22
|
|
|
*/ |
23
|
|
|
private $store; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @since 1.0 |
27
|
|
|
* |
28
|
|
|
* @param Store $store |
29
|
|
|
*/ |
30
|
21 |
|
public function __construct( Store $store ) { |
31
|
21 |
|
$this->store = $store; |
32
|
21 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Creates a new SMWQueryResult from passed arguments, |
36
|
|
|
* utilizing the {@see SMWQueryProcessor} |
37
|
|
|
* |
38
|
|
|
* @since 1.0 |
39
|
|
|
* |
40
|
|
|
* @param array $rawParameters |
41
|
|
|
* |
42
|
|
|
* @return \SMWQueryResult |
43
|
|
|
*/ |
44
|
7 |
|
public function newQueryResultFrom( $rawParameters ) { |
45
|
|
|
|
46
|
7 |
|
list( $queryString, $parameters, $printouts ) = QueryProcessor::getComponentsFromFunctionParams( |
47
|
7 |
|
$rawParameters, |
48
|
7 |
|
false |
49
|
|
|
); |
50
|
|
|
|
51
|
7 |
|
QueryProcessor::addThisPrintout( $printouts, $parameters ); |
52
|
|
|
|
53
|
7 |
|
$query = QueryProcessor::createQuery( |
54
|
7 |
|
$queryString, |
55
|
7 |
|
QueryProcessor::getProcessedParams( $parameters, $printouts ), |
56
|
7 |
|
QueryProcessor::SPECIAL_PAGE, |
57
|
7 |
|
'', |
58
|
7 |
|
$printouts |
59
|
|
|
); |
60
|
|
|
|
61
|
7 |
|
if ( defined( 'SMWQuery::PROC_CONTEXT' ) ) { |
62
|
7 |
|
$query->setOption( Query::PROC_CONTEXT, 'SSC.LibraryFactory' ); |
63
|
|
|
} |
64
|
|
|
|
65
|
7 |
|
return $this->store->getQueryResult( $query ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @since 1.0 |
70
|
|
|
* |
71
|
|
|
* @param \SMWQueryResult|string $queryResult |
72
|
|
|
* |
73
|
|
|
* @return LuaAskResultProcessor |
74
|
|
|
*/ |
75
|
4 |
|
public function newLuaAskResultProcessor( $queryResult ) { |
76
|
4 |
|
return new LuaAskResultProcessor( $queryResult ); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Creates a new ParserParameterProcessor from passed arguments |
81
|
|
|
* |
82
|
|
|
* @since 1.0 |
83
|
|
|
* |
84
|
|
|
* @param array $arguments |
85
|
|
|
* |
86
|
|
|
* @return \SMW\ParserParameterProcessor |
87
|
|
|
*/ |
88
|
10 |
|
public function newParserParameterProcessorFrom( $arguments ) { |
89
|
10 |
|
return ParameterProcessorFactory::newFromArray( $arguments ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Creates a new SetParserFunction utilizing a Parser |
94
|
|
|
* |
95
|
|
|
* @since 1.0 |
96
|
|
|
* |
97
|
|
|
* @param Parser $parser |
98
|
|
|
* |
99
|
|
|
* @return \SMW\ParserFunctions\SetParserFunction |
100
|
|
|
*/ |
101
|
8 |
|
public function newSetParserFunction( Parser $parser ) { |
102
|
8 |
|
return ApplicationFactory::getInstance()->newParserFunctionFactory( $parser )->newSetParserFunction( $parser ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Creates a new SubobjectParserFunction utilizing a Parser |
107
|
|
|
* |
108
|
|
|
* @since 1.0 |
109
|
|
|
* |
110
|
|
|
* @param Parser $parser |
111
|
|
|
* |
112
|
|
|
* @return \SMW\SubobjectParserFunction |
113
|
|
|
*/ |
114
|
3 |
|
public function newSubobjectParserFunction( Parser $parser ) { |
115
|
3 |
|
return ApplicationFactory::getInstance()->newParserFunctionFactory( $parser )->newSubobjectParserFunction( $parser ); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
This check looks at variables that have been passed in as parameters and 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.