This commit is contained in:
2023-11-25 00:56:18 -03:00
parent ab1647eed3
commit 7945579e80
27 changed files with 459 additions and 0 deletions

42
cli/setup/app.php Normal file
View 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
View File

@ -0,0 +1,6 @@
<?php
require_once implode(DIRECTORY_SEPARATOR, [
dirname(__FILE__, 2),
'vendor',
'autoload.php'
]);

View 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);

View File

@ -0,0 +1,2 @@
<?php
return $_ENV;

View 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;
}
];

View 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
View 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)
]);
}
];