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