Slim API
This commit is contained in:
11
setup/api/config.php
Normal file
11
setup/api/config.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
'locations' => DI\decorate(function($prev, Container $c) {
|
||||
$arr = (array) $prev;
|
||||
$arr['cache'] = $prev->base . '/cache';
|
||||
$arr['views'] = $prev->resources . '/views';
|
||||
return (object) $arr;
|
||||
})
|
||||
];
|
15
setup/api/setups.php
Normal file
15
setup/api/setups.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
Slim\Views\Blade::class => function(Container $c) {
|
||||
return new Slim\Views\Blade(
|
||||
$c->get('locations')->views,
|
||||
$c->get('locations')->cache,
|
||||
null,
|
||||
[
|
||||
'locations' => $c->get('locations')
|
||||
]
|
||||
);
|
||||
}
|
||||
];
|
52
setup/app.php
Normal file
52
setup/app.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
use DI\ContainerBuilder as Builder;
|
||||
use DI\Bridge\Slim\Bridge;
|
||||
|
||||
include_once 'composer.php';
|
||||
|
||||
$folders = [
|
||||
'env',
|
||||
'common',
|
||||
$__environment
|
||||
];
|
||||
$files = [
|
||||
'config',
|
||||
'setups'
|
||||
];
|
||||
$builder = new Builder();
|
||||
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('/api');
|
||||
$app->addRoutingMiddleware();
|
||||
|
||||
foreach ($folders as $folder) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
$folder,
|
||||
'middleware.php'
|
||||
]);
|
||||
if (!file_exists($filename)) {
|
||||
continue;
|
||||
}
|
||||
include_once $filename;
|
||||
}
|
||||
|
||||
$app->addErrorMiddleware(true, true, true);
|
||||
|
||||
include_once 'database.php';
|
||||
|
||||
include_once 'router.php';
|
40
setup/common/config.php
Normal file
40
setup/common/config.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
return [
|
||||
'timezone' => 'America/Santiago',
|
||||
'locale' => 'es',
|
||||
'database' => 'mysql',
|
||||
'login_hours' => 5*24,
|
||||
'cierres' => [
|
||||
'caducidad' => 30
|
||||
],
|
||||
'databases' => function() {
|
||||
$arr = [
|
||||
'mysql' => [
|
||||
'host' => 'db',
|
||||
//'port' => 3306,
|
||||
'database' => 'incoviba',
|
||||
'username' => 'incoviba',
|
||||
'password' => '5GQYFvRjVw2A4KcD'
|
||||
],
|
||||
'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;
|
||||
}
|
||||
];
|
6
setup/composer.php
Normal file
6
setup/composer.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'vendor',
|
||||
'autoload.php'
|
||||
]);
|
29
setup/database.php
Normal file
29
setup/database.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
$databases = $app->getContainer()->get('databases');
|
||||
|
||||
load($databases['mysql']);
|
||||
|
||||
foreach ($databases as $name => $data) {
|
||||
load($data, $name);
|
||||
}
|
||||
|
||||
function load($data, $name = '') {
|
||||
if (!isset($data['port'])) {
|
||||
$port = 3306;
|
||||
} else {
|
||||
$port = $data['port'];
|
||||
}
|
||||
$dsn = 'mysql:host=' . $data['host'] . ';port=' . $port . ';dbname=' . $data['database'] . ';charset=utf8';
|
||||
|
||||
if ($name != '') {
|
||||
ORM::configure($dsn, null, $name);
|
||||
ORM::configure('username', $data['username'], $name);
|
||||
ORM::configure('password', $data['password'], $name);
|
||||
} else {
|
||||
ORM::configure($dsn, null);
|
||||
ORM::configure('username', $data['username']);
|
||||
ORM::configure('password', $data['password']);
|
||||
}
|
||||
}
|
||||
|
||||
Model::$short_table_names = true;
|
5
setup/env/config.php
vendored
Normal file
5
setup/env/config.php
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
'debug' => false,
|
||||
'benchmark' => false
|
||||
];
|
5
setup/router.php
Normal file
5
setup/router.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
$app->getContainer()->get('locations')->routes,
|
||||
$__environment . '.php'
|
||||
]);
|
Reference in New Issue
Block a user