Completed
Push — master ( ec656c...4bc6db )
by Jacob
04:58
created

bootstrap.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
include_once 'vendor/autoload.php';
4
5
// load the config for the application
6
$configuration_path = 'config.json';
7
8
$handle = @fopen($configuration_path, 'r');
9
if ($handle === false) {
10
    throw new RuntimeException("Could not load configuration");
11
}
12
$configuration = fread($handle, filesize($configuration_path));
13
fclose($handle);
14
15
$configuration = json_decode($configuration);
16
$last_json_error = json_last_error();
17
if ($last_json_error !== JSON_ERROR_NONE) {
18
    throw new RuntimeException("Could not parse configuration - JSON error detected");
19
}
20
21
// configure the db connections holder
22
$db_connections = new Aura\Sql\ConnectionLocator();
23
$db_connections->setDefault(function () use ($configuration) {
24
    $connection = $configuration->database->slave;
25
    return new Aura\Sql\ExtendedPdo(
26
        "mysql:host={$connection->host}",
27
        $connection->user,
28
        $connection->password
29
    );
30
});
31 View Code Duplication
$db_connections->setWrite('master', function () use ($configuration) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    $connection = $configuration->database->master;
33
    return new Aura\Sql\ExtendedPdo(
34
        "mysql:host={$connection->host}",
35
        $connection->user,
36
        $connection->password
37
    );
38
});
39 View Code Duplication
$db_connections->setRead('slave', function () use ($configuration) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    $connection = $configuration->database->slave;
41
    return new Aura\Sql\ExtendedPdo(
42
        "mysql:host={$connection->host}",
43
        $connection->user,
44
        $connection->password
45
    );
46
});
47
48
// setup the service locator
49
$container = new Pimple\Container();
50
$container['db_connection_locator'] = $db_connections;
51
52