Cli
This commit is contained in:
1
.db.env
1
.db.env
@ -2,3 +2,4 @@ MYSQL_DATABASE=incoviba
|
||||
MYSQL_PASSWORD=5GQYFvRjVw2A4KcD
|
||||
MYSQL_ROOT_PASSWORD=password
|
||||
MYSQL_USER=incoviba
|
||||
MYSQL_PORT=3307
|
||||
|
@ -1,8 +1,12 @@
|
||||
<?php
|
||||
namespace App\Contract;
|
||||
|
||||
use App\Alias\RemoteConnection;
|
||||
use App\Definition\Contract;
|
||||
use App\Service\Money;
|
||||
use App\Service\Remote;
|
||||
use App\Service\View as ViewService;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class View
|
||||
{
|
||||
@ -10,7 +14,12 @@ class View
|
||||
|
||||
protected static function newInstance()
|
||||
{
|
||||
return new ViewService();
|
||||
$remote = new Remote(new RemoteConnection());
|
||||
$money = (new Money(new Client([
|
||||
'base_uri' => "http://{$remote->getIP()}:8008",
|
||||
'headers' => ['Accept' => 'application/json']
|
||||
])));
|
||||
return new ViewService(['money' => $money]);
|
||||
}
|
||||
public static function show($template, $variables = null)
|
||||
{
|
||||
|
@ -9,12 +9,12 @@ class View
|
||||
protected $cache;
|
||||
protected $blade;
|
||||
|
||||
public function __construct()
|
||||
public function __construct(array $variables = [])
|
||||
{
|
||||
$this->views = config('locations.views');
|
||||
$this->cache = config('locations.cache');
|
||||
|
||||
$this->blade = new BladeOne($this->views, $this->cache);
|
||||
$this->blade = new BladeOne($this->views, $this->cache, null, $variables);
|
||||
}
|
||||
public function show($template, $vars = null)
|
||||
{
|
||||
|
50
app/Alias/Connection.php
Normal file
50
app/Alias/Connection.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace App\Alias;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
|
||||
class Connection
|
||||
{
|
||||
public function __construct(
|
||||
protected string $host,
|
||||
protected string $database,
|
||||
protected string $username,
|
||||
protected string $password,
|
||||
protected ?int $port = null,
|
||||
protected int $retries = 5
|
||||
) {}
|
||||
|
||||
protected PDO $connection;
|
||||
public function connect(): PDO
|
||||
{
|
||||
if (!isset($this->connection)) {
|
||||
$r = 0;
|
||||
$exception = null;
|
||||
while ($r < $this->retries) {
|
||||
try {
|
||||
$dsn = $this->getDsn();
|
||||
$this->connection = new PDO($dsn, $this->username, $this->password);
|
||||
return $this->connection;
|
||||
} catch (PDOException $e) {
|
||||
if ($exception !== null) {
|
||||
$e = new PDOException($e->getMessage(), $e->getCode(), $exception);
|
||||
}
|
||||
$exception = $e;
|
||||
usleep(500);
|
||||
}
|
||||
$r ++;
|
||||
}
|
||||
throw $exception;
|
||||
}
|
||||
return $this->connection;
|
||||
}
|
||||
protected function getDsn(): string
|
||||
{
|
||||
$dsn = "mysql:host={$this->host};dbname={$this->database}";
|
||||
if (isset($this->port)) {
|
||||
$dsn .= ";port={$this->port}";
|
||||
}
|
||||
return $dsn;
|
||||
}
|
||||
}
|
@ -1,58 +1,17 @@
|
||||
<?php
|
||||
namespace App\Alias;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
|
||||
class RemoteConnection
|
||||
class RemoteConnection extends Connection
|
||||
{
|
||||
public function __construct(protected int $retries = 5)
|
||||
{
|
||||
$this->host = $_ENV['REMOTE_HOST'];
|
||||
$this->database = $_ENV['REMOTE_DATABASE'];
|
||||
$this->username = $_ENV['REMOTE_USER'];
|
||||
$this->password = $_ENV['REMOTE_PASSWORD'];
|
||||
if (isset($_ENV['REMOTE_PORT'])) {
|
||||
$this->port = $_ENV['REMOTE_PORT'];
|
||||
}
|
||||
}
|
||||
|
||||
protected string $host;
|
||||
protected string $database;
|
||||
protected int $port;
|
||||
protected string $username;
|
||||
protected string $password;
|
||||
|
||||
protected PDO $connection;
|
||||
public function connect(): PDO
|
||||
{
|
||||
if (!isset($this->connection)) {
|
||||
$r = 0;
|
||||
$exception = null;
|
||||
while ($r < $this->retries) {
|
||||
try {
|
||||
$dsn = $this->getDsn();
|
||||
$this->connection = new PDO($dsn, $this->username, $this->password);
|
||||
} catch (PDOException $e) {
|
||||
if ($exception !== null) {
|
||||
$e = new PDOException($e->getMessage(), $e->getCode(), $exception);
|
||||
}
|
||||
$exception = $e;
|
||||
usleep(500);
|
||||
}
|
||||
$r ++;
|
||||
}
|
||||
throw $exception;
|
||||
}
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
protected function getDsn(): string
|
||||
{
|
||||
$dsn = "mysql:host={$this->host};dbname={$this->database}";
|
||||
if (isset($this->port)) {
|
||||
$dsn .= ";port={$this->port}";
|
||||
}
|
||||
return $dsn;
|
||||
parent::__construct(
|
||||
$_ENV['REMOTE_HOST'],
|
||||
$_ENV['REMOTE_DATABASE'],
|
||||
$_ENV['REMOTE_USER'],
|
||||
$_ENV['REMOTE_PASSWORD'],
|
||||
$_ENV['REMOTE_PORT'] ?? null,
|
||||
$this->retries
|
||||
);
|
||||
}
|
||||
}
|
||||
|
86
app/Command/Money/Get.php
Normal file
86
app/Command/Money/Get.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
namespace App\Command\Money;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use App\Alias\Connection;
|
||||
use App\Service\Money;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'money:uf:get',
|
||||
hidden: false
|
||||
)]
|
||||
class Get extends Command
|
||||
{
|
||||
public function __construct(protected Money $service, protected Connection $connection, string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title('Get Money');
|
||||
|
||||
$dates = $this->getDates();
|
||||
foreach ($dates as $date_string => $ids) {
|
||||
$date = $this->parseDate($date_string);
|
||||
$response = $this->service->getUF($date);
|
||||
if ($response->total === 0) {
|
||||
continue;
|
||||
}
|
||||
foreach ($ids as $id) {
|
||||
$this->queueUpdate($id, $response->uf->value);
|
||||
}
|
||||
}
|
||||
$this->updateUF();
|
||||
}
|
||||
|
||||
protected function getDates(): array
|
||||
{
|
||||
$query = "SELECT id, fecha FROM pago WHERE uf IS NULL AND fecha BETWEEN 0 AND DATE_ADD(CURDATE(), INTERVAL 9 DAY) ORDER BY fecha";
|
||||
$statement = $this->connection->connect()->query($query);
|
||||
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (count($rows) === 0) {
|
||||
return [];
|
||||
}
|
||||
$dates = [];
|
||||
foreach ($rows as $row) {
|
||||
if (!isset($dates[$row['fecha']])) {
|
||||
$dates[$row['fecha']] = [];
|
||||
}
|
||||
$dates[$row['fecha']] []= (int) $row['id'];
|
||||
}
|
||||
return $dates;
|
||||
}
|
||||
protected function parseDate(string $date_string): DateTimeInterface
|
||||
{
|
||||
return new DateTimeImmutable($date_string);
|
||||
}
|
||||
protected array $rows;
|
||||
protected function queueUpdate(int $id, float $value): void
|
||||
{
|
||||
$this->rows []= [$value, $id];
|
||||
}
|
||||
protected function updateUF(): void
|
||||
{
|
||||
$query = "UPDATE pago SET uf = ? WHERE id = ?";
|
||||
$statement = $this->connection->connect()->prepare($query);
|
||||
foreach ($this->rows as $row) {
|
||||
$this->connection->connect()->beginTransaction();
|
||||
try {
|
||||
$statement->execute($row);
|
||||
$this->connection->connect()->commit();
|
||||
} catch (PDOException $e) {
|
||||
$this->connection->connect()->rollBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
app/Command/Money/Lookup.php
Normal file
51
app/Command/Money/Lookup.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace App\Command\Money;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use App\Alias\Connection;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'money:lookup',
|
||||
hidden: false
|
||||
)]
|
||||
class Lookup extends Command
|
||||
{
|
||||
public function __construct(protected Connection $connection, string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->title('Lookup Money');
|
||||
|
||||
while (true) {
|
||||
$io->info('Checking pending');
|
||||
if ($this->hasPendingMoney()) {
|
||||
$io->success('Running money get UF');
|
||||
$io->note($this->runGetUF());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function hasPendingMoney(): bool
|
||||
{
|
||||
$query = "SELECT 1 FROM pago WHERE uf IS NULL AND fecha BETWEEN 0 AND DATE_ADD(CURDATE(), INTERVAL 9 DAY)";
|
||||
$statement = $this->connection->connect()->query($query);
|
||||
return $statement->rowCount() > 0;
|
||||
}
|
||||
protected function runGetUF(): string
|
||||
{
|
||||
$command = "/code/bin/console money:uf:get";
|
||||
$result = shell_exec($command);
|
||||
if (!$result or $result === null) {
|
||||
throw new \Exception();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
@ -312,7 +312,7 @@ class Proyectos
|
||||
}
|
||||
return view('proyectos.reservas.base', compact('proyecto', 'pisos', 'max_unidades', 'totales'));
|
||||
}
|
||||
public function unidades()
|
||||
public static function unidades()
|
||||
{
|
||||
if (get('proyecto')) {
|
||||
$proyecto = model(Proyecto::class)->findOne(get('proyecto'));
|
||||
|
@ -40,6 +40,7 @@ class Money
|
||||
protected function checkNextMonthValueCalculationByDate(DateTimeInterface $date): bool
|
||||
{
|
||||
$next_m_9 = Carbon::today(config('app.timezone'))->copy()->endOfMonth()->addDays(9);
|
||||
$date = Carbon::parse($date);
|
||||
return $date->lessThan($next_m_9);
|
||||
}
|
||||
protected function isOk(ResponseInterface $response): bool
|
||||
|
3
bin/console
Normal file
3
bin/console
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
php /code/bin/index.php "$@"
|
8
bin/index.php
Normal file
8
bin/index.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
//$__environment = 'cli';
|
||||
$app = include_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__FILE__, 2),
|
||||
'setup',
|
||||
'cli.app.php'
|
||||
]);
|
||||
$app->run();
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
include_once dirname(__DIR__) . '/vendor/autoload.php';
|
||||
include_once 'errors.php';
|
||||
include_once 'logs.php';
|
||||
include_once 'dotenv.php';
|
||||
include_once 'database.php';
|
||||
include_once 'routes.php';
|
||||
|
@ -27,4 +27,3 @@ function load($data, $name = '') {
|
||||
}
|
||||
|
||||
Model::$short_table_names = true;
|
||||
?>
|
||||
|
26
bootstrap/logs.php
Normal file
26
bootstrap/logs.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
use Monolog\{Handler,Processor,Formatter,Level};
|
||||
|
||||
function buildLogger() {
|
||||
$logger = new Monolog\Logger('global', [
|
||||
new Handler\FilterHandler(new Handler\RotatingFileHandler('/logs/php.log'),
|
||||
Level::Debug,
|
||||
Level::Notice
|
||||
),
|
||||
new Handler\FilterHandler(new Handler\RotatingFileHandler('/logs/error.log'),
|
||||
Level::Warning,
|
||||
Level::Critical
|
||||
),
|
||||
new Handler\FilterHandler(new Handler\NativeMailerHandler('jpvial@incoviba.cl', 'Incoviba Error', 'alert@incoviba.cl'),
|
||||
Level::Alert
|
||||
)
|
||||
], [
|
||||
new Processor\PsrLogMessageProcessor(),
|
||||
new Processor\IntrospectionProcessor(),
|
||||
new Processor\WebProcessor(),
|
||||
new Processor\MemoryPeakUsageProcessor()
|
||||
]);
|
||||
return $logger;
|
||||
}
|
||||
$logger = buildLogger();
|
||||
Monolog\ErrorHandler::register($logger);
|
@ -3,28 +3,30 @@
|
||||
"description" : "Intranet portal for Incoviba",
|
||||
"type" : "project",
|
||||
"require" : {
|
||||
"aldarien/config" : "*",
|
||||
"aldarien/asset" : "*",
|
||||
"aldarien/format" : "*",
|
||||
"aldarien/response" : "*",
|
||||
"aldarien/view" : "*",
|
||||
"aldarien/session" : "*",
|
||||
"aldarien/asset": "*",
|
||||
"aldarien/config": "*",
|
||||
"aldarien/format": "*",
|
||||
"aldarien/response": "*",
|
||||
"aldarien/session": "*",
|
||||
"aldarien/url": "*",
|
||||
"j4mie/paris" : "^1.5",
|
||||
"voku/stringy" : "^6",
|
||||
"phpoffice/phpspreadsheet": "^1",
|
||||
"nesbot/carbon": "^2",
|
||||
"phpoffice/phpword": "^0",
|
||||
"slam/php-excel": "^4.4",
|
||||
"aldarien/view": "*",
|
||||
"guzzlehttp/guzzle": "*",
|
||||
"incoviba/modelos": "*",
|
||||
"slim/slim": "^4",
|
||||
"php-di/slim-bridge": "*",
|
||||
"rubellum/slim-blade-view": "*",
|
||||
"j4mie/paris": "^1.5",
|
||||
"monolog/monolog": "^3",
|
||||
"nesbot/carbon": "^2",
|
||||
"nyholm/psr7": "*",
|
||||
"nyholm/psr7-server": "*",
|
||||
"php-di/php-di": "*",
|
||||
"php-di/slim-bridge": "*",
|
||||
"phpoffice/phpspreadsheet": "^1",
|
||||
"phpoffice/phpword": "^0",
|
||||
"rubellum/slim-blade-view": "*",
|
||||
"slam/php-excel": "^4.4",
|
||||
"slim/slim": "^4",
|
||||
"symfony/console": "6.4.x-dev",
|
||||
"vlucas/phpdotenv": "^5.3",
|
||||
"monolog/monolog": "^3"
|
||||
"voku/stringy": "^6"
|
||||
},
|
||||
"require-dev" : {
|
||||
"phpunit/phpunit" : "*",
|
||||
|
@ -7,4 +7,3 @@ return [
|
||||
'benchmark' => false,
|
||||
'login_hours' => 5*24
|
||||
];
|
||||
?>
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
include_once dirname(__DIR__) . '/bootstrap/dotenv.php';
|
||||
|
||||
return [
|
||||
function buildDatabaseConfig(): array {
|
||||
$arr = [
|
||||
'mysql' => [
|
||||
'host' => $_ENV['MYSQL_HOST'],
|
||||
//'port' => 3306,
|
||||
'database' => $_ENV['MYSQL_DATABASE'],
|
||||
'username' => $_ENV['MYSQL_USER'],
|
||||
'password' => $_ENV['MYSQL_PASSWORD']
|
||||
@ -15,5 +15,10 @@ return [
|
||||
'username' => 'incoviba',
|
||||
'password' => $_ENV['MYSQL_PASSWORD']
|
||||
]
|
||||
]
|
||||
?>
|
||||
];
|
||||
if (isset($_ENV['MYSQL_PORT'])) {
|
||||
$arr['mysql']['port'] = $_ENV['MYSQL_PORT'];
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
return buildDatabaseConfig();
|
||||
|
@ -25,6 +25,7 @@ services:
|
||||
env_file:
|
||||
- .env
|
||||
- .db.env
|
||||
- .remote.env
|
||||
volumes:
|
||||
- .:/code
|
||||
- ./php-errors.ini:/usr/local/etc/php/conf.d/docker-php-errors.ini
|
||||
@ -39,6 +40,9 @@ services:
|
||||
env_file: .db.env
|
||||
volumes:
|
||||
- dbdata:/var/lib/mysql
|
||||
networks:
|
||||
- default
|
||||
- adminer_network
|
||||
|
||||
adminer:
|
||||
profiles:
|
||||
@ -68,6 +72,7 @@ services:
|
||||
container_name: incoviba_logview
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
WEB_URL: 'http://provm.cl:8084'
|
||||
WEB_PORT: '8084'
|
||||
volumes:
|
||||
- "./logs:/logs"
|
||||
@ -76,3 +81,6 @@ services:
|
||||
|
||||
volumes:
|
||||
dbdata:
|
||||
|
||||
networks:
|
||||
adminer_network: {}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
$__environment = 'api';
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
$app = include_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 2),
|
||||
'setup',
|
||||
'app.php'
|
||||
|
5
resources/routes/cli.php
Normal file
5
resources/routes/cli.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
use App\Command;
|
||||
|
||||
$app->add($app->getContainer()->get(Command\Money\Lookup::class));
|
||||
$app->add($app->getContainer()->get(Command\Money\Get::class));
|
@ -9,6 +9,9 @@ $folders = [
|
||||
'setups'
|
||||
];
|
||||
$builder = new Builder();
|
||||
if (isset($__environment)) {
|
||||
$builder->addDefinitions(['environment' => $__environment]);
|
||||
}
|
||||
foreach ($folders as $f) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
@ -50,3 +53,5 @@ $app->addErrorMiddleware(true, true, true);
|
||||
include_once 'database.php';
|
||||
|
||||
include_once 'router.php';
|
||||
|
||||
return $app;
|
||||
|
48
setup/cli.app.php
Normal file
48
setup/cli.app.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
use DI\ContainerBuilder;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
require_once 'composer.php';
|
||||
|
||||
$builder = new ContainerBuilder();
|
||||
$files = [
|
||||
'config',
|
||||
'setups'
|
||||
];
|
||||
foreach ($files as $f) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
'cli',
|
||||
"{$f}.php"
|
||||
]);
|
||||
if (!file_exists($filename)) {
|
||||
continue;
|
||||
}
|
||||
$builder->addDefinitions($filename);
|
||||
}
|
||||
$app = new class() extends Application
|
||||
{
|
||||
protected ContainerInterface $container;
|
||||
public function getContainer(): ContainerInterface
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
public function setContainer(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
return $this;
|
||||
}
|
||||
};
|
||||
$app->setContainer($builder->build());
|
||||
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
'cli',
|
||||
'middlewares.php'
|
||||
]);
|
||||
if (file_exists($filename)) {
|
||||
include_once $filename;
|
||||
}
|
||||
|
||||
return $app;
|
26
setup/cli/config.php
Normal file
26
setup/cli/config.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
return [
|
||||
'databases' => function() {
|
||||
$container = new DI\Container([
|
||||
ORM::DEFAULT_CONNECTION => new DI\Container([
|
||||
'host' => $_ENV['MYSQL_HOST'],
|
||||
'database' => $_ENV['MYSQL_DATABASE'],
|
||||
'username' => $_ENV['MYSQL_USER'],
|
||||
'password' => $_ENV['MYSQL_PASSWORD']
|
||||
]),
|
||||
'remote' => new DI\Container([
|
||||
'host' => $_ENV['REMOTE_HOST'],
|
||||
'database' => $_ENV['REMOTE_DATABASE'],
|
||||
'username' => $_ENV['REMOTE_USER'],
|
||||
'password' => $_ENV['REMOTE_PASSWORD']
|
||||
])
|
||||
]);
|
||||
if (isset($_ENV['MYSQL_PORT'])) {
|
||||
$container->get(ORM::DEFAULT_CONNECTION)->set('port', $_ENV['MYSQL_PORT']);
|
||||
}
|
||||
if (isset($_ENV['REMOTE_PORT'])) {
|
||||
$container->get('remote')->set('port', $_ENV['REMOTE_PORT']);
|
||||
}
|
||||
return $container;
|
||||
}
|
||||
];
|
9
setup/cli/middlewares.php
Normal file
9
setup/cli/middlewares.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__FILE__, 3),
|
||||
'resources',
|
||||
'routes',
|
||||
'cli.php'
|
||||
]);
|
||||
|
||||
Monolog\ErrorHandler::register($app->getContainer()->get(Psr\Log\LoggerInterface::class));
|
43
setup/cli/setups.php
Normal file
43
setup/cli/setups.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
|
||||
return new Monolog\Logger('cli', [
|
||||
new Monolog\Handler\FilterHandler(new Monolog\Handler\RotatingFileHandler('/logs/cli.debug.log'), Monolog\Level::Debug, Monolog\Level::Notice),
|
||||
new Monolog\Handler\FilterHandler(new Monolog\Handler\RotatingFileHandler('/logs/cli.error.log'), Monolog\Level::Warning)
|
||||
], [
|
||||
new Monolog\Processor\PsrLogMessageProcessor(),
|
||||
new Monolog\Processor\IntrospectionProcessor(),
|
||||
new Monolog\Processor\MemoryUsageProcessor(),
|
||||
new Monolog\Processor\MemoryPeakUsageProcessor()
|
||||
]);
|
||||
},
|
||||
GuzzleHttp\Client::class => function(ContainerInterface $container) {
|
||||
return new GuzzleHttp\Client([
|
||||
'base_uri' => "http://{$container->get(App\Service\Remote::class)->getIP()}:8008",
|
||||
'headers' => [
|
||||
'Accept' => 'application/json'
|
||||
]
|
||||
]);
|
||||
},
|
||||
App\Alias\RemoteConnection::class => function(ContainerInterface $container) {
|
||||
return new App\Alias\RemoteConnection();
|
||||
},
|
||||
App\Service\Remote::class => function(ContainerInterface $container) {
|
||||
return new App\Service\Remote($container->get(App\Alias\RemoteConnection::class));
|
||||
},
|
||||
App\Service\Money::class => function(ContainerInterface $container) {
|
||||
return new App\Service\Money($container->get(GuzzleHttp\Client::class));
|
||||
},
|
||||
App\Alias\Connection::class => function(ContainerInterface $container) {
|
||||
$data = $container->get('databases')->get(ORM::DEFAULT_CONNECTION);
|
||||
return new App\Alias\Connection(
|
||||
$data->get('host'),
|
||||
$data->get('database'),
|
||||
$data->get('username'),
|
||||
$data->get('password'),
|
||||
$data->has('port') ? $data->get('port') : null
|
||||
);
|
||||
},
|
||||
];
|
Reference in New Issue
Block a user