These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | require_once __DIR__ . '/vendor/autoload.php'; |
||
4 | |||
5 | $container = new Pimple\Container(); |
||
6 | |||
7 | |||
8 | // load the config for the application |
||
9 | $config_path = __DIR__ . '/config.json'; |
||
10 | |||
11 | $handle = @fopen($config_path, 'r'); |
||
12 | if ($handle === false) { |
||
13 | throw new RuntimeException("Could not load config"); |
||
14 | } |
||
15 | $config = fread($handle, filesize($config_path)); |
||
16 | fclose($handle); |
||
17 | |||
18 | $config = json_decode($config); |
||
19 | $last_json_error = json_last_error(); |
||
20 | if ($last_json_error !== JSON_ERROR_NONE) { |
||
21 | throw new RuntimeException("Could not parse config - JSON error detected"); |
||
22 | } |
||
23 | $container['config'] = $config; |
||
24 | |||
25 | |||
26 | // timezones are fun |
||
27 | date_default_timezone_set('America/Phoenix'); // todo - belongs in configuration |
||
28 | $container['default_timezone'] = function ($c) { |
||
29 | return new DateTimeZone('America/Phoenix'); |
||
30 | }; |
||
31 | |||
32 | |||
33 | // configure the db connections holder |
||
34 | $db_connections = new Aura\Sql\ConnectionLocator(); |
||
35 | $db_connections->setDefault(function () use ($config) { |
||
36 | $connection = $config->database->slave; |
||
37 | return new Aura\Sql\ExtendedPdo( |
||
38 | "mysql:host={$connection->host}", |
||
39 | $connection->user, |
||
40 | $connection->password |
||
41 | ); |
||
42 | }); |
||
43 | $db_connections->setWrite('master', function () use ($config) { |
||
44 | $connection = $config->database->master; |
||
45 | return new Aura\Sql\ExtendedPdo( |
||
46 | "mysql:host={$connection->host}", |
||
47 | $connection->user, |
||
48 | $connection->password |
||
49 | ); |
||
50 | }); |
||
51 | $db_connections->setRead('slave', function () use ($config) { |
||
52 | $connection = $config->database->slave; |
||
53 | $pdo = new Aura\Sql\ExtendedPdo( |
||
54 | "mysql:host={$connection->host}", |
||
55 | $connection->user, |
||
56 | $connection->password |
||
57 | ); |
||
58 | |||
59 | $profiler = new Aura\Sql\Profiler(); |
||
60 | $profiler->setActive(true); |
||
61 | $pdo->setProfiler($profiler); |
||
62 | |||
63 | return $pdo; |
||
64 | }); |
||
65 | $container['db_connection_locator'] = $db_connections; |
||
66 | |||
67 | |||
68 | // setup mail handler |
||
69 | $container['mail'] = $container->factory(function ($c) { |
||
0 ignored issues
–
show
|
|||
70 | return new Jacobemerick\Archangel\Archangel(); |
||
71 | }); |
||
72 | |||
73 | |||
74 | // setup the logger |
||
75 | $container['setup_logger'] = $container->protect(function ($name) use ($container) { |
||
76 | $logger = new Monolog\Logger($name); |
||
77 | |||
78 | $logPath = __DIR__ . "/../logs/{$name}.log"; |
||
79 | $streamHandler = new Monolog\Handler\StreamHandler($logPath, Monolog\Logger::INFO); |
||
80 | $streamHandler->setFormatter( |
||
81 | new Monolog\Formatter\LineFormatter("[%datetime%] %channel%.%level_name%: %message%\n") |
||
82 | ); |
||
83 | $logger->pushHandler($streamHandler); |
||
84 | |||
85 | Monolog\ErrorHandler::register($logger); |
||
86 | $container['logger'] = $logger; |
||
87 | }); |
||
88 | |||
89 | |||
90 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.