Version 3.0
New technologies
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
use DI\ContainerBuilder as Builder;
|
||||
use DI\Bridge\Slim\Bridge as Bridge;
|
||||
use Zeuxisoo\Whoops\Slim\WhoopsMiddleware;
|
||||
|
||||
include_once 'composer.php';
|
||||
|
||||
@ -24,12 +23,7 @@ foreach ($folders as $f) {
|
||||
}
|
||||
}
|
||||
|
||||
$container = $builder->build();
|
||||
$app = Bridge::create($container);
|
||||
|
||||
$app->addRoutingMiddleware();
|
||||
$app->add(new WhoopsMiddleware());
|
||||
|
||||
$app = Bridge::create($builder->build());
|
||||
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'middlewares']);
|
||||
if (file_exists($folder)) {
|
||||
@ -42,7 +36,4 @@ if (file_exists($folder)) {
|
||||
}
|
||||
}
|
||||
|
||||
include_once 'databases.php';
|
||||
include_once 'router.php';
|
||||
|
||||
return $app;
|
||||
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
$databases = $app->getContainer()->get('databases');
|
||||
|
||||
foreach ($databases->databases as $name => $settings) {
|
||||
if (!is_object($settings)) {
|
||||
continue;
|
||||
}
|
||||
$auth = false;
|
||||
$dsn = '';
|
||||
switch (strtolower($settings->type)) {
|
||||
case 'mysql':
|
||||
$data = [
|
||||
['host', $settings->host->name],
|
||||
['dbname', $settings->name]
|
||||
];
|
||||
if (isset($settings->host->port)) {
|
||||
$data []= ['port', $settings->host->port];
|
||||
}
|
||||
array_walk($data, function(&$item) {
|
||||
$item = implode('=', $item);
|
||||
});
|
||||
$dsn = implode(':', [
|
||||
'mysql',
|
||||
implode(';', $data)
|
||||
]);
|
||||
$auth = true;
|
||||
break;
|
||||
}
|
||||
ORM::configure($dsn, null, $name);
|
||||
if ($auth) {
|
||||
ORM::configure('username', $settings->user->name, $name);
|
||||
ORM::configure('password', $settings->user->password, $name);
|
||||
}
|
||||
}
|
||||
if (isset($databases->short_names) and $databases->short_names) {
|
||||
Model::$short_table_names = true;
|
||||
}
|
@ -1,4 +1,2 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Middleware\Auth;
|
||||
|
||||
$app->add($app->getContainer()->get(Auth::class));
|
||||
$app->add($app->getContainer()->get(Contabilidad\Common\Middleware\Auth::class));
|
||||
|
11
api/setup/middlewares/02_routes.php
Normal file
11
api/setup/middlewares/02_routes.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
$app->addRoutingMiddleware();
|
||||
|
||||
$folder = $app->getContainer()->get('folders')->routes;
|
||||
$files = new DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir() or $file->getExtension() != 'php') {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
<?php
|
||||
use Contabilidad\Common\Middleware\Consolidar;
|
||||
|
||||
$app->add(new Consolidar($app->getContainer()->get(\Contabilidad\Common\Service\Consolidar::class)));
|
2
api/setup/middlewares/99_error_handler.php
Normal file
2
api/setup/middlewares/99_error_handler.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$app->add($app->getContainer()->get(Zeuxisoo\Whoops\Slim\WhoopsMiddleware::class));
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
$folder = $app->getContainer()->get('folders')->routes;
|
||||
$files = new DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir() or $file->getExtension() != 'php') {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
@ -18,22 +18,6 @@ return [
|
||||
$arr['base'],
|
||||
'public'
|
||||
]);
|
||||
$arr['uploads'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['base'],
|
||||
'uploads'
|
||||
]);
|
||||
$arr['pdfs'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['uploads'],
|
||||
'pdfs'
|
||||
]);
|
||||
$arr['csvs'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['uploads'],
|
||||
'csvs'
|
||||
]);
|
||||
$arr['xlss'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['uploads'],
|
||||
'xlss'
|
||||
]);
|
||||
return (object) $arr;
|
||||
},
|
||||
'urls' => function(Container $c) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
return [
|
||||
'databases' => function() {
|
||||
$arr = [
|
||||
ORM::DEFAULT_CONNECTION => [
|
||||
'default' => [
|
||||
'type' => 'mysql',
|
||||
'host' => [
|
||||
'name' => $_ENV['MYSQL_HOST'] ?? 'db'
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
GuzzleHttp\Client::class => function(Container $c) {
|
||||
return new GuzzleHttp\Client();
|
||||
},
|
||||
Contabilidad\Common\Service\Auth::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\Auth($c->get('api_key'));
|
||||
},
|
||||
Contabilidad\Common\Middleware\Auth::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Middleware\Auth(
|
||||
$c->get(Nyholm\Psr7\Factory\Psr17Factory::class),
|
||||
$c->get(Contabilidad\Common\Service\Auth::class)
|
||||
);
|
||||
},
|
||||
Contabilidad\Common\Service\PdfHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\PdfHandler($c->get(GuzzleHttp\Client::class), $c->get('folders')->pdfs, implode('/', [
|
||||
$c->get('urls')->python,
|
||||
'pdf',
|
||||
'parse'
|
||||
]));
|
||||
},
|
||||
Contabilidad\Common\Service\CsvHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\CsvHandler($c->get('folders')->csvs);
|
||||
},
|
||||
Contabilidad\Common\Service\XlsHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\XlsHandler($c->get('folders')->xlss);
|
||||
},
|
||||
Contabilidad\Common\Service\DocumentHandler::class => function(Container $c) {
|
||||
$handlers = [
|
||||
$c->get(Contabilidad\Common\Service\XlsHandler::class),
|
||||
$c->get(Contabilidad\Common\Service\CsvHandler::class),
|
||||
$c->get(Contabilidad\Common\Service\PdfHandler::class)
|
||||
];
|
||||
return new Contabilidad\Common\Service\DocumentHandler($handlers);
|
||||
},
|
||||
Contabilidad\Common\Service\TiposCambios::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\TiposCambios(
|
||||
$c->get(GuzzleHttp\Client::class),
|
||||
$c->get(ProVM\Common\Factory\Model::class),
|
||||
$c->get('python_api'),
|
||||
$c->get('python_key')
|
||||
);
|
||||
},
|
||||
Contabilidad\Common\Service\FileHandler::class => function(Container $c) {
|
||||
return new Contabilidad\Common\Service\FileHandler((object) [
|
||||
'folder' => $c->get('folders')->uploads,
|
||||
'types' => [
|
||||
'text/csv' => 'csvs',
|
||||
'application/pdf' => 'pdfs',
|
||||
'application/vnd.ms-excel' => 'xlss',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlss',
|
||||
'application/json' => 'jsons'
|
||||
]
|
||||
]);
|
||||
}
|
||||
];
|
14
api/setup/setups/02_database.php
Normal file
14
api/setup/setups/02_database.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
\Common\Concept\Database::class => function(ContainerInterface $container) {
|
||||
$settings = $container->get('databases')->default;
|
||||
return new \Contabilidad\Implement\Database\MySQL(
|
||||
$settings->host->name,
|
||||
$settings->user->name,
|
||||
$settings->user->password,
|
||||
$settings->name
|
||||
);
|
||||
}
|
||||
];
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
\Contabilidad\Common\Service\Queuer::class => function(Container $container) {
|
||||
return new \Contabilidad\Common\Service\Queuer($container->get(\ProVM\Common\Factory\Model::class));
|
||||
},
|
||||
\Contabilidad\Common\Service\Consolidar::class => function(Container $container) {
|
||||
return new \Contabilidad\Common\Service\Consolidar($container->get(\ProVM\Common\Factory\Model::class), $container->get(\Contabilidad\Common\Service\Queuer::class));
|
||||
}
|
||||
];
|
Reference in New Issue
Block a user