gl-website-deployer/common.php

73 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2024-11-19 08:02:04 +01:00
<?php
require_once dirname(__FILE__).'/vendor/autoload.php';
require_once dirname(__FILE__).'/lib/config/config.php';
require_once dirname(__FILE__).'/lib/schema.php';
require_once dirname(__FILE__).'/assets/jslib.php';
// If debug mode, we activate the helper
if ($iap_debug) {
\Symfony\Component\ErrorHandler\Debug::enable();
}
// Start session
if(session_status() !== PHP_SESSION_ACTIVE) session_start();
Mustache_Autoloader::register();
function setup_mustache()
{
$mustache = new Mustache_Engine(array(
'template_class_prefix' => '__MyTemplates__',
'cache' => '/tmp/cache/mustache',
'loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/views'),
'partials_loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/views/partials'),
'escape' => function ($value) {
return htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
},
'charset' => 'ISO-8859-1',
));
return $mustache;
}
function return_error($e, array $extra = null)
{
header('Content-Type: application/json');
$data =[
'return_code'=>'-1',
'exception_code'=>$e->getCode(),
'exception_message'=>$e->getMessage(),
'exception_trace'=>$e->getTrace()
];
if ($extra) {
$data['extra'] = $extra;
}
echo json_encode($data);
exit(200);
}
function return_generic_error($data)
{
header('Content-Type: application/json');
echo json_encode([
'return_code'=>'-2',
'error'=>$data
]);
exit(200);
}
function return_ok($data)
{
header('Content-Type: application/json');
$data = [
'return_code'=>'1',
'data'=>$data
];
echo json_encode($data);
exit(200);
}
$db_conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
$schema = new PersoSchema([], $db_conn);