diff --git a/modules/operadores b/modules/operadores index 71e10c5..4f7241e 160000 --- a/modules/operadores +++ b/modules/operadores @@ -1 +1 @@ -Subproject commit 71e10c52bddbaa7a78220b69c4dd31681bf74fd5 +Subproject commit 4f7241e14674692c7e319ab3589783d38f6594f7 diff --git a/setup/app.php b/setup/app.php index 333dc42..d2e8644 100644 --- a/setup/app.php +++ b/setup/app.php @@ -5,32 +5,32 @@ use DI\Bridge\Slim\Bridge; include_once 'composer.php'; $folders = [ - 'env', - 'common', - $__environment -]; -$files = [ - 'config', + 'settings', 'setups' ]; $builder = new Builder(); -foreach ($files as $file) { - foreach ($folders as $folder) { - $filename = implode(DIRECTORY_SEPARATOR, [ - __DIR__, - $folder, - $file . '.php' - ]); - if (!file_exists($filename)) { +foreach ($folders as $f) { + $folder = implode(DIRECTORY_SEPARATOR, [ + __DIR__, + $f + ]); + if (!file_exists($folder)) { + continue; + } + $files = new DirectoryIterator($folder); + foreach ($files as $file) { + if ($file->isDir() or $file->getExtension() != 'php') { continue; } - $builder->addDefinitions($filename); + $builder->addDefinitions($file->getRealPath()); } } $container = $builder->build(); $app = Bridge::create($container); -$app->setBasePath($app->getContainer()->get('base_url')); +if ($app->getContainer()->has('base_url') and $app->getContainer()->get('base_url') != '') { + $app->setBasePath($app->getContainer()->get('base_url')); +} $app->addRoutingMiddleware(); foreach ($folders as $folder) { diff --git a/setup/env/config.php b/setup/env/config.php index a38e55d..7c3c1c4 100644 --- a/setup/env/config.php +++ b/setup/env/config.php @@ -12,7 +12,7 @@ foreach ($files as $file) { } return [ - 'debug' => false, + 'debug' => $_ENV['DEBUG'] ?? false, 'benchmark' => false, 'base_url' => $_ENV['BASE_URL']//'/incoviba' ]; diff --git a/setup/settings/01_env.php b/setup/settings/01_env.php new file mode 100644 index 0000000..6949ba9 --- /dev/null +++ b/setup/settings/01_env.php @@ -0,0 +1,18 @@ +isDir() or $file->getExtension() != 'env') { + continue; + } + $env = Dotenv::createImmutable($file->getPath(), $file->getBasename()); + $env->load(); +} + +return [ + 'debug' => $_ENV['DEBUG'] ?? false, + 'benchmark' => false, + 'base_url' => $_ENV['BASE_URL'] ?? '/incoviba' +]; diff --git a/setup/settings/02_common.php b/setup/settings/02_common.php new file mode 100644 index 0000000..b16515e --- /dev/null +++ b/setup/settings/02_common.php @@ -0,0 +1,40 @@ + 'America/Santiago', + 'locale' => 'es', + 'database' => 'mysql', + 'login_hours' => 5*24, + 'cierres' => [ + 'caducidad' => 30 + ], + 'databases' => function() { + $arr = [ + 'mysql' => [ + 'host' => $_ENV['MYSQL_HOST'], + //'port' => 3306, + 'database' => $_ENV['MYSQL_DATABASE'], + 'username' => $_ENV['MYSQL_USER'], + 'password' => $_ENV['MYSQL_PASSWORD'] + ], + 'mysql_copy' => [ + 'host' => 'localhost', + 'database' => 'incoviba3', + 'username' => 'incoviba', + 'password' => '5GQYFvRjVw2A4KcD' + ] + ]; + return $arr; + }, + 'locations' => function() { + $arr = ['base' => dirname(__DIR__, 2)]; + $arr['public'] = $arr['base'] . '/public'; + $arr['resources'] = $arr['base'] . '/resources'; + $arr['routes'] = $arr['resources'] . '/routes'; + $arr['src'] = $arr['base'] . '/src'; + $arr['app'] = $arr['base'] . '/app'; + $arr['controllers'] = $arr['app'] . '/Controller'; + $arr['money'] = 'http://provm.cl/optimus/money'; + $arr['api'] = 'http://localhost:8080/api'; + return (object) $arr; + } +]; diff --git a/setup/settings/03_api.php b/setup/settings/03_api.php new file mode 100644 index 0000000..7e1bc5b --- /dev/null +++ b/setup/settings/03_api.php @@ -0,0 +1,8 @@ + DI\decorate(function($prev, Container $c) { + return $prev . '/api'; + }) +]; diff --git a/setup/settings/04_ui.php b/setup/settings/04_ui.php new file mode 100644 index 0000000..f7839c9 --- /dev/null +++ b/setup/settings/04_ui.php @@ -0,0 +1,11 @@ + DI\decorate(function($prev, Container $c) { + $arr = (array) $prev; + $arr['cache'] = $prev->base . '/cache'; + $arr['views'] = $prev->resources . '/views'; + return (object) $arr; + }) +]; diff --git a/setup/setups/04_ui.php b/setup/setups/04_ui.php new file mode 100644 index 0000000..0bf6f5d --- /dev/null +++ b/setup/setups/04_ui.php @@ -0,0 +1,15 @@ + function(Container $c) { + return new Slim\Views\Blade( + $c->get('locations')->views, + $c->get('locations')->cache, + null, + [ + 'locations' => $c->get('locations') + ] + ); + } +];