Console application
This commit is contained in:
12
console/Dockerfile
Normal file
12
console/Dockerfile
Normal 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
7
console/bin/console
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
$app = require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__FILE__, 2),
|
||||
'setup',
|
||||
'app.php'
|
||||
]);
|
||||
$app->run();
|
21
console/common/Define/Application.php
Normal file
21
console/common/Define/Application.php
Normal 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
25
console/composer.json
Normal 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
4
console/php.ini
Normal 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
39
console/setup/app.php
Normal 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;
|
6
console/setup/composer.php
Normal file
6
console/setup/composer.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'vendor',
|
||||
'autoload.php'
|
||||
]);
|
5
console/setup/settings/02_api.php
Normal file
5
console/setup/settings/02_api.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
'api_url' => $_ENV['API_URL'],
|
||||
'api_key' => $_ENV['API_KEY']
|
||||
];
|
13
console/setup/setups/02_client.php
Normal file
13
console/setup/setups/02_client.php
Normal 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')}"
|
||||
]
|
||||
]);
|
||||
}
|
||||
];
|
Reference in New Issue
Block a user