-
Notifications
You must be signed in to change notification settings - Fork 6
/
bootstrap.php
45 lines (35 loc) · 1.13 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
namespace SqlDriver;
use MongoHybrid\ClientWrapper as MongoHybridClientWrapper;
use MongoSql\Driver\Driver;
// Set autoloader (may use composer generated if avail)
require_once __DIR__ . '/autoload.php';
$dbConfig = $app->retrieve('config/database');
// Skip when server other than sqldriver
if ($dbConfig['server'] !== Driver::SERVER_NAME) {
return;
}
/**
* Register on bootstrap
* @var \LimeExtra\App $this
* @var \LimeExtra\App $app
* @var \Lime\Module $module
*
* Note: classes may be autoloaded after app has booted which happens after module is booted
*/
$app->on('cockpit.bootstrap', function () use ($dbConfig): ?bool {
// Overwrite storage in registry
$this->set('storage', function () use ($dbConfig): MongoHybridClientWrapper {
static $client = null;
if ($client === null) {
$client = new MongoHybridClientWrapper(
$dbConfig['server'],
$dbConfig['options'],
$dbConfig['driverOptions']
);
}
return $client;
});
return true;
}, $dbConfig['options']['bootstrapPriority'] ?? 999);