Base setup

This commit is contained in:
2020-12-15 17:45:11 -03:00
parent 559d287a3d
commit 736eb72254
6 changed files with 146 additions and 0 deletions

50
setup/app.php Normal file
View File

@ -0,0 +1,50 @@
<?php
use DI\ContainerBuilder as Builder;
use DI\Bridge\Slim\Bridge;
include_once 'composer.php';
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
$dotenv->load();
$builder = new Builder();
$folders = [
'common',
$__environment
];
$files = [
'config',
'setup'
];
foreach ($files as $file) {
foreach ($folders as $folder) {
$filename = implode(DIRECTORY_SEPARATOR, [
__DIR__,
$folder,
$file . '.php'
]);
if (!file_exists($filename)) {
continue;
}
$builder->addDefinitions($filename);
}
}
$container = $builder->build();
$app = Bridge::create($container);
$app->setBasePath($container->get('base_url'));
foreach ($folders as $folder) {
$filename = implode(DIRECTORY_SEPARATOR, [
__DIR__,
$folder,
'middleware.php'
]);
if (!file_exists($filename)) {
continue;
}
include_once $filename;
}
include_once 'router.php';

16
setup/common/config.php Normal file
View File

@ -0,0 +1,16 @@
<?php
use ProVM\Common\Helper\Tree;
return [
'debug' => true,
'base_url' => $_ENV['BASE_URL'],
'folders' => function() {
$directory = new Tree(DIRECTORY_SEPARATOR);
return $directory->build([
[dirname(__DIR__, 2), null, 'base'],
['public', 'base', 'public'],
['resources', 'base', 'resources'],
['routes', 'resources', 'routes']
]);
}
];

6
setup/composer.php Normal file
View File

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

5
setup/router.php Normal file
View File

@ -0,0 +1,5 @@
<?php
include_once implode(DIRECTORY_SEPARATOR, [
$app->getContainer()->get('folders')->routes,
$__environment . '.php'
]);

49
setup/web/config.php Normal file
View File

@ -0,0 +1,49 @@
<?php
use Psr\Container\ContainerInterface as Container;
use ProVM\Common\Helper\Tree;
use ProVM\Common\Helper\Merger;
return [
'folders' => DI\decorate(function($prev, Container $c) {
$merger = new Merger(DIRECTORY_SEPARATOR);
$arr = (array) $prev;
$arr['templates'] = $merger->start()->add($prev->resources)->add('views')->merge();
$arr['cache'] = $merger->start()->add($prev->base)->add('cache')->merge();
return (object) $arr;
}),
'urls' => function(Container $c) {
$tree = new Tree('/');
return $tree->build([
[$c->get('base_url'), null, 'base'],
['assets', 'base', 'assets'],
['images', 'assets', 'images'],
['scripts', 'assets', 'scripts'],
['styles', 'assets', 'styles']
]);
},
'assets' => function(Container $c) {
$arr = [
'links' => [
'<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/semantic.min.css" integrity="sha512-g/MzOGVPy3OQ4ej1U+qe4D/xhLwUn5l5xL0Fa7gdC258ZWVJQGwsbIR47SWMpRxSPjD0tfu/xkilTy+Lhrl3xg==" crossorigin="anonymous" />'
],
'fonts' => [
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/themes/default/assets/fonts/icons.eot',
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/themes/default/assets/fonts/icons.ttf',
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/themes/default/assets/fonts/icons.woff',
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/themes/default/assets/fonts/icons.woff2',
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/themes/default/assets/fonts/outline-icons.eot',
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/themes/default/assets/fonts/outline-icons.ttf',
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/themes/default/assets/fonts/outline-icons.woff',
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/themes/default/assets/fonts/outline-icons.woff2',
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/themes/default/assets/fonts/brand-icons.eot',
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/themes/default/assets/fonts/brand-icons.ttf',
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/themes/default/assets/fonts/brand-icons.woff',
'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/themes/default/assets/fonts/brand-icons.woff2'
],
'scripts' => [
'<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.7/semantic.min.js" integrity="sha512-1Nyd5H4Aad+OyvVfUOkO/jWPCrEvYIsQENdnVXt1+Jjc4NoJw28nyRdrpOCyFH4uvR3JmH/5WmfX1MJk2ZlhgQ==" crossorigin="anonymous"></script>'
]
];
return $arr;
}
];

20
setup/web/setup.php Normal file
View File

@ -0,0 +1,20 @@
<?php
use Psr\Container\ContainerInterface as Container;
return [
ProVM\Common\Alias\View::class => function(Container $c) {
if (!file_exists($c->get('folders')->cache)) {
mkdir($c->get('folders')->cache);
chmod($c->get('folders')->cache, 777);
}
return new ProVM\Common\Definition\View(
$c->get('folders')->templates,
$c->get('folders')->cache,
null,
[
'urls' => $c->get('urls'),
'assets' => $c->get('assets')
]
);
}
];