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

12
console/Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM php:8-cli
RUN apt-get update -y && apt-get install -y cron git libzip-dev zip
RUN docker-php-ext-install zip
COPY --from=composer /usr/bin/composer /usr/bin/composer
WORKDIR /app
CMD ["cron", "-f", "-l", "2"]
ENTRYPOINT ["cron", "-f", "-l", "2"]

7
console/bin/console Normal file
View File

@ -0,0 +1,7 @@
<?php
$app = require_once implode(DIRECTORY_SEPARATOR, [
dirname(__FILE__, 2),
'setup',
'app.php'
]);
$app->run();

View File

@ -0,0 +1,21 @@
<?php
namespace Contabilidad\Common\Define;
use Psr\Container\ContainerInterface as Container;
use Symfony\Component\Console\Application as Base;
class Application extends Base {
public function __construct(Container $container = null, string $name = 'UNKNOWN', string $version = 'UNKNOWN')
{
parent::__construct($name, $version);
$this->setContainer($container);
}
protected $container;
public function setContainer(Container $container) {
$this->container = $container;
return $this;
}
public function getContainer() {
return $this->container;
}
}

25
console/composer.json Normal file
View File

@ -0,0 +1,25 @@
{
"name": "provm/contabilidad-console",
"type": "project",
"require": {
"symfony/console": "^6.0",
"php-di/php-di": "^6.3",
"nesbot/carbon": "^2.57",
"guzzlehttp/guzzle": "^7.4"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"kint-php/kint": "^4.1"
},
"authors": [
{
"name": "Aldarien",
"email": "aldarien85@gmail.com"
}
],
"autoload": {
"psr-4": {
"Contabilidad\\Common\\": "common/"
}
}
}

4
console/php.ini Normal file
View File

@ -0,0 +1,4 @@
[PHP]
display_errors = E_ALL
log_errors = true
error_log = /var/log/php/error.log

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