CLI
This commit is contained in:
14
CLI.Dockerfile
Normal file
14
CLI.Dockerfile
Normal file
@ -0,0 +1,14 @@
|
||||
FROM php:8.1-fpm
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends cron && rm -r /var/lib/apt/lists/*
|
||||
|
||||
RUN pecl install xdebug-3.1.3 \
|
||||
&& docker-php-ext-enable xdebug
|
||||
|
||||
COPY ./php-errors.ini /usr/local/etc/php/conf.d/docker-php-errors.ini
|
||||
|
||||
WORKDIR /code
|
||||
|
||||
COPY ./cli/crontab /var/spool/cron/crontabs/root
|
||||
|
||||
CMD ["cron", "-f"]
|
20
cli/common/Alias/Application.php
Normal file
20
cli/common/Alias/Application.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Alias;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\Console\Application as Base;
|
||||
|
||||
class Application extends Base
|
||||
{
|
||||
public function __construct(protected ContainerInterface $container, string $name = 'UNKNOWN', string $version = 'UNKNOWN')
|
||||
{
|
||||
if ($this->container->has('APP_NAME')) {
|
||||
$name = $this->container->get('APP_NAME');
|
||||
}
|
||||
parent::__construct($name, $version);
|
||||
}
|
||||
public function getContainer(): ContainerInterface
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
}
|
29
cli/composer.json
Normal file
29
cli/composer.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "incoviba/cli",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"symfony/console": "^6.3",
|
||||
"php-di/php-di": "^7.0",
|
||||
"guzzlehttp/guzzle": "^7.8",
|
||||
"monolog/monolog": "^3.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^10.4",
|
||||
"kint-php/kint": "^5.1"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Aldarien",
|
||||
"email": "aldarien85@gmail.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Incoviba\\Common\\": "common/",
|
||||
"Incoviba\\": "src/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
}
|
||||
}
|
8
cli/crontab
Normal file
8
cli/crontab
Normal file
@ -0,0 +1,8 @@
|
||||
0 2 * * * php /code/bin/index.php ventas:cuotas:hoy
|
||||
0 2 * * * php /code/bin/index.php ventas:cuotas:pendientes
|
||||
0 2 * * * php /code/bin/index.php ventas:cuotas:vencer
|
||||
0 2 * * * php /code/bin/index.php ventas:cierres:vigentes
|
||||
0 2 * * * php /code/bin/index.php proyectos:activos
|
||||
0 2 * * * php /code/bin/index.php comunas
|
||||
0 2 * * * php /code/bin/index.php money:uf
|
||||
0 2 1 * * php /code/bin/index.php money:ipc
|
2
cli/resources/commands/comunas.php
Normal file
2
cli/resources/commands/comunas.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$app->add($app->getContainer()->get(Incoviba\Command\Comunas::class));
|
3
cli/resources/commands/money.php
Normal file
3
cli/resources/commands/money.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
$app->add($app->getContainer()->get(Incoviba\Command\Money\UF::class));
|
||||
$app->add($app->getContainer()->get(Incoviba\Command\Money\IPC::class));
|
9
cli/resources/commands/proyectos.php
Normal file
9
cli/resources/commands/proyectos.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'proyectos']);
|
||||
$files = new FilesystemIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
2
cli/resources/commands/proyectos/activos.php
Normal file
2
cli/resources/commands/proyectos/activos.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$app->add($app->getContainer()->get(Incoviba\Command\Proyectos\Activos::class));
|
9
cli/resources/commands/ventas.php
Normal file
9
cli/resources/commands/ventas.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'ventas']);
|
||||
$files = new FilesystemIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
2
cli/resources/commands/ventas/cierres.php
Normal file
2
cli/resources/commands/ventas/cierres.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$app->add($app->getContainer()->get(Incoviba\Command\Ventas\Cierres\Vigentes::class));
|
4
cli/resources/commands/ventas/cuotas.php
Normal file
4
cli/resources/commands/ventas/cuotas.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
$app->add($app->getContainer()->get(Incoviba\Command\Ventas\Cuotas\Hoy::class));
|
||||
$app->add($app->getContainer()->get(Incoviba\Command\Ventas\Cuotas\Pendientes::class));
|
||||
$app->add($app->getContainer()->get(Incoviba\Command\Ventas\Cuotas\PorVencer::class));
|
42
cli/setup/app.php
Normal file
42
cli/setup/app.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
use DI\ContainerBuilder;
|
||||
use Incoviba\Common\Alias\Application;
|
||||
|
||||
include_once 'composer.php';
|
||||
|
||||
function buildApp(): Application
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
$folders = [
|
||||
'settings',
|
||||
'setups'
|
||||
];
|
||||
foreach ($folders as $folder_name) {
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, $folder_name]);
|
||||
if (!file_exists($folder)) {
|
||||
continue;
|
||||
}
|
||||
$files = new FilesystemIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
$builder->addDefinitions($file->getRealPath());
|
||||
}
|
||||
}
|
||||
$app = new Application($builder->build());
|
||||
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'middlewares']);
|
||||
if (file_exists($folder)) {
|
||||
$files = new FilesystemIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
|
||||
return $app;
|
||||
}
|
||||
return buildApp();
|
6
cli/setup/composer.php
Normal file
6
cli/setup/composer.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__FILE__, 2),
|
||||
'vendor',
|
||||
'autoload.php'
|
||||
]);
|
11
cli/setup/middlewares/01_commands.php
Normal file
11
cli/setup/middlewares/01_commands.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
function loadCommands(&$app): void {
|
||||
$files = new FilesystemIterator($app->getContainer()->get('folders')->commands);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
loadCommands($app);
|
2
cli/setup/settings/env.php
Normal file
2
cli/setup/settings/env.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return $_ENV;
|
15
cli/setup/settings/folders.php
Normal file
15
cli/setup/settings/folders.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
return [
|
||||
'folders' => function() {
|
||||
$arr = ['base' => dirname(__FILE__, 3)];
|
||||
$arr['resources'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['base'],
|
||||
'resources'
|
||||
]);
|
||||
$arr['commands'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['resources'],
|
||||
'commands'
|
||||
]);
|
||||
return (object) $arr;
|
||||
}
|
||||
];
|
15
cli/setup/setups/client.php
Normal file
15
cli/setup/setups/client.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Psr\Http\Client\ClientInterface::class => function(ContainerInterface $container) {
|
||||
return new GuzzleHttp\Client([
|
||||
'base_uri' => $container->get('API_URL'),
|
||||
'headers' => [
|
||||
'Authorization' => [
|
||||
'Bearer ' . md5($container->get('API_KEY'))
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
];
|
32
cli/setup/setups/logs.php
Normal file
32
cli/setup/setups/logs.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
|
||||
return new Monolog\Logger('incoviba', [
|
||||
new Monolog\Handler\FilterHandler(
|
||||
(new Monolog\Handler\RotatingFileHandler('/logs/debug.log'))
|
||||
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
|
||||
Monolog\Level::Debug,
|
||||
Monolog\Level::Notice
|
||||
),
|
||||
new Monolog\Handler\FilterHandler(
|
||||
(new Monolog\Handler\RotatingFileHandler('/logs/error.log'))
|
||||
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
|
||||
Monolog\Level::Warning,
|
||||
Monolog\Level::Error
|
||||
),
|
||||
new Monolog\Handler\FilterHandler(
|
||||
(new Monolog\Handler\RotatingFileHandler('/logs/critical.log'))
|
||||
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true)),
|
||||
Monolog\Level::Critical
|
||||
)
|
||||
], [
|
||||
$container->get(Monolog\Processor\PsrLogMessageProcessor::class),
|
||||
$container->get(Monolog\Processor\WebProcessor::class),
|
||||
$container->get(Monolog\Processor\IntrospectionProcessor::class),
|
||||
$container->get(Monolog\Processor\MemoryUsageProcessor::class),
|
||||
$container->get(Monolog\Processor\MemoryPeakUsageProcessor::class)
|
||||
]);
|
||||
}
|
||||
];
|
25
cli/src/Command/Comunas.php
Normal file
25
cli/src/Command/Comunas.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Command;
|
||||
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Symfony\Component\Console;
|
||||
|
||||
#[Console\Attribute\AsCommand(
|
||||
name: 'comunas'
|
||||
)]
|
||||
class Comunas extends Console\Command\Command
|
||||
{
|
||||
public function __construct(protected ClientInterface $client, string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$uri = '/api/direcciones/region/13/comunas';
|
||||
$output->writeln("GET {$uri}");
|
||||
$response = $this->client->get($uri);
|
||||
$output->writeln("Response Code: {$response->getStatusCode()}");
|
||||
return Console\Command\Command::SUCCESS;
|
||||
}
|
||||
}
|
35
cli/src/Command/Money/IPC.php
Normal file
35
cli/src/Command/Money/IPC.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Incoviba\Command\Money;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Symfony\Component\Console;
|
||||
|
||||
#[Console\Attribute\AsCommand(
|
||||
name: 'money:ipc'
|
||||
)]
|
||||
class IPC extends Console\Command\Command
|
||||
{
|
||||
public function __construct(protected ClientInterface $client, string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$lastMonth = (new DateTimeImmutable())->sub(new DateInterval('P1M'));
|
||||
$uri = '/api/money';
|
||||
$data = [
|
||||
'provider' => 'ipc',
|
||||
'fecha' => $lastMonth->format('Y-m-1')
|
||||
];
|
||||
$output->writeln("POST {$uri}");
|
||||
$response = $this->client->post($uri, [
|
||||
'body' => http_build_query($data),
|
||||
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded']
|
||||
]);
|
||||
$output->writeln("Response Code: {$response->getStatusCode()}");
|
||||
return Console\Command\Command::SUCCESS;
|
||||
}
|
||||
}
|
34
cli/src/Command/Money/UF.php
Normal file
34
cli/src/Command/Money/UF.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Incoviba\Command\Money;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Symfony\Component\Console;
|
||||
|
||||
#[Console\Attribute\AsCommand(
|
||||
name: 'money:uf'
|
||||
)]
|
||||
class UF extends Console\Command\Command
|
||||
{
|
||||
public function __construct(protected ClientInterface $client, string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$now = new DateTimeImmutable();
|
||||
$uri = '/api/money';
|
||||
$data = [
|
||||
'provider' => 'uf',
|
||||
'fecha' => $now->format('Y-m-d')
|
||||
];
|
||||
$output->writeln("POST {$uri}");
|
||||
$response = $this->client->post($uri, [
|
||||
'body' => http_build_query($data),
|
||||
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded']
|
||||
]);
|
||||
$output->writeln("Response Code: {$response->getStatusCode()}");
|
||||
return Console\Command\Command::SUCCESS;
|
||||
}
|
||||
}
|
25
cli/src/Command/Proyectos/Activos.php
Normal file
25
cli/src/Command/Proyectos/Activos.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Command\Proyectos;
|
||||
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Symfony\Component\Console;
|
||||
|
||||
#[Console\Attribute\AsCommand(
|
||||
name: 'proyectos:activos'
|
||||
)]
|
||||
class Activos extends Console\Command\Command
|
||||
{
|
||||
public function __construct(protected ClientInterface $client, string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$uri = '/api/proyectos';
|
||||
$output->writeln("GET {$uri}");
|
||||
$response = $this->client->get($uri);
|
||||
$output->writeln("Response Code: {$response->getStatusCode()}");
|
||||
return Console\Command\Command::SUCCESS;
|
||||
}
|
||||
}
|
25
cli/src/Command/Ventas/Cierres/Vigentes.php
Normal file
25
cli/src/Command/Ventas/Cierres/Vigentes.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Command\Ventas\Cierres;
|
||||
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Symfony\Component\Console;
|
||||
|
||||
#[Console\Attribute\AsCommand(
|
||||
name: 'ventas:cierres:vigentes'
|
||||
)]
|
||||
class Vigentes extends Console\Command\Command
|
||||
{
|
||||
public function __construct(protected ClientInterface $client, string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$uri = '/api/ventas/cierres/vigentes';
|
||||
$output->writeln("GET {$uri}");
|
||||
$response = $this->client->get($uri);
|
||||
$output->writeln("Response Code: {$response->getStatusCode()}");
|
||||
return Console\Command\Command::SUCCESS;
|
||||
}
|
||||
}
|
25
cli/src/Command/Ventas/Cuotas/Hoy.php
Normal file
25
cli/src/Command/Ventas/Cuotas/Hoy.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Command\Ventas\Cuotas;
|
||||
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Symfony\Component\Console;
|
||||
|
||||
#[Console\Attribute\AsCommand(
|
||||
name: 'ventas:cuotas:hoy'
|
||||
)]
|
||||
class Hoy extends Console\Command\Command
|
||||
{
|
||||
public function __construct(protected ClientInterface $client, string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$uri = '/api/ventas/cuotas/hoy';
|
||||
$output->writeln("GET {$uri}");
|
||||
$response = $this->client->get($uri);
|
||||
$output->writeln("Response Code: {$response->getStatusCode()}");
|
||||
return Console\Command\Command::SUCCESS;
|
||||
}
|
||||
}
|
25
cli/src/Command/Ventas/Cuotas/Pendientes.php
Normal file
25
cli/src/Command/Ventas/Cuotas/Pendientes.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Command\Ventas\Cuotas;
|
||||
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Symfony\Component\Console;
|
||||
|
||||
#[Console\Attribute\AsCommand(
|
||||
name: 'ventas:cuotas:pendientes'
|
||||
)]
|
||||
class Pendientes extends Console\Command\Command
|
||||
{
|
||||
public function __construct(protected ClientInterface $client, string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$uri = '/api/ventas/cuotas/pendientes';
|
||||
$output->writeln("GET {$uri}");
|
||||
$response = $this->client->get($uri);
|
||||
$output->writeln("Response Code: {$response->getStatusCode()}");
|
||||
return Console\Command\Command::SUCCESS;
|
||||
}
|
||||
}
|
25
cli/src/Command/Ventas/Cuotas/PorVencer.php
Normal file
25
cli/src/Command/Ventas/Cuotas/PorVencer.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Incoviba\Command\Ventas\Cuotas;
|
||||
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Symfony\Component\Console;
|
||||
|
||||
#[Console\Attribute\AsCommand(
|
||||
name: 'ventas:cuotas:vencer'
|
||||
)]
|
||||
class PorVencer extends Console\Command\Command
|
||||
{
|
||||
public function __construct(protected ClientInterface $client, string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$uri = '/api/ventas/cuotas/vencer';
|
||||
$output->writeln("GET {$uri}");
|
||||
$response = $this->client->get($uri);
|
||||
$output->writeln("Response Code: {$response->getStatusCode()}");
|
||||
return Console\Command\Command::SUCCESS;
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ services:
|
||||
env_file:
|
||||
- ${APP_PATH:-.}/.env
|
||||
- ${APP_PATH:-.}/.db.env
|
||||
- ./.key.env
|
||||
#- ${APP_PATH:-.}/.remote.env
|
||||
volumes:
|
||||
- ${APP_PATH:-.}/:/code
|
||||
@ -83,6 +84,20 @@ services:
|
||||
- "./logs:/logs"
|
||||
ports:
|
||||
- "8084:80"
|
||||
cli:
|
||||
profiles:
|
||||
- cli
|
||||
build:
|
||||
context: .
|
||||
dockerfile: CLI.Dockerfile
|
||||
container_name: incoviba_cli
|
||||
<<: *restart
|
||||
env_file:
|
||||
- ${CLI_PATH:-.}/.env
|
||||
- ./.key.env
|
||||
volumes:
|
||||
- ${CLI_PATH:-.}:/code
|
||||
- ./logs/cli:/logs
|
||||
|
||||
volumes:
|
||||
dbdata: {}
|
||||
|
Reference in New Issue
Block a user