Console application

This commit is contained in:
2022-03-25 10:10:43 -03:00
parent 2b3b475d91
commit fcc84ac09c
10 changed files with 163 additions and 12 deletions

39
console/setup/app.php Normal file
View File

@ -0,0 +1,39 @@
<?php
use DI\ContainerBuilder as Builder;
use Contabilidad\Common\Define\Application;
require_once 'composer.php';
$builder = new Builder();
$folders = [
'settings',
'setups'
];
foreach ($folders as $f) {
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, $f]);
if (!file_exists($folder)) {
continue;
}
$files = new DirectoryIterator($folder);
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
$builder->addDefinitions($file->getRealPath());
}
}
$container = $builder->build();
$app = new Application($container);
$folder = implode(DIRECTORY_SEPARATOR, [__DIR__, 'commands']);
if (file_exists($folder)) {
$files = new DirectoryIterator($folder);
foreach ($files as $file) {
if ($file->isDir() or $file->getExtension() != 'php') {
continue;
}
include_once $file->getRealPath();
}
}
return $app;

View File

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

View File

@ -0,0 +1,5 @@
<?php
return [
'api_url' => $_ENV['API_URL'],
'api_key' => $_ENV['API_KEY']
];

View File

@ -0,0 +1,13 @@
<?php
use Psr\Container\ContainerInterface as Container;
return [
\Psr\Http\Client\ClientInterface::class => function(Container $container) {
return new \GuzzleHttp\Client([
'base_uri' => $container->get('api_url'),
'headers' => [
'Authorization' => "Bearer {$container->get('api_key')}"
]
]);
}
];