UI Base App
This commit is contained in:
7
ui/public/index.php
Normal file
7
ui/public/index.php
Normal 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
43
ui/setup/app.php
Normal 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
6
ui/setup/composer.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
require_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__FILE__, 2),
|
||||
'vendor',
|
||||
'autoload.php'
|
||||
]);
|
11
ui/setup/middleware/01_routes.php
Normal file
11
ui/setup/middleware/01_routes.php
Normal 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();
|
||||
}
|
2
ui/setup/middleware/99_errors.php
Normal file
2
ui/setup/middleware/99_errors.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$app->add($app->getContainer()->get(\Zeuxisoo\Whoops\Slim\WhoopsMiddleware::class));
|
4
ui/setup/settings/01_env.php
Normal file
4
ui/setup/settings/01_env.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'api_key' => $_ENV['API_KEY']
|
||||
];
|
25
ui/setup/settings/02_folders.php
Normal file
25
ui/setup/settings/02_folders.php
Normal 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;
|
||||
}
|
||||
];
|
8
ui/setup/settings/03_urls.php
Normal file
8
ui/setup/settings/03_urls.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
return [
|
||||
'urls' => function() {
|
||||
$arr = ['base' => '/'];
|
||||
$arr['api'] = 'http://localhost:8080';
|
||||
return (object) $arr;
|
||||
}
|
||||
];
|
4
ui/setup/settings/98_log.php
Normal file
4
ui/setup/settings/98_log.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'log_file' => '/logs/php.log'
|
||||
];
|
16
ui/setup/setups/03_views.php
Normal file
16
ui/setup/setups/03_views.php
Normal 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'))
|
||||
]
|
||||
);
|
||||
}
|
||||
];
|
15
ui/setup/setups/98_log.php
Normal file
15
ui/setup/setups/98_log.php
Normal 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;
|
||||
}
|
||||
];
|
8
ui/setup/setups/99_errors.php
Normal file
8
ui/setup/setups/99_errors.php
Normal 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();
|
||||
}
|
||||
];
|
Reference in New Issue
Block a user