1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SESP; |
4
|
|
|
|
5
|
|
|
use Psr\Log\NullLogger; |
6
|
|
|
use Psr\Log\LoggerInterface; |
7
|
|
|
use Psr\Log\LoggerAwareInterface; |
8
|
|
|
use Title; |
9
|
|
|
use WikiPage; |
10
|
|
|
use User; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @ingroup SESP |
14
|
|
|
* |
15
|
|
|
* @license GNU GPL v2+ |
16
|
|
|
* @since 1.3 |
17
|
|
|
* |
18
|
|
|
* @author mwjames |
19
|
|
|
*/ |
20
|
|
|
class AppFactory implements LoggerAwareInterface { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private $options; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
private $connection; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var LoggerInterface |
34
|
|
|
*/ |
35
|
|
|
private $logger; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var PropertyDefinitions |
39
|
|
|
*/ |
40
|
|
|
private $propertyDefinitions; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @since 2.0 |
44
|
|
|
* |
45
|
|
|
* @param array $options |
46
|
|
|
*/ |
47
|
9 |
|
public function __construct( array $options = array() ) { |
48
|
9 |
|
$this->options = $options; |
49
|
9 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @since 2.0 |
53
|
|
|
*/ |
54
|
1 |
|
public function setConnection( \DatabaseBase $connection ) { |
55
|
1 |
|
$this->connection = $connection; |
|
|
|
|
56
|
1 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @since 1.3 |
60
|
|
|
* |
61
|
|
|
* @return DatabaseBase |
62
|
|
|
*/ |
63
|
1 |
|
public function getConnection() { |
64
|
1 |
|
return $this->connection; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @see LoggerAwareInterface::setLogger |
69
|
|
|
* |
70
|
|
|
* @since 2.0 |
71
|
|
|
* |
72
|
|
|
* @param LoggerInterface $logger |
73
|
|
|
*/ |
74
|
|
|
public function setLogger( LoggerInterface $logger ) { |
75
|
|
|
$this->logger = $logger; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @since 3.0 |
80
|
|
|
* |
81
|
|
|
* @param LoggerInterface |
82
|
|
|
*/ |
83
|
1 |
|
public function getLogger() { |
84
|
|
|
|
85
|
1 |
|
if ( $this->logger === null ) { |
86
|
1 |
|
return new NullLogger(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $this->logger; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @since 2.4 |
94
|
|
|
* |
95
|
|
|
* @param string $key |
96
|
|
|
* @param $default $mixed |
|
|
|
|
97
|
|
|
* |
98
|
|
|
* @return mixed|false |
99
|
|
|
*/ |
100
|
2 |
|
public function getOption( $key, $default = false ) { |
101
|
|
|
|
102
|
2 |
|
if ( isset( $this->options[$key] ) ) { |
103
|
2 |
|
return $this->options[$key]; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $default; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @since 2.0 |
111
|
|
|
* |
112
|
|
|
* @return PropertyDefinitions |
113
|
|
|
*/ |
114
|
1 |
|
public function getPropertyDefinitions() { |
115
|
|
|
|
116
|
1 |
|
if ( $this->propertyDefinitions !== null ) { |
117
|
|
|
return $this->propertyDefinitions; |
118
|
|
|
} |
119
|
|
|
|
120
|
1 |
|
$this->propertyDefinitions = new PropertyDefinitions( |
121
|
1 |
|
$this->getOption( 'sespPropertyDefinitionFile' ) |
122
|
1 |
|
); |
123
|
|
|
|
124
|
1 |
|
$this->propertyDefinitions->setLocalPropertyDefinitions( |
125
|
1 |
|
$this->getOption( 'sespLocalPropertyDefinitions', array() ) |
|
|
|
|
126
|
1 |
|
); |
127
|
|
|
|
128
|
1 |
|
return $this->propertyDefinitions; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @since 1.3 |
133
|
|
|
* |
134
|
|
|
* @param Title $title |
135
|
|
|
* |
136
|
|
|
* @return WikiPage |
137
|
|
|
*/ |
138
|
2 |
|
public function newWikiPage( Title $title ) { |
139
|
|
|
|
140
|
|
|
// #55 |
141
|
|
|
// Fight a possible DB corruption and avoid "NS_MEDIA is a virtual namespace; use NS_FILE" |
142
|
2 |
|
if ( $title->getNamespace() === NS_MEDIA ) { |
143
|
1 |
|
$title = Title::makeTitleSafe( |
144
|
1 |
|
NS_FILE, |
145
|
1 |
|
$title->getDBkey(), |
146
|
1 |
|
$title->getInterwiki(), |
147
|
1 |
|
$title->getFragment() |
148
|
1 |
|
); |
149
|
1 |
|
} |
150
|
|
|
|
151
|
2 |
|
return WikiPage::factory( $title ); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @since 1.3 |
156
|
|
|
* |
157
|
|
|
* @param Title $title |
158
|
|
|
* |
159
|
|
|
* @return User |
160
|
|
|
*/ |
161
|
1 |
|
public function newUserFromTitle( Title $title ) { |
162
|
1 |
|
return User::newFromName( $title->getText() ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @since 1.3 |
167
|
|
|
* |
168
|
|
|
* @param $id |
169
|
|
|
* |
170
|
|
|
* @return User |
171
|
|
|
*/ |
172
|
1 |
|
public function newUserFromID( $id ) { |
173
|
1 |
|
return User::newFromId( $id ); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
} |
177
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..