Files
This commit is contained in:
53
setup/app.php
Normal file
53
setup/app.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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'));
|
||||
}
|
||||
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
||||
$app->addRoutingMiddleware();
|
||||
|
||||
include_once 'databases.php';
|
||||
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'
|
||||
]);
|
24
setup/databases.php
Normal file
24
setup/databases.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
$database = $app->getContainer()->get('database');
|
||||
|
||||
foreach ($database->databases as $name => $settings) {
|
||||
switch (strtolower($settings->engine)) {
|
||||
case 'mysql':
|
||||
$dsn = "mysql:host={$settings->host->name};dbname={$settings->name}" . (isset($settings->host->port) ? ';port=' . $settings->host->port : '');
|
||||
ORM::configure([
|
||||
'connection_string' => $dsn,
|
||||
'username' => $settings->user->name,
|
||||
'password' => $settings->user->password
|
||||
], null, $name);
|
||||
break;
|
||||
}
|
||||
if (isset($settings->logging) and $settings->logging) {
|
||||
ORM::configure('logging', true, $name);
|
||||
}
|
||||
if (isset($settings->caching) and $settings->caching) {
|
||||
ORM::configure('caching', true, $name);
|
||||
}
|
||||
}
|
||||
if (isset($database->short_names) and $database->short_names) {
|
||||
Model::$short_table_names = true;
|
||||
}
|
4
setup/middlewares/01_error.php
Normal file
4
setup/middlewares/01_error.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
$app->add($app->getContainer()->get(Zeuxisoo\Whoops\Slim\WhoopsMiddleware::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\API\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();
|
||||
}
|
5
setup/settings/01_env.php
Normal file
5
setup/settings/01_env.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
'debug' => $_ENV['DEBUG'] ?? false,
|
||||
'AUTH_KEY' => $_ENV['API_KEY']
|
||||
];
|
24
setup/settings/02_databases.php
Normal file
24
setup/settings/02_databases.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
return [
|
||||
'database' => function() {
|
||||
$arr = [
|
||||
'default' => (object) [
|
||||
'engine' => 'mysql',
|
||||
'host' => (object) [
|
||||
'name' => $_ENV['MYSQL_HOST'] ?? 'db'
|
||||
],
|
||||
'user' => (object) [
|
||||
'name' => $_ENV['MYSQL_USER'],
|
||||
'password' => $_ENV['MYSQL_PASSWORD']
|
||||
],
|
||||
'name' => $_ENV['MYSQL_DATABASE'],
|
||||
'logging' => true,
|
||||
'caching' => true
|
||||
]
|
||||
];
|
||||
return (object) [
|
||||
'short_names' => true,
|
||||
'databases' => $arr
|
||||
];
|
||||
}
|
||||
];
|
15
setup/settings/03_common.php
Normal file
15
setup/settings/03_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;
|
||||
}
|
||||
];
|
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'
|
||||
]);
|
||||
}
|
||||
];
|
15
setup/setups/02_auth.php
Normal file
15
setup/setups/02_auth.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
Incoviba\API\Common\Service\Auth::class => function(Container $c) {
|
||||
return new Incoviba\API\Common\Service\Auth($c->get('AUTH_KEY'));
|
||||
},
|
||||
Incoviba\API\Common\Middleware\Auth::class => function(Container $c) {
|
||||
return new Incoviba\API\Common\Middleware\Auth(
|
||||
$c->get(Incoviba\API\Common\Service\Auth::class),
|
||||
$c->get(Slim\Psr7\Factory\ResponseFactory::class),
|
||||
['/auth/generate']
|
||||
);
|
||||
}
|
||||
];
|
Reference in New Issue
Block a user