-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
66 lines (57 loc) · 1.85 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
require_once __DIR__ . '/vendor/autoload.php';
// load the config for the application
$config_path = __DIR__ . '/config.json';
$handle = @fopen($config_path, 'r');
if ($handle === false) {
throw new RuntimeException("Could not load config");
}
$config = fread($handle, filesize($config_path));
fclose($handle);
$config = json_decode($config);
$last_json_error = json_last_error();
if ($last_json_error !== JSON_ERROR_NONE) {
throw new RuntimeException("Could not parse config - JSON error detected");
}
// timezones are fun
date_default_timezone_set('America/Phoenix');
// configure the db connections holder
$db = new Aura\Sql\ConnectionLocator();
$db->setDefault(function () use ($config) {
$connection = $config->database->slave;
return new Aura\Sql\ExtendedPdo(
"mysql:host={$connection->host}",
$connection->user,
$connection->password
);
});
$db->setWrite('master', function () use ($config) {
$connection = $config->database->master;
return new Aura\Sql\ExtendedPdo(
"mysql:host={$connection->host}",
$connection->user,
$connection->password
);
});
$db->setRead('slave', function () use ($config) {
$connection = $config->database->slave;
$pdo = new Aura\Sql\ExtendedPdo(
"mysql:host={$connection->host}",
$connection->user,
$connection->password
);
$profiler = new Aura\Sql\Profiler();
$profiler->setActive(true);
$pdo->setProfiler($profiler);
return $pdo;
});
// setup logger
$logName = $_SERVER['PHP_SELF'];
$logName = explode('/', $logName);
$logName = end($logName);
$logName = explode('.', $logName);
$logName = current($logName);
$logPath = __DIR__ . "/logs/{$logName}.log";
$streamHandler = new Monolog\Handler\StreamHandler($logPath, Monolog\Logger::INFO);
$logger = new Monolog\Logger('script');
$logger->pushHandler($streamHandler);