config
This commit is contained in:
48
app_old/cli/app.php
Normal file
48
app_old/cli/app.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface;
|
||||
use DI\ContainerBuilder;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
require_once 'composer.php';
|
||||
|
||||
$builder = new ContainerBuilder();
|
||||
$files = [
|
||||
'config',
|
||||
'setups'
|
||||
];
|
||||
foreach ($files as $f) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
'cli',
|
||||
"{$f}.php"
|
||||
]);
|
||||
if (!file_exists($filename)) {
|
||||
continue;
|
||||
}
|
||||
$builder->addDefinitions($filename);
|
||||
}
|
||||
$app = new class() extends Application
|
||||
{
|
||||
protected ContainerInterface $container;
|
||||
public function getContainer(): ContainerInterface
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
public function setContainer(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
return $this;
|
||||
}
|
||||
};
|
||||
$app->setContainer($builder->build());
|
||||
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
'cli',
|
||||
'middlewares.php'
|
||||
]);
|
||||
if (file_exists($filename)) {
|
||||
include_once $filename;
|
||||
}
|
||||
|
||||
return $app;
|
26
app_old/cli/cli/config.php
Normal file
26
app_old/cli/cli/config.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
return [
|
||||
'databases' => function() {
|
||||
$container = new DI\Container([
|
||||
ORM::DEFAULT_CONNECTION => new DI\Container([
|
||||
'host' => $_ENV['MYSQL_HOST'],
|
||||
'database' => $_ENV['MYSQL_DATABASE'],
|
||||
'username' => $_ENV['MYSQL_USER'],
|
||||
'password' => $_ENV['MYSQL_PASSWORD']
|
||||
]),
|
||||
'remote' => new DI\Container([
|
||||
'host' => $_ENV['REMOTE_HOST'],
|
||||
'database' => $_ENV['REMOTE_DATABASE'],
|
||||
'username' => $_ENV['REMOTE_USER'],
|
||||
'password' => $_ENV['REMOTE_PASSWORD']
|
||||
])
|
||||
]);
|
||||
if (isset($_ENV['MYSQL_PORT'])) {
|
||||
$container->get(ORM::DEFAULT_CONNECTION)->set('port', $_ENV['MYSQL_PORT']);
|
||||
}
|
||||
if (isset($_ENV['REMOTE_PORT'])) {
|
||||
$container->get('remote')->set('port', $_ENV['REMOTE_PORT']);
|
||||
}
|
||||
return $container;
|
||||
}
|
||||
];
|
9
app_old/cli/cli/middlewares.php
Normal file
9
app_old/cli/cli/middlewares.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__FILE__, 3),
|
||||
'resources',
|
||||
'routes',
|
||||
'cli.php'
|
||||
]);
|
||||
|
||||
Monolog\ErrorHandler::register($app->getContainer()->get(Psr\Log\LoggerInterface::class));
|
44
app_old/cli/cli/setups.php
Normal file
44
app_old/cli/cli/setups.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
|
||||
return new Monolog\Logger('cli', [
|
||||
new Monolog\Handler\FilterHandler(new Monolog\Handler\RotatingFileHandler('/logs/cli.debug.log'), Monolog\Level::Debug, Monolog\Level::Notice),
|
||||
new Monolog\Handler\FilterHandler(new Monolog\Handler\RotatingFileHandler('/logs/cli.error.log'), Monolog\Level::Warning)
|
||||
], [
|
||||
new Monolog\Processor\PsrLogMessageProcessor(),
|
||||
new Monolog\Processor\IntrospectionProcessor(),
|
||||
new Monolog\Processor\MemoryUsageProcessor(),
|
||||
new Monolog\Processor\MemoryPeakUsageProcessor()
|
||||
]);
|
||||
},
|
||||
GuzzleHttp\Client::class => function(ContainerInterface $container) {
|
||||
return new GuzzleHttp\Client([
|
||||
'base_uri' => "http://{$container->get(App\Service\Remote::class)->getIP()}:8008",
|
||||
'headers' => [
|
||||
'Accept' => 'application/json'
|
||||
]
|
||||
]);
|
||||
},
|
||||
\App\Alias\RemoteConnection::class => function(ContainerInterface $container) {
|
||||
return new \App\Alias\RemoteConnection();
|
||||
},
|
||||
App\Service\Remote::class => function(ContainerInterface $container) {
|
||||
return new App\Service\Remote($container->get(\App\Alias\RemoteConnection::class));
|
||||
},
|
||||
App\Service\Money::class => function(ContainerInterface $container) {
|
||||
return new App\Service\Money($container->get(GuzzleHttp\Client::class));
|
||||
},
|
||||
\App\Alias\Connection::class => function(ContainerInterface $container) {
|
||||
$data = $container->get('databases')->get(ORM::DEFAULT_CONNECTION);
|
||||
return new \App\Alias\Connection(
|
||||
$data->get('host'),
|
||||
$data->get('database'),
|
||||
$data->get('username'),
|
||||
$data->get('password'),
|
||||
$data->has('port') ? $data->get('port') : null
|
||||
);
|
||||
},
|
||||
];
|
6
app_old/cli/composer.php
Normal file
6
app_old/cli/composer.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'vendor',
|
||||
'autoload.php'
|
||||
]);
|
Reference in New Issue
Block a user