v0.5.0
This commit is contained in:
60
app/setup/setups/services.php
Normal file
60
app/setup/setups/services.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
|
||||
return new Monolog\Logger('file', [
|
||||
new Monolog\Handler\FilterHandler(
|
||||
new Monolog\Handler\RotatingFileHandler('/var/log/remote.debug.log'),
|
||||
Monolog\Level::Debug,
|
||||
Monolog\Level::Warning
|
||||
),
|
||||
new Monolog\Handler\FilterHandler(
|
||||
new Monolog\Handler\RotatingFileHandler('/var/log/remote.error.log'),
|
||||
Monolog\Level::Error
|
||||
)
|
||||
], [
|
||||
new Monolog\Processor\PsrLogMessageProcessor(),
|
||||
new Monolog\Processor\IntrospectionProcessor(),
|
||||
new Monolog\Processor\MemoryUsageProcessor(),
|
||||
new Monolog\Processor\MemoryPeakUsageProcessor(),
|
||||
]);
|
||||
},
|
||||
Psr\Http\Client\ClientInterface::class => function(ContainerInterface $container) {
|
||||
return new GuzzleHttp\Client([
|
||||
'base_uri' => $container->get('uri')
|
||||
]);
|
||||
},
|
||||
ProVM\Service\Ipify::class => function(ContainerInterface $container) {
|
||||
return new ProVM\Service\Ipify(
|
||||
$container->get(Psr\Http\Client\ClientInterface::class),
|
||||
$container->get(Psr\Log\LoggerInterface::class)
|
||||
);
|
||||
},
|
||||
PDO::class => function(ContainerInterface $container) {
|
||||
$database = $container->get('database');
|
||||
$retries = $container->get('retries');
|
||||
$r = 0;
|
||||
$exception = null;
|
||||
while($r < $retries) {
|
||||
try {
|
||||
$dsn = "mysql:host={$database->get('host')};dbname={$database->get('name')}";
|
||||
return new PDO($dsn, $database->get('user')->get('name'), $database->get('user')->get('password'));
|
||||
} catch (PDOException $e) {
|
||||
if ($exception !== null) {
|
||||
$e = new PDOException($e->getMessage(), $e->getCode(), $exception);
|
||||
}
|
||||
$exception = $e;
|
||||
$container->get(Psr\Log\LoggerInterface::class)->debug('Retrying Connection');
|
||||
}
|
||||
}
|
||||
throw $exception;
|
||||
},
|
||||
ProVM\Service\Repository::class => function(ContainerInterface $container) {
|
||||
return new ProVM\Service\Repository(
|
||||
$container->get(PDO::class),
|
||||
$container->get('database')->get('table'),
|
||||
$container->get(Psr\Log\LoggerInterface::class)
|
||||
);
|
||||
}
|
||||
];
|
Reference in New Issue
Block a user