first commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Desc. : Konfigurasi Parameter Utama Aplikasi
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 23rd, 2019.
|
||||
Last Modified : September 2nd, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
use flight\Engine;
|
||||
use flight\Session;
|
||||
use flight\database\SimplePdo;
|
||||
use Webapp\App\Register;
|
||||
|
||||
/** @var Engine $app
|
||||
* @var Session $session
|
||||
* @var SimplePdo $db
|
||||
*/
|
||||
|
||||
$apps = [
|
||||
'APP_CODE' => "-",
|
||||
'APP_NAME' => "-",
|
||||
'APP_NAMES' => "-",
|
||||
'APP_VER' => "-",
|
||||
'APP_UPDATED' => "-",
|
||||
'APP_SID' => $session->id(),
|
||||
'APP_LOCALE' => [ 'id' => "Indonesia", 'en' => "English" ],
|
||||
'DEF_LOCALE' => "id",
|
||||
'AUTH_OVER' => false,
|
||||
'AUTH_LEVEL' => 9,
|
||||
'USER_LEVEL' => [ 0 => "Administrator", 1 => "Supervisor", 9 => "Operator" ],
|
||||
'CREATOR_YEAR' => 0,
|
||||
'CREATOR_NAME' => "3FONIA Software",
|
||||
'CREATOR_WEBSITE' => "https://www.3fonia.com",
|
||||
'PARENT_SITE' => "https://localhost",
|
||||
'PARENT_CODE' => "-",
|
||||
'PARENT_SUB' => false,
|
||||
'SERVER_ID' => "0",
|
||||
];
|
||||
|
||||
$_apps = $session->get('WEB_APP', []);
|
||||
|
||||
if (count($_apps) > 0 && ($_apps['APP_CODE'] ?? "") !== $apps['APP_CODE']) {
|
||||
$session->clear();
|
||||
}
|
||||
|
||||
// config web_app
|
||||
if (empty($session->get('WEB_APP'))) {
|
||||
$row = $app->db()->fetchRow("SELECT * FROM app_config WHERE REG_ID = ?", [$apps['APP_CODE']]);
|
||||
if ($row) $apps = array_merge($apps, $row->getData());
|
||||
if ($apps['APP_BUILD'] ?? "" !== "") $apps['APP_VER'] = $apps['APP_BUILD'];
|
||||
$apps['CREATOR_YEARS'] = ($apps['CREATOR_YEAR'] !== date('Y')) ? $apps['CREATOR_YEAR']." - ".date('Y') : $apps['CREATOR_YEAR'];
|
||||
$apps = array_merge($apps, Register::reg_status($db, $apps));
|
||||
$session->set('WEB_APP', $apps);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Desc. : Konfigurasi Assets Aplikasi [css / js]
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 23rd, 2019.
|
||||
Last Modified : October 20th, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
return [
|
||||
'css' => [
|
||||
'login' => [ "bootstrap/bootstrap.css", "bootstrap/bootstrap.icon.css" ],
|
||||
'monitor' => [ "bootstrap/bootstrap.css", "bootstrap/bootstrap.icon.css" ],
|
||||
'index' => [
|
||||
"bootstrap/bootstrap.css",
|
||||
"bootstrap/bootstrap.icon.css",
|
||||
"bootstrap/bootstrap.datepicker.css",
|
||||
"datatables/dataTables.bootstrap5.css",
|
||||
"datatables/responsive.bootstrap5.css",
|
||||
"datatables/scroller.bootstrap5.css",
|
||||
"datatables/stateRestore.bootstrap5.css",
|
||||
"select2/select2.css",
|
||||
"select2/select2-bootstrap-5-theme.css",
|
||||
//"lightbox.css",
|
||||
//"summernote-bs4.css",
|
||||
"default.css",
|
||||
"print.css",
|
||||
],
|
||||
],
|
||||
|
||||
'js' => [
|
||||
'login' => [ "jquery/jquery.js", "jquery/jquery.base64.js", "bootstrap/bootstrap.bundle.js", "jquery/jquery.backstretch.js", "fonia3.js" ],
|
||||
'monitor' => [ "jquery/jquery.js", "jquery/jquery.base64.js", "bootstrap/bootstrap.bundle.js", "socket.io/socket.io.js", "fonia3.js" ],
|
||||
'index' => [
|
||||
"jquery/jquery.js",
|
||||
"jquery/jquery.base64.js",
|
||||
"jquery/jquery.autosize.js",
|
||||
"jquery/jquery.validate.js",
|
||||
"bootstrap/bootstrap.bundle.js",
|
||||
"bootstrap/bootstrap.datepicker.js",
|
||||
"bootstrap/bootstrap.autocomplete.js",
|
||||
"datatables/jquery.dataTables.js",
|
||||
"datatables/dataTables.bootstrap5.js",
|
||||
"datatables/dataTables.responsive.js",
|
||||
"datatables/dataTables.scroller.js",
|
||||
"datatables/dataTables.stateRestore.js",
|
||||
"datatables/responsive.bootstrap5.js",
|
||||
"datatables/scroller.bootstrap5.js",
|
||||
"datatables/stateRestore.bootstrap5.js",
|
||||
"select2/select2.js",
|
||||
"chart/chart.js",
|
||||
"socket.io/socket.io.js",
|
||||
//"lightbox.js",
|
||||
//"summernote-bs4.js",
|
||||
"moment.js",
|
||||
"html5-qrcode.js",
|
||||
"fonia3.js",
|
||||
"print.js",
|
||||
"pdf.js",
|
||||
"download.js",
|
||||
//"simulator.js",
|
||||
"pole-display.js",
|
||||
// add qz support
|
||||
"qz/qz-tray.js",
|
||||
"qz/qz-start.js",
|
||||
],
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Desc. : Proses Utama Aplikasi
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 23rd, 2019.
|
||||
Last Modified : September 13th, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
$ds = DIRECTORY_SEPARATOR;
|
||||
$projectRoot = dirname(__DIR__, 2);
|
||||
|
||||
require $projectRoot . $ds . 'vendor' . $ds . 'autoload.php';
|
||||
|
||||
use App\Utils\Config;
|
||||
use App\Utils\Env;
|
||||
|
||||
/* Loading configuration from .env */
|
||||
Env::load($projectRoot . $ds . '.env');
|
||||
|
||||
$configPath = __DIR__ . $ds . 'config.php';
|
||||
if (file_exists($configPath) === false) {
|
||||
Flight::halt(500, 'Ada kendala dengan Konfigurasi Aplikasi, hubungi Developer.');
|
||||
}
|
||||
|
||||
/* App Main Configuration */
|
||||
$fileConfig = require $configPath;
|
||||
|
||||
/* Merge from .env and config */
|
||||
$merged = Config::mergeEnv($fileConfig, $_ENV);
|
||||
$config = new Config($merged);
|
||||
|
||||
// Setup timezone from config
|
||||
$timezone = (string) $config->get('app.timezone', 'UTC');
|
||||
if (!empty($timezone)) date_default_timezone_set($timezone);
|
||||
|
||||
// Character encoding
|
||||
if (function_exists('mb_internal_encoding') === true) {
|
||||
mb_internal_encoding('UTF-8');
|
||||
}
|
||||
|
||||
// Default Locale Change as needed or feel free to remove.
|
||||
if (function_exists('setlocale') === true) {
|
||||
setlocale(LC_ALL, 'en_US.UTF-8');
|
||||
}
|
||||
|
||||
// Error reporting config
|
||||
if ($config->env() === 'production') {
|
||||
error_reporting(E_ALL & ~E_DEPRECATED);
|
||||
} else {
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
|
||||
/* FlightPHP App Instance */
|
||||
$app = Flight::app();
|
||||
$app->set('app.project_root', $projectRoot);
|
||||
$app->set('flight.base_url', $config->baseUrl());
|
||||
$app->set('flight.case_sensitive', false);
|
||||
$app->set('flight.log_errors', true);
|
||||
$app->set('flight.handle_errors', $config->isDebug() === false);
|
||||
$app->set('flight.views.path', __DIR__ . $ds . '..' . $ds . 'views');
|
||||
$app->set('flight.views.extension', '.twig');
|
||||
$app->set('flight.content_length', false);
|
||||
$app->set('csp_nonce', bin2hex(random_bytes(16)));
|
||||
|
||||
if (!defined('PROJECT_ROOT')) define('PROJECT_ROOT', $projectRoot . '/');
|
||||
if (!defined('PROJECT_BASE')) define('PROJECT_BASE', $config->baseUrl() . '/');
|
||||
|
||||
/* Loading Services */
|
||||
require(__DIR__ . $ds . 'services.php');
|
||||
|
||||
/* Loading App Configuration */
|
||||
require(__DIR__ . $ds . 'app.php');
|
||||
|
||||
/* Loading App Route Configuration */
|
||||
require(__DIR__ . $ds . 'routes.php');
|
||||
|
||||
/* Start App */
|
||||
$app->start();
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Desc. : Default Konfigurasi Aplikasi
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 23rd, 2019.
|
||||
Last Modified : August 22nd, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
return [
|
||||
'app' => [
|
||||
'env' => 'development',
|
||||
'debug' => true,
|
||||
'base_url' => '/',
|
||||
'timezone' => 'UTC',
|
||||
],
|
||||
'database' => [
|
||||
'driver' => 'mysql',
|
||||
'host' => 'localhost',
|
||||
'dbname' => '',
|
||||
'user' => '',
|
||||
'password' => '',
|
||||
'file_path' => __DIR__ . '/../../database.sqlite',
|
||||
'charset' => 'utf8mb4',
|
||||
'socket' => '',
|
||||
],
|
||||
'session' => [
|
||||
'prefix' => 'fsess_',
|
||||
'save_path' => __DIR__ . '/../../temp/session',
|
||||
'encryption_key' => '58766743c3a4f802a1b84eb5700379af',
|
||||
],
|
||||
'runway' => [
|
||||
'app_root' => 'app/',
|
||||
'index_root' => 'public/index.php',
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,25 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEQTCCAymgAwIBAgIURsO6MescVe8spD7xpJWisWkfaDcwDQYJKoZIhvcNAQEL
|
||||
BQAwga4xCzAJBgNVBAYTAklEMRkwFwYDVQQIDBBLYWxpbWFudGFuIEJhcmF0MREw
|
||||
DwYDVQQHDAhNZW1wYXdhaDEYMBYGA1UECgwPM0ZPTklBIFNvZnR3YXJlMRgwFgYD
|
||||
VQQLDA9EaXZpc2kgV2ViIEFwcHMxGDAWBgNVBAMMDzNGT05JQSBTb2Z0d2FyZTEj
|
||||
MCEGCSqGSIb3DQEJARYUc2lhdXBoZW5nQDNmb25pYS5jb20wIBcNM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fg7ySHoN0X0QKBgQDJ/72KWRKcEW25IGOX
|
||||
PkpIWUf4dq7NzMsysNj+CfWM/OcIVrPZohS2WMeUTl5PARI6Va5k3IRD+0RVL/1H
|
||||
aFE3Pq6UhvtQMmvrIEU9H0lIUEtxi1niHzlagp56dTxXHOzMXKThfrLFPH+0Sbqb
|
||||
x60snZM2cNL4gNe+ykmGx0DRswKBgQDGGdexeEg5yRWKSKY7MbDTM9w2aiAa6yyx
|
||||
VQiMgPlKnmHbO7yo9UTH+QEez7RLQWW/hxRsVowCkpVe6P7E1+Ct/nSYAS3syZ+D
|
||||
DXRzlrpGaTnSXnOeS8iEsR9qbUN4i6KXCBJfkCo/RIhcC89JTcn/YO+4L43xTlJB
|
||||
/mv0J7WvPwKBgEN5BFPpCtlMzQzQb9O+P8vI3sx0wFEH/jvRbLn2k6njdDyJ0Yt5
|
||||
o1eBcjDsuH3FStRneFhCfH/Et3+JBx5KDw7YBjKgn+Oa5AdnARm4kJ7yCzFDLePl
|
||||
MCA2jz8yV9R1WfetXnnf+1D8s1+CXS3Z1dOYUusVZrMRPn+BTGwTtGgXAoGAbSj2
|
||||
WxutqPHuRanst7eU+XydPvrRwCORGBKESHAVbpHB2H2dYvjsMsk6XdEUR1e9CoIT
|
||||
tfMm6Y/+cTMwmCVg8F/DvbMArHcZx6xVXBBVitEXBJ35VePqlXvIlOuqfzVqnZDc
|
||||
Fv6o2P4Zqab0TS9pPKkcz0CdFbgTybu5nut2yR8CgYEAm8zi9zzISz4lHUE6hbq+
|
||||
VQNpENiZdcCy6AAt2pkSKELNIXz4Qtu4ntvBCjnWf5pYSN2NO2027G2RG3ViBPjB
|
||||
lfiyDswCefMzBATDkqGztBmyv6hHDgwWyjm2xKPlkhwUFpKg2Vd3f5Z9sNKlppN3
|
||||
x74KMqdBQGSiq9X8F74uGzA=
|
||||
-----END PRIVATE KEY-----
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Desc. : Loading Routing Setup
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 23rd, 2019.
|
||||
Last Modified : October 21st, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
use flight\Engine;
|
||||
use flight\Session;
|
||||
use flight\net\Router;
|
||||
use Webapp\App\Auth;
|
||||
use Webapp\Data\Cache;
|
||||
use Webapp\Web\Menu;
|
||||
use App\Middleware\SecurityHeaders;
|
||||
use App\Controller\IndexController;
|
||||
use App\Controller\QZController;
|
||||
|
||||
/**
|
||||
* Application routes.
|
||||
*
|
||||
* @var Router $router
|
||||
* @var Engine $app
|
||||
* @var Session $session
|
||||
*/
|
||||
|
||||
$router = $app->router();
|
||||
|
||||
$router->group('', function(Router $router) use ($app, $session, $config) {
|
||||
|
||||
$router->get('/(@token(/@nowhere))', function(?string $token, ?string $nowhere) use ($app, $session, $config) {
|
||||
$token_s = $session->get('APP_TOKEN');
|
||||
if (!empty($token) && strlen($token ?? '') === 60) {
|
||||
$auth = new Auth($app);
|
||||
if ($token !== $token_s) {
|
||||
if ($auth->token_check($token)) {
|
||||
if (empty($session->get('WEB_USER'))) {
|
||||
$auser = $auth->user_data($auth->getUserByToken($token));
|
||||
$auth->pos_login($session->get("APP_INV")['CABANGID'] ?? 0, $auser['UserID'], $auser['UNIX'], $app->request()->ip);
|
||||
$session->set('WEB_USER', $auser);
|
||||
}
|
||||
$auth->user_log();
|
||||
$session->set('APP_TOKEN', $token);
|
||||
} else {
|
||||
$session->delete('APP_TOKEN');
|
||||
$session->delete('WEB_USER');
|
||||
$app->redirect('/', 301);
|
||||
}
|
||||
} else $auth->token_update();
|
||||
if (!empty($nowhere)) $app->redirect($token ?? $token_s, 301);
|
||||
} else {
|
||||
if (!empty($token_s) && empty($nowhere) && $token !== 'monitor') $app->redirect($token_s, 301);
|
||||
return true;
|
||||
}
|
||||
|
||||
$asset = require('asset.php');
|
||||
$_user = $session->get('WEB_USER') ?? [];
|
||||
$_menu = new Menu($app);
|
||||
$cache = new Cache($app);
|
||||
$cache->set_dev($config->env() === 'development');
|
||||
$cache->set_asset($asset);
|
||||
|
||||
$_web_app = $session->get('WEB_APP') ?? [];
|
||||
$_web_app = array_merge($_web_app, $cache->Cache('index'));
|
||||
|
||||
$_web_app['NAVI_SIDEBAR'] = $_menu->Sidebar();
|
||||
$_web_app['NAVI_HEADER'] = $_menu->Header();
|
||||
$_web_app['USER_ID'] = $_user['UserID'] ?? "";
|
||||
$_web_app['USER_USER'] = $_user['Username'] ?? "";
|
||||
$_web_app['USER_NAME'] = $_user['Nama'] ?? "";
|
||||
$_web_app['USER_POSISI'] = $_user['Posisi'] ?? "";
|
||||
$_web_app['MENU_MODUL'] = $_menu->Modul();
|
||||
$app->render('index', $_web_app);
|
||||
});
|
||||
|
||||
$router->get('/login', function() use ($app, $session, $config) {
|
||||
$asset = require('asset.php');
|
||||
$cache = new Cache($app);
|
||||
$cache->set_dev($config->env() === 'development');
|
||||
$cache->set_asset($asset);
|
||||
$_web_app = $session->get('WEB_APP') ?? [];
|
||||
$_web_app = array_merge($_web_app, $cache->Cache('login'));
|
||||
$app->render('login', $_web_app);
|
||||
});
|
||||
|
||||
$router->get('/monitor', function() use ($app, $session, $config) {
|
||||
$asset = require('asset.php');
|
||||
$cache = new Cache($app);
|
||||
$cache->set_dev($config->env() === 'development');
|
||||
$cache->set_asset($asset);
|
||||
$_web_app = $session->get('WEB_APP') ?? [];
|
||||
$_web_app = array_merge($_web_app, $cache->Cache('monitor'));
|
||||
$app->render('monitor', $_web_app);
|
||||
});
|
||||
|
||||
$router->post('/(@path1(/@path2(/@path3(/@path4))))', static function ($path1, $path2, $path3, $path4) use ($app) {
|
||||
$_path1 = ucfirst($path1) . '\\';
|
||||
$_path2 = ucfirst($path2) . '\\';
|
||||
if (empty($path3)) {
|
||||
$_path1 = '';
|
||||
$_path2 = '';
|
||||
$controller = $path1;
|
||||
$method = $path2;
|
||||
} else if (empty($path4)) {
|
||||
$_path2 = '';
|
||||
$controller = $path2;
|
||||
$method = $path3;
|
||||
} else {
|
||||
$controller = $path3;
|
||||
$method = $path4;
|
||||
}
|
||||
$controller = $controller ? ucfirst(strtolower($controller)) : 'Index';
|
||||
$method = $method ? $method : 'index';
|
||||
$class = '\\App\\Controller\\' . $_path1 . $_path2 . $controller . 'Controller';
|
||||
if (!class_exists($class) || (class_exists($class) && ! method_exists($class, $method))) return true;
|
||||
$ct = $app->make($class);
|
||||
$ct->$method();
|
||||
});
|
||||
|
||||
// handle Cache css & js for application
|
||||
$router->get('/cache/@filename', function($filename) use ($app) {
|
||||
$rootdir = (defined('PROJECT_ROOT')) ? PROJECT_ROOT : $app->get('app.project_root');
|
||||
$filePath = $rootdir . '/temp/cache/' . $filename;
|
||||
if (file_exists($filePath) && !str_contains($filename, '..')) {
|
||||
$mimeType = 'application/octet-stream';
|
||||
if (str_ends_with($filePath, '.js')) $mimeType = 'application/javascript';
|
||||
if (str_ends_with($filePath, '.css')) $mimeType = 'text/css';
|
||||
$app->response()->header('Content-Type', $mimeType);
|
||||
echo file_get_contents($filePath);
|
||||
} else {
|
||||
$app->notFound();
|
||||
}
|
||||
});
|
||||
|
||||
// handle QZ Printer
|
||||
$router->group('/qz', function() use ($router) {
|
||||
$router->get('/cert', [ QZController::class, 'getCert' ]);
|
||||
$router->get('/sign(/@req)', [ QZController::class, 'getSign' ]);
|
||||
});
|
||||
|
||||
$router->get('/401', [IndexController::class, 'get401']);
|
||||
$router->get('/404', [IndexController::class, 'get404']);
|
||||
$router->get('*', [IndexController::class, 'get404']);
|
||||
$router->post('*', [IndexController::class, 'post404']);
|
||||
|
||||
}, [ SecurityHeaders::class ]);
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Desc. : Proses Utama Runway
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 23rd, 2019.
|
||||
Last Modified : September 3rd, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
$ds = DIRECTORY_SEPARATOR;
|
||||
$projectRoot = dirname(__DIR__, 2);
|
||||
|
||||
require $projectRoot . $ds . 'vendor' . $ds . 'autoload.php';
|
||||
|
||||
use App\Utils\Config;
|
||||
use App\Utils\Env;
|
||||
|
||||
/* Loading configuration from .env */
|
||||
Env::load($projectRoot . $ds . '.env');
|
||||
|
||||
$configPath = __DIR__ . $ds . 'config.php';
|
||||
if (file_exists($configPath) === false) {
|
||||
Flight::halt(500, 'Ada kendala dengan Konfigurasi Aplikasi, hubungi Developer.');
|
||||
}
|
||||
|
||||
/* App Main Configuration */
|
||||
$fileConfig = require $configPath;
|
||||
|
||||
/* Merge from .env and config */
|
||||
$merged = Config::mergeEnv($fileConfig, $_ENV);
|
||||
$config = new Config($merged);
|
||||
|
||||
// Setup timezone from config
|
||||
$timezone = (string) $config->get('app.timezone', 'UTC');
|
||||
if (!empty($timezone)) date_default_timezone_set($timezone);
|
||||
|
||||
// Character encoding
|
||||
if (function_exists('mb_internal_encoding') === true) {
|
||||
mb_internal_encoding('UTF-8');
|
||||
}
|
||||
|
||||
// Default Locale Change as needed or feel free to remove.
|
||||
if (function_exists('setlocale') === true) {
|
||||
setlocale(LC_ALL, 'en_US.UTF-8');
|
||||
}
|
||||
|
||||
// Error reporting level (E_ALL recommended for development)
|
||||
error_reporting(E_ALL);
|
||||
|
||||
/* FlightPHP App Instance */
|
||||
$app = Flight::app();
|
||||
$app->set('app.project_root', $projectRoot);
|
||||
$app->set('flight.base_url', $config->baseUrl());
|
||||
$app->set('flight.case_sensitive', false);
|
||||
$app->set('flight.log_errors', true);
|
||||
$app->set('flight.handle_errors', $config->isDebug() === false);
|
||||
$app->set('flight.views.path', __DIR__ . $ds . '..' . $ds . 'views');
|
||||
$app->set('flight.views.extension', '.twig');
|
||||
$app->set('flight.content_length', false);
|
||||
$app->set('csp_nonce', bin2hex(random_bytes(16)));
|
||||
|
||||
//if (!defined('PROJECT_ROOT')) define('PROJECT_ROOT', $projectRoot);
|
||||
//if (!defined('PROJECT_BASE')) define('PROJECT_BASE', $config->baseUrl());
|
||||
if (!defined('RUNWAY_CMD')) define('RUNWAY_CMD', true);
|
||||
|
||||
/* Loading Services */
|
||||
require(__DIR__ . $ds . 'services.php');
|
||||
|
||||
/* Loading App Configuration */
|
||||
require(__DIR__ . $ds . 'app.php');
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Desc. : Loading Service untuk Aplikasi
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : November 23rd, 2019.
|
||||
Last Modified : September 10th, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
use flight\Engine;
|
||||
use flight\database\SimplePdo;
|
||||
use flight\debug\database\PdoQueryCapture;
|
||||
use flight\debug\tracy\TracyExtensionLoader;
|
||||
use flight\Session;
|
||||
use Dice\Dice;
|
||||
use Tracy\Debugger;
|
||||
use App\Utils\Config;
|
||||
use App\Utils\DBFactory;
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\FilesystemLoader;
|
||||
use Webapp\App\User;
|
||||
|
||||
/**
|
||||
* Services + Dice DI wiring.
|
||||
*
|
||||
* @var Engine $app
|
||||
* @var string $projectRoot
|
||||
* @var string $ds
|
||||
*/
|
||||
|
||||
if (!isset($app) || !($app instanceof Engine) || !($config instanceof Config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*********************************************
|
||||
* Tracy Debugger Setup *
|
||||
*********************************************/
|
||||
|
||||
$logDir = $projectRoot . $ds . 'temp' . $ds . 'log';
|
||||
if (!is_dir($logDir)) {
|
||||
mkdir($logDir, 0775, true);
|
||||
}
|
||||
if ($config->isDebug()) {
|
||||
Debugger::enable(Debugger::Development);
|
||||
Debugger::$strictMode = true;
|
||||
} else {
|
||||
Debugger::enable(Debugger::Production);
|
||||
Debugger::$strictMode = E_ALL & ~E_DEPRECATED;
|
||||
}
|
||||
Debugger::$logDirectory = $logDir;
|
||||
if (Debugger::$showBar === true && PHP_SAPI !== 'cli' && class_exists(TracyExtensionLoader::class)) {
|
||||
new TracyExtensionLoader($app);
|
||||
}
|
||||
|
||||
/**********************************************
|
||||
* Flight Database Setup *
|
||||
**********************************************/
|
||||
|
||||
$db = null;
|
||||
if (DBFactory::isEnabled($config)) {
|
||||
$db = DBFactory::create($config);
|
||||
$app->map('db', function () use ($db) {
|
||||
return $db;
|
||||
});
|
||||
}
|
||||
|
||||
/**********************************************
|
||||
* Flight Session Setup *
|
||||
**********************************************/
|
||||
|
||||
$sessionOptions = [
|
||||
'prefix' => (string) $config->get('session.prefix', 'flight_sess_'),
|
||||
'encryption_key' => (string) $config->get('session.encryption_key', md5($projectRoot)),
|
||||
'auto_commit' => true,
|
||||
];
|
||||
$savePath = $config->get('session.save_path');
|
||||
if ($savePath !== null && $savePath !== '') {
|
||||
$sessionOptions['save_path'] = (string) $savePath;
|
||||
}
|
||||
if (PHP_SAPI === 'cli') $sessionOptions['start_session'] = false;
|
||||
$session = new Session($sessionOptions);
|
||||
$app->map('session', function () use ($session) {
|
||||
return $session;
|
||||
});
|
||||
|
||||
/**********************************************
|
||||
* User Util Setup *
|
||||
**********************************************/
|
||||
|
||||
$user = new User($app);
|
||||
$app->map('user', function () use ($user) {
|
||||
return $user;
|
||||
});
|
||||
|
||||
/**********************************************
|
||||
* Setup Twig as Default Render *
|
||||
**********************************************/
|
||||
|
||||
if (!defined('RUNWAY_CMD')) {
|
||||
$viewsPath = $projectRoot . $ds . 'app' . $ds . 'views';
|
||||
$twigCache = $projectRoot . $ds . 'temp' . $ds . 'twig';
|
||||
if (!is_dir($twigCache)) mkdir($twigCache, 0775, true);
|
||||
$loader = new FilesystemLoader($viewsPath);
|
||||
$twig = new Environment($loader, [
|
||||
'cache' => $config->isDebug() ? false : $twigCache,
|
||||
'debug' => $config->isDebug(),
|
||||
'auto_reload' => $config->isDebug(),
|
||||
]);
|
||||
$twig->addGlobal('csp_nonce', $app->get('csp_nonce'));
|
||||
$app->map('render', function (string $template, array $data = []) use ($app, $twig) {
|
||||
if (substr($template, -5) !== '.twig') $template .= '.twig';
|
||||
$app->response()->write($twig->render($template, $data));
|
||||
});
|
||||
}
|
||||
|
||||
/**********************************************
|
||||
* Dice + Engine substitutions *
|
||||
**********************************************/
|
||||
|
||||
if (!defined('RUNWAY_CMD')) {
|
||||
$container = new Dice();
|
||||
$substitutions = [
|
||||
Engine::class => $app,
|
||||
Config::class => $config,
|
||||
Session::class => $session,
|
||||
];
|
||||
if ($db instanceof SimplePdo) $substitutions[SimplePdo::class] = $db;
|
||||
$container = $container->addRule('*', [
|
||||
'substitutions' => $substitutions,
|
||||
]);
|
||||
$container = $container->addRule(Config::class, ['shared' => true]);
|
||||
$container = $container->addRule(Session::class, ['shared' => true]);
|
||||
if ($db instanceof SimplePdo) $container = $container->addRule(SimplePdo::class, ['shared' => true]);
|
||||
$app->registerContainerHandler(function ($class, $params) use ($container) {
|
||||
return $container->create($class, $params);
|
||||
});
|
||||
// Helper for non-route code: $app->make(SomeClass::class)
|
||||
$app->map('make', function ($class, $params = []) use ($container) {
|
||||
return $container->create($class, $params);
|
||||
});
|
||||
}
|
||||
|
||||
/**********************************************
|
||||
* Third-Party Integrations *
|
||||
**********************************************/
|
||||
// Google OAuth Example:
|
||||
// $app->register('google_oauth', Google_Client::class, [ $config['google_oauth'] ]);
|
||||
|
||||
// Redis Example:
|
||||
// $app->register('redis', Redis::class, [ $config['redis']['host'], $config['redis']['port'] ]);
|
||||
|
||||
// Add more service registrations below as needed
|
||||
Reference in New Issue
Block a user