Files
This commit is contained in:
51
setup/app.php
Normal file
51
setup/app.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
use DI\ContainerBuilder as Builder;
|
||||
use DI\Bridge\Slim\Bridge;
|
||||
|
||||
include_once 'composer.php';
|
||||
|
||||
$builder = new Builder();
|
||||
|
||||
$folders = [
|
||||
'settings',
|
||||
'setups'
|
||||
];
|
||||
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()) {
|
||||
continue;
|
||||
}
|
||||
$builder->addDefinitions($file->getRealPath());
|
||||
}
|
||||
}
|
||||
|
||||
$container = $builder->build();
|
||||
$app = Bridge::create($container);
|
||||
if ($app->getContainer()->has('base_url')) {
|
||||
$app->setBasePath($app->getContainer()->get('base_url'));
|
||||
}
|
||||
$app->addRoutingMiddleware();
|
||||
|
||||
$folder = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
'middlewares'
|
||||
]);
|
||||
if (file_exists($folder)) {
|
||||
$files = new DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir() and $file->getExtension() != 'php') {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
||||
}
|
||||
|
||||
include_once 'router.php';
|
6
setup/composer.php
Normal file
6
setup/composer.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__FILE__, 2),
|
||||
'vendor',
|
||||
'autoload.php'
|
||||
]);
|
3
setup/middlewares/01_error.php
Normal file
3
setup/middlewares/01_error.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
$app->add($app->getContainer()->get(Zeuxisoo\Whoops\Slim\WhoopsMiddleware::class));
|
||||
$app->add($app->getContainer()->get(Incoviba\UI\Common\Middleware\NotFound::class));
|
2
setup/middlewares/02_auth.php
Normal file
2
setup/middlewares/02_auth.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
$app->add($app->getContainer()->get(Incoviba\UI\Common\Middleware\Auth::class));
|
9
setup/router.php
Normal file
9
setup/router.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$folder = $app->getContainer()->get('folders')->routes;
|
||||
$files = new DirectoryIterator($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir() or $file->getExtension() != 'php') {
|
||||
continue;
|
||||
}
|
||||
include_once $file->getRealPath();
|
||||
}
|
6
setup/settings/01_env.php
Normal file
6
setup/settings/01_env.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
'debug' => $_ENV['DEBUG'] ?? false,
|
||||
'base_url' => $_ENV['BASE_URL'] ?? false,
|
||||
'API_KEY' => $_ENV['API_KEY']
|
||||
];
|
15
setup/settings/02_common.php
Normal file
15
setup/settings/02_common.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
return [
|
||||
'folders' => function () {
|
||||
$arr = ['base' => dirname(__FILE__, 3)];
|
||||
$arr['resources'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['base'],
|
||||
'resources'
|
||||
]);
|
||||
$arr['routes'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['resources'],
|
||||
'routes'
|
||||
]);
|
||||
return (object)$arr;
|
||||
}
|
||||
];
|
34
setup/settings/03_web.php
Normal file
34
setup/settings/03_web.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
'cookie_name' => 'rememberMe',
|
||||
'folders' => DI\decorate(function ($prev, Container $c) {
|
||||
$arr = (array) $prev;
|
||||
$arr['templates'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$prev->resources,
|
||||
'views'
|
||||
]);
|
||||
$arr['cache'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$prev->base,
|
||||
'cache'
|
||||
]);
|
||||
return (object) $arr;
|
||||
}),
|
||||
'urls' => function(Container $c) {
|
||||
$arr = [];
|
||||
$base = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
||||
if ($c->has('base_url')) {
|
||||
if ($c->get('base_url') != '') {
|
||||
$base = $c->get('base_url');
|
||||
}
|
||||
}
|
||||
$arr['base'] = $base;
|
||||
$arr['images'] = implode('/', [$arr['base'], 'images']);
|
||||
$arr['scripts'] = implode('/', [$arr['base'], 'js']);
|
||||
$arr['styles'] = implode('/', [$arr['base'], 'css']);
|
||||
$arr['api'] = $_ENV['API_URL'] ?? 'http://localhost:8081';
|
||||
$arr['money'] = 'http://provm.cl/money';
|
||||
return (object) $arr;
|
||||
}
|
||||
];
|
11
setup/setups/01_env.php
Normal file
11
setup/setups/01_env.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
Zeuxisoo\Whoops\Slim\WhoopsMiddleware::class => function(Container $c) {
|
||||
return new Zeuxisoo\Whoops\Slim\WhoopsMiddleware([
|
||||
'enable' => $c->get('debug'),
|
||||
'editor' => 'vscode'
|
||||
]);
|
||||
}
|
||||
];
|
42
setup/setups/02_web.php
Normal file
42
setup/setups/02_web.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
Slim\Views\Blade::class => function(Container $c) {
|
||||
return new Slim\Views\Blade(
|
||||
$c->get('folders')->templates,
|
||||
$c->get('folders')->cache,
|
||||
null,
|
||||
[
|
||||
'urls' => $c->get('urls'),
|
||||
'auth' => $c->get(Incoviba\UI\Common\Service\Auth::class),
|
||||
'api_key' => $c->get('API_KEY')
|
||||
]
|
||||
);
|
||||
},
|
||||
Psr\Http\Client\ClientInterface::class => function(Container $c) {
|
||||
return new GuzzleHttp\Client([
|
||||
'base_uri' => $c->get('urls')->api,
|
||||
'headers' => ['Authorization' => 'Bearer ' . $c->get('API_KEY')]
|
||||
]);
|
||||
},
|
||||
Incoviba\UI\Common\Service\Auth::class => function(Container $c) {
|
||||
return new Incoviba\UI\Common\Service\Auth(
|
||||
$c->get(Psr\Http\Client\ClientInterface::class),
|
||||
$c->get('cookie_name')
|
||||
);
|
||||
},
|
||||
Incoviba\UI\Common\Middleware\Auth::class => function(Container $c) {
|
||||
return new Incoviba\UI\Common\Middleware\Auth(
|
||||
$c->get(Incoviba\UI\Common\Service\Auth::class),
|
||||
$c->get(Nyholm\Psr7\Factory\Psr17Factory::class),
|
||||
['/', '/auth/login']
|
||||
);
|
||||
},
|
||||
Incoviba\UI\Common\Middleware\NotFound::class => function(Container $c) {
|
||||
return new Incoviba\UI\Common\Middleware\NotFound(
|
||||
$c->get(Nyholm\Psr7\Factory\Psr17Factory::class),
|
||||
$c->get(Slim\Views\Blade::class)
|
||||
);
|
||||
}
|
||||
];
|
Reference in New Issue
Block a user