From 736eb722548ac534b5b0f5df1606fbe146523c27 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Tue, 15 Dec 2020 17:45:11 -0300 Subject: [PATCH] Base setup --- setup/app.php | 50 +++++++++++++++++++++++++++++++++++++++++ setup/common/config.php | 16 +++++++++++++ setup/composer.php | 6 +++++ setup/router.php | 5 +++++ setup/web/config.php | 49 ++++++++++++++++++++++++++++++++++++++++ setup/web/setup.php | 20 +++++++++++++++++ 6 files changed, 146 insertions(+) create mode 100644 setup/app.php create mode 100644 setup/common/config.php create mode 100644 setup/composer.php create mode 100644 setup/router.php create mode 100644 setup/web/config.php create mode 100644 setup/web/setup.php diff --git a/setup/app.php b/setup/app.php new file mode 100644 index 0000000..83cf9f3 --- /dev/null +++ b/setup/app.php @@ -0,0 +1,50 @@ +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'; diff --git a/setup/common/config.php b/setup/common/config.php new file mode 100644 index 0000000..0b1b9ad --- /dev/null +++ b/setup/common/config.php @@ -0,0 +1,16 @@ + 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'] + ]); + } +]; diff --git a/setup/composer.php b/setup/composer.php new file mode 100644 index 0000000..2d27ee1 --- /dev/null +++ b/setup/composer.php @@ -0,0 +1,6 @@ +getContainer()->get('folders')->routes, + $__environment . '.php' +]); diff --git a/setup/web/config.php b/setup/web/config.php new file mode 100644 index 0000000..5948859 --- /dev/null +++ b/setup/web/config.php @@ -0,0 +1,49 @@ + 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' => [ + '' + ], + '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' => [ + '' + ] + ]; + return $arr; + } +]; diff --git a/setup/web/setup.php b/setup/web/setup.php new file mode 100644 index 0000000..c1071bd --- /dev/null +++ b/setup/web/setup.php @@ -0,0 +1,20 @@ + 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') + ] + ); + } +];