UI Base App

This commit is contained in:
2022-11-09 15:22:58 -03:00
parent b3115be4f2
commit 557d218bcc
12 changed files with 149 additions and 0 deletions

7
ui/public/index.php Normal file
View File

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

43
ui/setup/app.php Normal file
View File

@ -0,0 +1,43 @@
<?php
require_once 'composer.php';
$builder = new \DI\ContainerBuilder();
$folders = [
'settings',
'setups'
];
foreach ($folders as $f) {
$folder = implode(DIRECTORY_SEPARATOR, [
__DIR__,
$f
]);
if (!file_exists($folder)) {
continue;
}
$files = new FilesystemIterator($folder);
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
$builder->addDefinitions($file->getRealPath());
}
}
$app = \DI\Bridge\Slim\Bridge::create($builder->build());
$folder = implode(DIRECTORY_SEPARATOR, [
__DIR__,
'middleware'
]);
if (file_exists($folder)) {
$files = new FilesystemIterator($folder);
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
require_once $file->getRealPath();
}
}
return $app;

6
ui/setup/composer.php Normal file
View File

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

View File

@ -0,0 +1,11 @@
<?php
$app->addRoutingMiddleware();
$folder = $app->getContainer()->get('folders')->routes;
$files = new FilesystemIterator($folder);
foreach ($files as $file) {
if ($file->isDir()) {
continue;
}
include_once $file->getRealPath();
}

View File

@ -0,0 +1,2 @@
<?php
$app->add($app->getContainer()->get(\Zeuxisoo\Whoops\Slim\WhoopsMiddleware::class));

View File

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

View File

@ -0,0 +1,25 @@
<?php
use Psr\Container\ContainerInterface;
return [
'folders' => function() {
$arr = ['base' => dirname(__FILE__, 3)];
$arr['resources'] = implode(DIRECTORY_SEPARATOR, [
$arr['base'],
'resources'
]);
$arr['routes'] = implode(DIRECTORY_SEPARATOR, [
$arr['resources'],
'routes'
]);
$arr['views'] = implode(DIRECTORY_SEPARATOR, [
$arr['resources'],
'views'
]);
$arr['cache'] = implode(DIRECTORY_SEPARATOR, [
$arr['base'],
'cache'
]);
return (object) $arr;
}
];

View File

@ -0,0 +1,8 @@
<?php
return [
'urls' => function() {
$arr = ['base' => '/'];
$arr['api'] = 'http://localhost:8080';
return (object) $arr;
}
];

View File

@ -0,0 +1,4 @@
<?php
return [
'log_file' => '/logs/php.log'
];

View File

@ -0,0 +1,16 @@
<?php
use Psr\Container\ContainerInterface;
return [
\Slim\Views\Blade::class => function(ContainerInterface $container) {
return new \Slim\Views\Blade(
$container->get('folders')->views,
$container->get('folders')->cache,
null,
[
'urls' => $container->get('urls'),
'api_key' => sha1($container->get('api_key'))
]
);
}
];

View File

@ -0,0 +1,15 @@
<?php
use Psr\Container\ContainerInterface;
return [
\Monolog\Handler\RotatingFileHandler::class => function(ContainerInterface $container) {
$handler = new \Monolog\Handler\RotatingFileHandler($container->get('log_file'));
$handler->setFormatter($container->get(\Monolog\Formatter\LineFormatter::class));
return $handler;
},
\Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
$logger = new \Monolog\Logger('file_logger');
$logger->pushHandler($container->get(\Monolog\Handler\RotatingFileHandler::class));
return $logger;
}
];

View File

@ -0,0 +1,8 @@
<?php
use Psr\Container\ContainerInterface;
return [
\Zeuxisoo\Whoops\Slim\WhoopsMiddleware::class => function(ContainerInterface $container) {
return new \Zeuxisoo\Whoops\Slim\WhoopsMiddleware();
}
];