1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Elgg\Di; |
4
|
|
|
|
5
|
|
|
use ConfigurationException; |
6
|
|
|
use Elgg\Application; |
7
|
|
|
use Elgg\Cache\CompositeCache; |
8
|
|
|
use Elgg\Cache\DataCache; |
9
|
|
|
use Elgg\Cache\SessionCache; |
10
|
|
|
use Elgg\Config; |
11
|
|
|
use Elgg\Database\DbConfig; |
12
|
|
|
use Elgg\Database\SiteSecret; |
13
|
|
|
use Elgg\Printer\CliPrinter; |
14
|
|
|
use Elgg\Printer\HtmlPrinter; |
15
|
|
|
use Elgg\Project\Paths; |
16
|
|
|
use Zend\Mail\Transport\TransportInterface as Mailer; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Provides common Elgg services. |
20
|
|
|
* |
21
|
|
|
* We extend the container because it allows us to document properties in the PhpDoc, which assists |
22
|
|
|
* IDEs to auto-complete properties and understand the types returned. Extension allows us to keep |
23
|
|
|
* the container generic. |
24
|
|
|
* |
25
|
|
|
* @property-read \Elgg\Database\AccessCollections $accessCollections |
26
|
|
|
* @property-read \ElggCache $accessCache |
27
|
|
|
* @property-read \Elgg\ActionsService $actions |
28
|
|
|
* @property-read \Elgg\Database\AdminNotices $adminNotices |
29
|
|
|
* @property-read \Elgg\Ajax\Service $ajax |
30
|
|
|
* @property-read \Elgg\Amd\Config $amdConfig |
31
|
|
|
* @property-read \Elgg\Database\AnnotationsTable $annotationsTable |
32
|
|
|
* @property-read \ElggAutoP $autoP |
33
|
|
|
* @property-read \Elgg\AutoloadManager $autoloadManager |
34
|
|
|
* @property-read \Elgg\BatchUpgrader $batchUpgrader |
35
|
|
|
* @property-read \Elgg\BootService $boot |
36
|
|
|
* @property-read \Elgg\Application\CacheHandler $cacheHandler |
37
|
|
|
* @property-read \Elgg\ClassLoader $classLoader |
38
|
|
|
* @property-read \Elgg\Cli $cli |
39
|
|
|
* @property-read \ElggCrypto $crypto |
40
|
|
|
* @property-read \Elgg\Config $config |
41
|
|
|
* @property-read \Elgg\Database\ConfigTable $configTable |
42
|
|
|
* @property-read \Elgg\Context $context |
43
|
|
|
* @property-read \Elgg\Cache\DataCache $dataCache |
44
|
|
|
* @property-read \Elgg\Database $db |
45
|
|
|
* @property-read \Elgg\Database\DbConfig $dbConfig |
46
|
|
|
* @property-read \Elgg\DeprecationService $deprecation |
47
|
|
|
* @property-read \Elgg\EmailService $emails |
48
|
|
|
* @property-read \Elgg\Cache\EntityCache $entityCache |
49
|
|
|
* @property-read \Elgg\EntityPreloader $entityPreloader |
50
|
|
|
* @property-read \Elgg\Database\EntityTable $entityTable |
51
|
|
|
* @property-read \Elgg\Assets\ExternalFiles $externalFiles |
52
|
|
|
* @property-read \ElggCache $fileCache |
53
|
|
|
* @property-read \ElggDiskFilestore $filestore |
54
|
|
|
* @property-read \Elgg\FormsService $forms |
55
|
|
|
* @property-read \Elgg\HandlersService $handlers |
56
|
|
|
* @property-read \Elgg\Security\HmacFactory $hmac |
57
|
|
|
* @property-read \Elgg\PluginHooksService $hooks |
58
|
|
|
* @property-read \Elgg\EntityIconService $iconService |
59
|
|
|
* @property-read \Elgg\Http\Input $input |
60
|
|
|
* @property-read \Elgg\ImageService $imageService |
61
|
|
|
* @property-read \Elgg\Logger $logger |
62
|
|
|
* @property-read Mailer $mailer |
63
|
|
|
* @property-read \Elgg\Menu\Service $menus |
64
|
|
|
* @property-read \Elgg\Cache\MetadataCache $metadataCache |
65
|
|
|
* @property-read \Elgg\Database\MetadataTable $metadataTable |
66
|
|
|
* @property-read \Elgg\Database\Mutex $mutex |
67
|
|
|
* @property-read \Elgg\Notifications\NotificationsService $notifications |
68
|
|
|
* @property-read \Elgg\PasswordService $passwords |
69
|
|
|
* @property-read \Elgg\PersistentLoginService $persistentLogin |
70
|
|
|
* @property-read \Elgg\Database\Plugins $plugins |
71
|
|
|
* @property-read \ElggCache $privateSettingsCache |
72
|
|
|
* @property-read \Elgg\Printer $printer |
73
|
|
|
* @property-read \Elgg\Database\PrivateSettingsTable $privateSettings |
74
|
|
|
* @property-read \Elgg\Application\Database $publicDb |
75
|
|
|
* @property-read \Elgg\Database\QueryCounter $queryCounter |
76
|
|
|
* @property-read \Elgg\RedirectService $redirects |
77
|
|
|
* @property-read \Elgg\Http\Request $request |
78
|
|
|
* @property-read \Elgg\Http\ResponseFactory $responseFactory |
79
|
|
|
* @property-read \Elgg\Database\RelationshipsTable $relationshipsTable |
80
|
|
|
* @property-read \Elgg\Router $router |
81
|
|
|
* @property-read \Elgg\Database\Seeder $seeder |
82
|
|
|
* @property-read \Elgg\Application\ServeFileHandler $serveFileHandler |
83
|
|
|
* @property-read \ElggSession $session |
84
|
|
|
* @property-read \Elgg\Cache\SessionCache $sessionCache |
85
|
|
|
* @property-read \Elgg\Search\SearchService $search |
86
|
|
|
* @property-read \Elgg\Cache\SimpleCache $simpleCache |
87
|
|
|
* @property-read \Elgg\Database\SiteSecret $siteSecret |
88
|
|
|
* @property-read \Elgg\Forms\StickyForms $stickyForms |
89
|
|
|
* @property-read \Elgg\Cache\SystemCache $systemCache |
90
|
|
|
* @property-read \Elgg\SystemMessagesService $systemMessages |
91
|
|
|
* @property-read \Elgg\Views\TableColumn\ColumnFactory $table_columns |
92
|
|
|
* @property-read \ElggTempDiskFilestore $temp_filestore |
93
|
|
|
* @property-read \Elgg\Timer $timer |
94
|
|
|
* @property-read \Elgg\I18n\Translator $translator |
95
|
|
|
* @property-read \Elgg\Security\UrlSigner $urlSigner |
96
|
|
|
* @property-read \Elgg\UpgradeService $upgrades |
97
|
|
|
* @property-read \Elgg\Upgrade\Locator $upgradeLocator |
98
|
|
|
* @property-read \Elgg\UploadService $uploads |
99
|
|
|
* @property-read \Elgg\UserCapabilities $userCapabilities |
100
|
|
|
* @property-read \Elgg\Database\UsersTable $usersTable |
101
|
|
|
* @property-read \Elgg\ViewsService $views |
102
|
|
|
* @property-read \Elgg\Cache\ViewCacher $viewCacher |
103
|
|
|
* @property-read \Elgg\WidgetsService $widgets |
104
|
|
|
* |
105
|
|
|
* @access private |
106
|
|
|
*/ |
107
|
|
|
class ServiceProvider extends DiContainer { |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Constructor |
111
|
|
|
* |
112
|
|
|
* @param Config $config Elgg Config service |
113
|
|
|
* @throws ConfigurationException |
114
|
|
|
*/ |
115
|
|
|
public function __construct(Config $config) { |
116
|
|
|
|
117
|
4417 |
|
$this->setFactory('autoloadManager', function(ServiceProvider $c) { |
118
|
40 |
|
$manager = new \Elgg\AutoloadManager($c->classLoader); |
119
|
40 |
|
if (!$c->config->AutoloaderManager_skip_storage) { |
120
|
40 |
|
$manager->setStorage($c->fileCache); |
121
|
40 |
|
$manager->loadCache(); |
122
|
|
|
} |
123
|
40 |
|
return $manager; |
124
|
4417 |
|
}); |
125
|
|
|
|
126
|
4417 |
|
$this->setFactory('accessCache', function(ServiceProvider $c) { |
|
|
|
|
127
|
471 |
|
return $this->sessionCache->access; |
128
|
4417 |
|
}); |
129
|
|
|
|
130
|
4417 |
|
$this->setFactory('accessCollections', function(ServiceProvider $c) { |
131
|
11 |
|
return new \Elgg\Database\AccessCollections( |
132
|
11 |
|
$c->config, |
133
|
11 |
|
$c->db, |
134
|
11 |
|
$c->entityTable, |
135
|
11 |
|
$c->userCapabilities, |
136
|
11 |
|
$c->accessCache, |
137
|
11 |
|
$c->hooks, |
138
|
11 |
|
$c->session, |
139
|
11 |
|
$c->translator |
140
|
|
|
); |
141
|
4417 |
|
}); |
142
|
|
|
|
143
|
4417 |
|
$this->setFactory('actions', function(ServiceProvider $c) { |
144
|
22 |
|
return new \Elgg\ActionsService($c->config, $c->session, $c->crypto); |
145
|
4417 |
|
}); |
146
|
|
|
|
147
|
4417 |
|
$this->setClassName('adminNotices', \Elgg\Database\AdminNotices::class); |
148
|
|
|
|
149
|
4417 |
|
$this->setFactory('ajax', function(ServiceProvider $c) { |
150
|
21 |
|
return new \Elgg\Ajax\Service($c->hooks, $c->systemMessages, $c->input, $c->amdConfig); |
151
|
4417 |
|
}); |
152
|
|
|
|
153
|
4417 |
|
$this->setFactory('amdConfig', function(ServiceProvider $c) { |
154
|
131 |
|
$obj = new \Elgg\Amd\Config($c->hooks); |
155
|
131 |
|
$obj->setBaseUrl($c->simpleCache->getRoot()); |
156
|
131 |
|
return $obj; |
157
|
4417 |
|
}); |
158
|
|
|
|
159
|
4417 |
|
$this->setFactory('annotationsTable', function(ServiceProvider $c) { |
160
|
12 |
|
return new \Elgg\Database\AnnotationsTable($c->db, $c->hooks->getEvents()); |
161
|
4417 |
|
}); |
162
|
|
|
|
163
|
4417 |
|
$this->setClassName('autoP', \ElggAutoP::class); |
164
|
|
|
|
165
|
4417 |
|
$this->setFactory('boot', function (ServiceProvider $c) { |
166
|
4417 |
|
$flags = ELGG_CACHE_PERSISTENT | ELGG_CACHE_FILESYSTEM | ELGG_CACHE_RUNTIME; |
167
|
4417 |
|
$cache = new CompositeCache("elgg_boot", $c->config, $flags); |
168
|
4417 |
|
$boot = new \Elgg\BootService($cache); |
169
|
4417 |
|
if ($c->config->enable_profiling) { |
170
|
|
|
$boot->setTimer($c->timer); |
171
|
|
|
} |
172
|
4417 |
|
return $boot; |
173
|
4417 |
|
}); |
174
|
|
|
|
175
|
4417 |
|
$this->setFactory('batchUpgrader', function(ServiceProvider $c) { |
176
|
1 |
|
return new \Elgg\BatchUpgrader($c->config); |
177
|
4417 |
|
}); |
178
|
|
|
|
179
|
4417 |
|
$this->setFactory('cacheHandler', function(ServiceProvider $c) { |
180
|
1 |
|
$simplecache_enabled = $c->config->simplecache_enabled; |
181
|
1 |
|
if ($simplecache_enabled === null) { |
182
|
|
|
$simplecache_enabled = $c->configTable->get('simplecache_enabled'); |
183
|
|
|
} |
184
|
1 |
|
return new \Elgg\Application\CacheHandler($c->config, $c->request, $simplecache_enabled); |
|
|
|
|
185
|
4417 |
|
}); |
186
|
|
|
|
187
|
4417 |
|
$this->setFactory('classLoader', function(ServiceProvider $c) { |
|
|
|
|
188
|
41 |
|
$loader = new \Elgg\ClassLoader(new \Elgg\ClassMap()); |
189
|
41 |
|
$loader->register(); |
190
|
41 |
|
return $loader; |
191
|
4417 |
|
}); |
192
|
|
|
|
193
|
4417 |
|
$this->setFactory('cli', function(ServiceProvider $c) { |
194
|
1 |
|
$version = elgg_get_version(true); |
195
|
1 |
|
$console = new \Symfony\Component\Console\Application('Elgg', $version); |
|
|
|
|
196
|
1 |
|
return new \Elgg\Cli($console, $c->hooks); |
197
|
4417 |
|
}); |
198
|
|
|
|
199
|
4417 |
|
$this->setFactory('config', function (ServiceProvider $sp) use ($config) { |
200
|
4417 |
|
$this->initConfig($config, $sp); |
201
|
4417 |
|
return $config; |
202
|
4417 |
|
}); |
203
|
|
|
|
204
|
4417 |
|
$this->setFactory('configTable', function(ServiceProvider $c) { |
205
|
11 |
|
return new \Elgg\Database\ConfigTable($c->db, $c->boot, $c->logger); |
206
|
4417 |
|
}); |
207
|
|
|
|
208
|
4417 |
|
$this->setFactory('context', function(ServiceProvider $c) { |
209
|
4417 |
|
$context = new \Elgg\Context(); |
210
|
4417 |
|
$context->initialize($c->request); |
211
|
4417 |
|
return $context; |
212
|
4417 |
|
}); |
213
|
|
|
|
214
|
4417 |
|
$this->setClassName('crypto', \ElggCrypto::class); |
215
|
|
|
|
216
|
4417 |
|
$this->setFactory('dataCache', function (ServiceProvider $c) { |
217
|
4417 |
|
return new DataCache($c->config); |
218
|
4417 |
|
}); |
219
|
|
|
|
220
|
4417 |
|
$this->setFactory('db', function (ServiceProvider $c) { |
221
|
11 |
|
$db = new \Elgg\Database($c->dbConfig); |
222
|
11 |
|
$db->setLogger($c->logger); |
223
|
|
|
|
224
|
11 |
|
if ($c->config->profiling_sql) { |
225
|
|
|
$db->setTimer($c->timer); |
226
|
|
|
} |
227
|
|
|
|
228
|
11 |
|
return $db; |
229
|
4417 |
|
}); |
230
|
|
|
|
231
|
4417 |
|
$this->setFactory('dbConfig', function(ServiceProvider $c) { |
232
|
|
|
$config = $c->config; |
233
|
|
|
$db_config = \Elgg\Database\DbConfig::fromElggConfig($config); |
234
|
|
|
|
235
|
|
|
// get this stuff out of config! |
236
|
|
|
unset($config->db); |
237
|
|
|
unset($config->dbname); |
238
|
|
|
unset($config->dbhost); |
239
|
|
|
unset($config->dbuser); |
240
|
|
|
unset($config->dbpass); |
241
|
|
|
|
242
|
|
|
return $db_config; |
243
|
4417 |
|
}); |
244
|
|
|
|
245
|
4417 |
|
$this->setFactory('deprecation', function(ServiceProvider $c) { |
246
|
21 |
|
return new \Elgg\DeprecationService($c->logger); |
247
|
4417 |
|
}); |
248
|
|
|
|
249
|
4417 |
|
$this->setFactory('emails', function(ServiceProvider $c) { |
250
|
5 |
|
return new \Elgg\EmailService($c->config, $c->hooks, $c->mailer, $c->logger); |
251
|
4417 |
|
}); |
252
|
|
|
|
253
|
4417 |
|
$this->setFactory('entityCache', function(ServiceProvider $c) { |
254
|
4417 |
|
return new \Elgg\Cache\EntityCache($c->session, $c->sessionCache->entities); |
255
|
4417 |
|
}); |
256
|
|
|
|
257
|
4417 |
|
$this->setFactory('entityPreloader', function(ServiceProvider $c) { |
258
|
10 |
|
return new \Elgg\EntityPreloader($c->entityTable); |
259
|
4417 |
|
}); |
260
|
|
|
|
261
|
4417 |
|
$this->setFactory('entityTable', function(ServiceProvider $c) { |
262
|
11 |
|
return new \Elgg\Database\EntityTable( |
263
|
11 |
|
$c->config, |
264
|
11 |
|
$c->db, |
265
|
11 |
|
$c->entityCache, |
266
|
11 |
|
$c->metadataCache, |
267
|
11 |
|
$c->hooks->getEvents(), |
268
|
11 |
|
$c->session, |
269
|
11 |
|
$c->translator, |
270
|
11 |
|
$c->logger |
271
|
|
|
); |
272
|
4417 |
|
}); |
273
|
|
|
|
274
|
4417 |
|
$this->setClassName('externalFiles', \Elgg\Assets\ExternalFiles::class); |
275
|
|
|
|
276
|
4417 |
|
$this->setFactory('fileCache', function(ServiceProvider $c) { |
277
|
4417 |
|
$flags = ELGG_CACHE_PERSISTENT | ELGG_CACHE_FILESYSTEM | ELGG_CACHE_RUNTIME; |
278
|
4417 |
|
return new CompositeCache("elgg_system_cache", $c->config, $flags); |
279
|
4417 |
|
}); |
280
|
|
|
|
281
|
4417 |
|
$this->setFactory('filestore', function(ServiceProvider $c) { |
282
|
76 |
|
return new \ElggDiskFilestore($c->config->dataroot); |
283
|
4417 |
|
}); |
284
|
|
|
|
285
|
4417 |
|
$this->setFactory('forms', function(ServiceProvider $c) { |
286
|
12 |
|
return new \Elgg\FormsService($c->views, $c->logger); |
287
|
4417 |
|
}); |
288
|
|
|
|
289
|
4417 |
|
$this->setClassName('handlers', \Elgg\HandlersService::class); |
290
|
|
|
|
291
|
4417 |
|
$this->setFactory('hmac', function(ServiceProvider $c) { |
292
|
66 |
|
return new \Elgg\Security\HmacFactory($c->siteSecret, $c->crypto); |
293
|
4417 |
|
}); |
294
|
|
|
|
295
|
4417 |
|
$this->setFactory('hooks', function(ServiceProvider $c) { |
296
|
4417 |
|
$events = new \Elgg\EventsService($c->handlers); |
297
|
4417 |
|
if ($c->config->enable_profiling) { |
298
|
|
|
$events->setTimer($c->timer); |
299
|
|
|
} |
300
|
4417 |
|
return new \Elgg\PluginHooksService($events); |
301
|
4417 |
|
}); |
302
|
|
|
|
303
|
4417 |
|
$this->setFactory('iconService', function(ServiceProvider $c) { |
304
|
6 |
|
return new \Elgg\EntityIconService($c->config, $c->hooks, $c->request, $c->logger, $c->entityTable, $c->uploads); |
305
|
4417 |
|
}); |
306
|
|
|
|
307
|
4417 |
|
$this->setClassName('input', \Elgg\Http\Input::class); |
308
|
|
|
|
309
|
4417 |
|
$this->setFactory('imageService', function(ServiceProvider $c) { |
310
|
72 |
|
switch ($c->config->image_processor) { |
311
|
72 |
|
case 'imagick': |
|
|
|
|
312
|
|
|
if (extension_loaded('imagick')) { |
|
|
|
|
313
|
|
|
$imagine = new \Imagine\Imagick\Imagine(); |
314
|
|
|
break; |
315
|
|
|
} |
316
|
|
|
default: |
317
|
|
|
// default use GD |
318
|
72 |
|
$imagine = new \Imagine\Gd\Imagine(); |
319
|
72 |
|
break; |
320
|
|
|
} |
321
|
|
|
|
322
|
72 |
|
return new \Elgg\ImageService($imagine, $c->config); |
323
|
4417 |
|
}); |
324
|
|
|
|
325
|
4417 |
|
$this->setFactory('logger', function (ServiceProvider $c) { |
326
|
4417 |
|
$logger = new \Elgg\Logger($c->hooks, $c->context, $c->config, $c->printer); |
327
|
4417 |
|
return $logger; |
328
|
4417 |
|
}); |
329
|
|
|
|
330
|
|
|
// TODO(evan): Support configurable transports... |
331
|
4417 |
|
$this->setClassName('mailer', 'Zend\Mail\Transport\Sendmail'); |
332
|
|
|
|
333
|
4417 |
|
$this->setFactory('menus', function(ServiceProvider $c) { |
334
|
3 |
|
return new \Elgg\Menu\Service($c->hooks, $c->config); |
335
|
4417 |
|
}); |
336
|
|
|
|
337
|
4417 |
|
$this->setFactory('metadataCache', function (ServiceProvider $c) { |
338
|
4417 |
|
$cache = $c->dataCache->metadata; |
339
|
4417 |
|
return new \Elgg\Cache\MetadataCache($cache); |
340
|
4417 |
|
}); |
341
|
|
|
|
342
|
4417 |
|
$this->setFactory('metadataTable', function(ServiceProvider $c) { |
343
|
|
|
// TODO(ewinslow): Use Pool instead of MetadataCache for caching |
344
|
11 |
|
return new \Elgg\Database\MetadataTable($c->metadataCache, $c->db, $c->hooks->getEvents()); |
345
|
4417 |
|
}); |
346
|
|
|
|
347
|
4417 |
|
$this->setFactory('mutex', function(ServiceProvider $c) { |
348
|
2 |
|
return new \Elgg\Database\Mutex( |
349
|
2 |
|
$c->db, |
350
|
2 |
|
$c->logger |
351
|
|
|
); |
352
|
4417 |
|
}); |
353
|
|
|
|
354
|
4417 |
|
$this->setFactory('notifications', function(ServiceProvider $c) { |
355
|
|
|
// @todo move queue in service provider |
356
|
17 |
|
$queue_name = \Elgg\Notifications\NotificationsService::QUEUE_NAME; |
357
|
17 |
|
$queue = new \Elgg\Queue\DatabaseQueue($queue_name, $c->db); |
358
|
17 |
|
$sub = new \Elgg\Notifications\SubscriptionsService($c->db); |
359
|
17 |
|
return new \Elgg\Notifications\NotificationsService($sub, $queue, $c->hooks, $c->session, $c->translator, $c->entityTable, $c->logger); |
360
|
4417 |
|
}); |
361
|
|
|
|
362
|
4417 |
|
$this->setFactory('persistentLogin', function(ServiceProvider $c) { |
363
|
4417 |
|
$global_cookies_config = $c->config->getCookieConfig(); |
364
|
4417 |
|
$cookie_config = $global_cookies_config['remember_me']; |
365
|
4417 |
|
$cookie_name = $cookie_config['name']; |
366
|
4417 |
|
$cookie_token = $c->request->cookies->get($cookie_name, ''); |
367
|
4417 |
|
return new \Elgg\PersistentLoginService( |
368
|
4417 |
|
$c->db, $c->session, $c->crypto, $cookie_config, $cookie_token); |
369
|
4417 |
|
}); |
370
|
|
|
|
371
|
4417 |
|
$this->setClassName('passwords', \Elgg\PasswordService::class); |
372
|
|
|
|
373
|
4417 |
|
$this->setFactory('plugins', function(ServiceProvider $c) { |
374
|
11 |
|
$cache = new CompositeCache('plugins', $c->config, ELGG_CACHE_RUNTIME); |
375
|
11 |
|
$plugins = new \Elgg\Database\Plugins($cache, $this->db); |
376
|
11 |
|
if ($c->config->enable_profiling) { |
377
|
|
|
$plugins->setTimer($c->timer); |
378
|
|
|
} |
379
|
11 |
|
return $plugins; |
380
|
4417 |
|
}); |
381
|
|
|
|
382
|
4417 |
|
$this->setFactory('privateSettingsCache', function(ServiceProvider $c) { |
383
|
26 |
|
return $c->dataCache->private_settings; |
384
|
4417 |
|
}); |
385
|
|
|
|
386
|
4417 |
|
$this->setFactory('printer', function(ServiceProvider $c) { |
|
|
|
|
387
|
4417 |
|
if (php_sapi_name() === 'cli') { |
388
|
4417 |
|
return new CliPrinter(); |
389
|
|
|
} else { |
390
|
|
|
return new HtmlPrinter(); |
391
|
|
|
} |
392
|
4417 |
|
}); |
393
|
|
|
|
394
|
4417 |
|
$this->setFactory('privateSettings', function(ServiceProvider $c) { |
395
|
9 |
|
return new \Elgg\Database\PrivateSettingsTable($c->db, $c->entityTable, $c->privateSettingsCache); |
396
|
4417 |
|
}); |
397
|
|
|
|
398
|
4417 |
|
$this->setFactory('publicDb', function(ServiceProvider $c) { |
399
|
12 |
|
return new \Elgg\Application\Database($c->db); |
400
|
4417 |
|
}); |
401
|
|
|
|
402
|
4417 |
|
$this->setFactory('queryCounter', function(ServiceProvider $c) { |
403
|
1 |
|
return new \Elgg\Database\QueryCounter($c->db); |
404
|
4417 |
|
}, false); |
405
|
|
|
|
406
|
4417 |
|
$this->setFactory('redirects', function(ServiceProvider $c) { |
407
|
1 |
|
$url = current_page_url(); |
408
|
1 |
|
$is_xhr = $c->request->isXmlHttpRequest(); |
409
|
1 |
|
return new \Elgg\RedirectService($c->session, $is_xhr, $c->config->wwwroot, $url); |
410
|
4417 |
|
}); |
411
|
|
|
|
412
|
4417 |
|
$this->setFactory('relationshipsTable', function(ServiceProvider $c) { |
413
|
11 |
|
return new \Elgg\Database\RelationshipsTable($c->db, $c->entityTable, $c->metadataTable, $c->hooks->getEvents()); |
414
|
4417 |
|
}); |
415
|
|
|
|
416
|
4417 |
|
$this->setFactory('request', [\Elgg\Http\Request::class, 'createFromGlobals']); |
417
|
|
|
|
418
|
4417 |
|
$this->setFactory('responseFactory', function(ServiceProvider $c) { |
419
|
6 |
|
if (php_sapi_name() === 'cli') { |
420
|
6 |
|
$transport = new \Elgg\Http\OutputBufferTransport(); |
421
|
|
|
} else { |
422
|
|
|
$transport = new \Elgg\Http\HttpProtocolTransport(); |
423
|
|
|
} |
424
|
6 |
|
return new \Elgg\Http\ResponseFactory($c->request, $c->hooks, $c->ajax, $transport); |
425
|
4417 |
|
}); |
426
|
|
|
|
427
|
4417 |
|
$this->setFactory('router', function(ServiceProvider $c) { |
428
|
|
|
// TODO(evan): Init routes from plugins or cache |
429
|
116 |
|
$router = new \Elgg\Router($c->hooks); |
430
|
116 |
|
if ($c->config->enable_profiling) { |
431
|
|
|
$router->setTimer($c->timer); |
432
|
|
|
} |
433
|
116 |
|
return $router; |
434
|
4417 |
|
}); |
435
|
|
|
|
436
|
4417 |
|
$this->setFactory('search', function(ServiceProvider $c) { |
437
|
34 |
|
return new \Elgg\Search\SearchService($c->config, $c->hooks, $c->db); |
438
|
4417 |
|
}); |
439
|
|
|
|
440
|
4417 |
|
$this->setFactory('seeder', function(ServiceProvider $c) { |
441
|
1 |
|
return new \Elgg\Database\Seeder($c->hooks); |
442
|
4417 |
|
}); |
443
|
|
|
|
444
|
4417 |
|
$this->setFactory('serveFileHandler', function(ServiceProvider $c) { |
445
|
10 |
|
return new \Elgg\Application\ServeFileHandler($c->hmac, $c->config); |
446
|
4417 |
|
}); |
447
|
|
|
|
448
|
4417 |
|
$this->setFactory('session', function(ServiceProvider $c) { |
449
|
|
|
return \ElggSession::fromDatabase($c->config, $c->db); |
450
|
4417 |
|
}); |
451
|
|
|
|
452
|
4417 |
|
$this->setFactory('sessionCache', function (ServiceProvider $c) { |
453
|
4417 |
|
return new SessionCache($c->config); |
454
|
4417 |
|
}); |
455
|
|
|
|
456
|
4417 |
|
$this->initSiteSecret($config); |
457
|
|
|
|
458
|
4417 |
|
$this->setClassName('urlSigner', \Elgg\Security\UrlSigner::class); |
459
|
|
|
|
460
|
4417 |
|
$this->setFactory('simpleCache', function(ServiceProvider $c) { |
461
|
133 |
|
return new \Elgg\Cache\SimpleCache($c->config); |
462
|
4417 |
|
}); |
463
|
|
|
|
464
|
4417 |
|
$this->setClassName('stickyForms', \Elgg\Forms\StickyForms::class); |
465
|
|
|
|
466
|
4417 |
|
$this->setFactory('systemCache', function (ServiceProvider $c) { |
467
|
4417 |
|
$cache = new \Elgg\Cache\SystemCache($c->fileCache, $c->config); |
468
|
4417 |
|
if ($c->config->enable_profiling) { |
469
|
|
|
$cache->setTimer($c->timer); |
470
|
|
|
} |
471
|
4417 |
|
return $cache; |
472
|
4417 |
|
}); |
473
|
|
|
|
474
|
4417 |
|
$this->setFactory('systemMessages', function(ServiceProvider $c) { |
475
|
26 |
|
return new \Elgg\SystemMessagesService($c->session); |
476
|
4417 |
|
}); |
477
|
|
|
|
478
|
4417 |
|
$this->setClassName('table_columns', \Elgg\Views\TableColumn\ColumnFactory::class); |
479
|
|
|
|
480
|
4417 |
|
$this->setClassName('temp_filestore', \ElggTempDiskFilestore::class); |
481
|
|
|
|
482
|
4417 |
|
$this->setClassName('timer', \Elgg\Timer::class); |
483
|
|
|
|
484
|
4417 |
|
$this->setFactory('translator', function(ServiceProvider $c) { |
485
|
4417 |
|
return new \Elgg\I18n\Translator($c->config); |
486
|
4417 |
|
}); |
487
|
|
|
|
488
|
4417 |
|
$this->setFactory('uploads', function(ServiceProvider $c) { |
489
|
7 |
|
return new \Elgg\UploadService($c->request, $c->imageService); |
490
|
4417 |
|
}); |
491
|
|
|
|
492
|
4417 |
|
$this->setFactory('upgrades', function(ServiceProvider $c) { |
493
|
1 |
|
return new \Elgg\UpgradeService( |
494
|
1 |
|
$c->translator, |
495
|
1 |
|
$c->hooks, |
496
|
1 |
|
$c->config, |
497
|
1 |
|
$c->logger, |
498
|
1 |
|
$c->mutex |
499
|
|
|
); |
500
|
4417 |
|
}); |
501
|
|
|
|
502
|
4417 |
|
$this->setFactory('userCapabilities', function(ServiceProvider $c) { |
503
|
479 |
|
return new \Elgg\UserCapabilities($c->hooks, $c->entityTable, $c->session); |
504
|
4417 |
|
}); |
505
|
|
|
|
506
|
4418 |
|
$this->setFactory('usersTable', function(ServiceProvider $c) { |
507
|
4418 |
|
return new \Elgg\Database\UsersTable( |
508
|
4418 |
|
$c->config, |
509
|
4418 |
|
$c->db, |
510
|
4418 |
|
$c->metadataTable |
511
|
|
|
); |
512
|
4417 |
|
}); |
513
|
|
|
|
514
|
4417 |
|
$this->setFactory('upgradeLocator', function(ServiceProvider $c) { |
515
|
7 |
|
return new \Elgg\Upgrade\Locator( |
516
|
7 |
|
$c->plugins, |
517
|
7 |
|
$c->logger, |
518
|
7 |
|
$c->privateSettings |
519
|
|
|
); |
520
|
4417 |
|
}); |
521
|
|
|
|
522
|
4417 |
|
$this->setFactory('views', function(ServiceProvider $c) { |
523
|
582 |
|
return new \Elgg\ViewsService($c->hooks, $c->logger, $c->input); |
524
|
4417 |
|
}); |
525
|
|
|
|
526
|
4417 |
|
$this->setFactory('viewCacher', function(ServiceProvider $c) { |
527
|
17 |
|
return new \Elgg\Cache\ViewCacher($c->views, $c->config); |
528
|
4417 |
|
}); |
529
|
|
|
|
530
|
4417 |
|
$this->setClassName('widgets', \Elgg\WidgetsService::class); |
531
|
4417 |
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* Extract the site secret from config or set up its factory |
535
|
|
|
* |
536
|
|
|
* @param Config $config Elgg Config |
537
|
|
|
* @return void |
538
|
|
|
*/ |
539
|
4417 |
|
protected function initSiteSecret(Config $config) { |
540
|
|
|
// Try the config, because if it's there we want to remove it to isolate who can see it. |
541
|
4417 |
|
$secret = SiteSecret::fromConfig($config); |
542
|
4417 |
|
if ($secret) { |
543
|
1 |
|
$this->setValue('siteSecret', $secret); |
544
|
1 |
|
$config->elgg_config_set_secret = true; |
545
|
1 |
|
return; |
546
|
|
|
} |
547
|
|
|
|
548
|
4417 |
|
$this->setFactory('siteSecret', function (ServiceProvider $c) { |
549
|
1 |
|
return SiteSecret::fromDatabase($c->configTable); |
550
|
4417 |
|
}); |
551
|
4417 |
|
} |
552
|
|
|
|
553
|
|
|
/** |
554
|
|
|
* Validate, normalize, fill in missing values, and lock some |
555
|
|
|
* |
556
|
|
|
* @param Config $config Config |
557
|
|
|
* @param ServiceProvider $sp Service Provider |
558
|
|
|
* |
559
|
|
|
* @return void |
560
|
|
|
* @throws ConfigurationException |
561
|
|
|
*/ |
562
|
4417 |
|
public function initConfig(Config $config, ServiceProvider $sp) { |
563
|
4417 |
|
if ($config->elgg_config_locks === null) { |
564
|
4417 |
|
$config->elgg_config_locks = true; |
565
|
|
|
} |
566
|
|
|
|
567
|
4417 |
|
if ($config->elgg_config_locks) { |
568
|
4417 |
|
$lock = function ($name) use ($config) { |
569
|
4417 |
|
$config->lock($name); |
570
|
4417 |
|
}; |
571
|
|
|
} else { |
572
|
|
|
// the installer needs to build an application with defaults then update |
573
|
|
|
// them after they're validated, so we don't want to lock them. |
574
|
9 |
|
$lock = function () { |
575
|
9 |
|
}; |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
$sp->timer->begin([]); |
579
|
|
|
|
580
|
|
|
if ($config->dataroot) { |
581
|
|
|
$config->dataroot = rtrim($config->dataroot, '\\/') . DIRECTORY_SEPARATOR; |
582
|
|
|
} else { |
583
|
|
|
if (!$config->installer_running) { |
584
|
|
|
throw new ConfigurationException('Config value "dataroot" is required.'); |
585
|
|
|
} |
586
|
|
|
} |
587
|
|
|
$lock('dataroot'); |
588
|
|
|
|
589
|
|
|
if ($config->cacheroot) { |
590
|
|
|
$config->cacheroot = rtrim($config->cacheroot, '\\/') . DIRECTORY_SEPARATOR; |
591
|
|
|
} else { |
592
|
|
|
$config->cacheroot = $config->dataroot; |
593
|
|
|
} |
594
|
|
|
$lock('cacheroot'); |
595
|
|
|
|
596
|
|
|
if ($config->wwwroot) { |
597
|
|
|
$config->wwwroot = rtrim($config->wwwroot, '/') . '/'; |
598
|
|
|
} else { |
599
|
|
|
$config->wwwroot = $sp->request->sniffElggUrl(); |
600
|
|
|
} |
601
|
|
|
$lock('wwwroot'); |
602
|
|
|
|
603
|
|
|
if (!$config->language) { |
604
|
|
|
$config->language = Application::DEFAULT_LANG; |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
if ($config->default_limit) { |
608
|
|
|
$lock('default_limit'); |
609
|
|
|
} else { |
610
|
|
|
$config->default_limit = Application::DEFAULT_LIMIT; |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
if ($config->plugins_path) { |
614
|
|
|
$plugins_path = rtrim($config->plugins_path, '/') . '/'; |
615
|
|
|
} else { |
616
|
|
|
$plugins_path = Paths::project() . 'mod/'; |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
$locked_props = [ |
620
|
|
|
'site_guid' => 1, |
621
|
|
|
'path' => Paths::project(), |
622
|
|
|
'plugins_path' => $plugins_path, |
623
|
|
|
'pluginspath' => $plugins_path, |
624
|
|
|
'url' => $config->wwwroot, |
625
|
|
|
]; |
626
|
|
|
foreach ($locked_props as $name => $value) { |
627
|
|
|
$config->$name = $value; |
628
|
|
|
$lock($name); |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
// move sensitive credentials into isolated services |
632
|
|
|
$sp->setValue('dbConfig', DbConfig::fromElggConfig($config)); |
633
|
|
|
|
634
|
|
|
// get this stuff out of config! |
635
|
|
|
unset($config->db); |
636
|
|
|
unset($config->dbname); |
637
|
|
|
unset($config->dbhost); |
638
|
|
|
unset($config->dbuser); |
639
|
|
|
unset($config->dbpass); |
640
|
|
|
|
641
|
|
|
$config->boot_complete = false; |
642
|
|
|
} |
643
|
|
|
} |
644
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.