UI
This commit is contained in:
64
ui/setup/app.php
Normal file
64
ui/setup/app.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
use DI\ContainerBuilder as Builder;
|
||||
use DI\Bridge\Slim\Bridge;
|
||||
|
||||
include_once 'composer.php';
|
||||
|
||||
$builder = new Builder();
|
||||
|
||||
$folders = [
|
||||
implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 2),
|
||||
'setup',
|
||||
'env'
|
||||
]),
|
||||
implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 2),
|
||||
'setup',
|
||||
'common'
|
||||
]),
|
||||
implode(DIRECTORY_SEPARATOR, [
|
||||
__DIR__,
|
||||
'web'
|
||||
])
|
||||
];
|
||||
$files = [
|
||||
'settings',
|
||||
'setups'
|
||||
];
|
||||
|
||||
foreach ($files as $file) {
|
||||
foreach ($folders as $folder) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
$file . '.php'
|
||||
]);
|
||||
if (!file_exists($filename)) {
|
||||
continue;
|
||||
}
|
||||
$builder->addDefinitions($filename);
|
||||
}
|
||||
}
|
||||
|
||||
$container = $builder->build();
|
||||
$app = Bridge::create($container);
|
||||
include_once 'databases.php';
|
||||
|
||||
if ($container->has('base_url')) {
|
||||
$app->setBasePath($container->get('base_url'));
|
||||
}
|
||||
$app->addRoutingMiddleware();
|
||||
|
||||
foreach ($folders as $folder) {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
'middleware.php'
|
||||
]);
|
||||
if (!file_exists($filename)) {
|
||||
continue;
|
||||
}
|
||||
include_once $filename;
|
||||
}
|
||||
|
||||
include_once 'router.php';
|
||||
$app->addErrorMiddleware(true, true, true);
|
6
ui/setup/composer.php
Normal file
6
ui/setup/composer.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__),
|
||||
'vendor',
|
||||
'autoload.php'
|
||||
]);
|
36
ui/setup/databases.php
Normal file
36
ui/setup/databases.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
$databases = $app->getContainer()->get('databases');
|
||||
foreach ($databases as $name => $settings) {
|
||||
switch($settings->system) {
|
||||
case 'mysql':
|
||||
$dsn = implode(':', [
|
||||
'mysql',
|
||||
implode(';', [
|
||||
implode('=', [
|
||||
'host',
|
||||
$settings->host->name
|
||||
]),
|
||||
implode('=', [
|
||||
'dbname',
|
||||
$settings->name
|
||||
])
|
||||
])
|
||||
]);
|
||||
if (isset($settings->host->port)) {
|
||||
$dsn .= ';' . implode('=', [
|
||||
'port',
|
||||
$settings->host->port
|
||||
]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
ORM::configure($dsn, null, $name);
|
||||
switch ($settings->system) {
|
||||
case 'mysql':
|
||||
ORM::configure('username', $settings->user->name, $name);
|
||||
ORM::configure('password', $settings->user->password, $name);
|
||||
}
|
||||
}
|
||||
if (isset($databases->short_names)) {
|
||||
Model::$short_table_names = $databases->short_names;
|
||||
}
|
5
ui/setup/router.php
Normal file
5
ui/setup/router.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
$app->getContainer()->get('locations')->routes,
|
||||
'web.php'
|
||||
]);
|
50
ui/setup/web/settings.php
Normal file
50
ui/setup/web/settings.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
'locations' => DI\decorate(function($prev, Container $container) {
|
||||
$arr = (array) $prev;
|
||||
$arr['base'] = dirname(__DIR__, 2);
|
||||
$arr['resources'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['base'],
|
||||
'resources'
|
||||
]);
|
||||
$arr['routes'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['resources'],
|
||||
'routes'
|
||||
]);
|
||||
$arr['templates'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['resources'],
|
||||
'views'
|
||||
]);
|
||||
$arr['cache'] = implode(DIRECTORY_SEPARATOR, [
|
||||
$arr['base'],
|
||||
'cache'
|
||||
]);
|
||||
return (object) $arr;
|
||||
}),
|
||||
'urls' => function(Container $c) {
|
||||
$arr = ['base' => ($c->has('base_url')) ? $c->get('base_url') : ''];
|
||||
$arr['assets'] = implode('/', [
|
||||
$arr['base'],
|
||||
'assets'
|
||||
]);
|
||||
$arr['styles'] = implode('/', [
|
||||
$arr['assets'],
|
||||
'styles'
|
||||
]);
|
||||
$arr['scripts'] = implode('/', [
|
||||
$arr['assets'],
|
||||
'scripts'
|
||||
]);
|
||||
$arr['images'] = implode('/', [
|
||||
$arr['assets'],
|
||||
'images'
|
||||
]);
|
||||
$arr['api'] = 'http://localhost:8081';
|
||||
return (object) $arr;
|
||||
},
|
||||
'format' => function(Container $c) {
|
||||
return [];
|
||||
}
|
||||
];
|
16
ui/setup/web/setups.php
Normal file
16
ui/setup/web/setups.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
|
||||
return [
|
||||
Slim\Views\Blade::class => function(Container $c) {
|
||||
return new Slim\Views\Blade(
|
||||
$c->get('locations')->templates,
|
||||
$c->get('locations')->cache,
|
||||
null,
|
||||
[
|
||||
'urls' => $c->get('urls'),
|
||||
'format' => $c->get('format')
|
||||
]
|
||||
);
|
||||
}
|
||||
];
|
Reference in New Issue
Block a user