core/src/opnsense/www/api.php
Franco Fichtner 3a98ebb22f
Phalcon 4 migration (#4921)
phalcon 4 migration  #4012

o replace Phalcon\Session\Adapter\Files with new Phalcon\Session\Adapter\Stream adapter
o replace router->setUriSource() with handle() parameter
o combining sessions between phalcon and legacy php seems to be a bit problematic, first issue seems to be the legacy csrf check. refactor to use phalcon's method and legacy session
o Fix Phalcon Syslog usage in ControllerRoot (wrap in Logger class)
o session seems to miss standard prefix.
o also Gettext seems to like being wrapped...
o Gettext inheritance
o another handle()
o Volt: handle registerEngines / VoltEngine changes
o volt templates - missing session reference, bootstrap in ControllerBase
o router getRewriteUri() deprecated
o another handle() in index.php
o  Phalcon\Dispatcher::EXCEPTION_* moved to  Phalcon\Dispatcher\Exception::EXCEPTION_*
o changes in filter handling.
o fix plist
o Syslog usage changes
o refactor Validation changes
o FILTER_ALNUM - replaced FILTER_ALPHANUM
2021-04-15 11:36:57 +02:00

46 lines
1.3 KiB
PHP

<?php
error_reporting(E_ALL);
try {
/**
* Read the configuration
*/
$config = include __DIR__ . "/../mvc/app/config/config.php";
/**
* Read auto-loader
*/
include __DIR__ . "/../mvc/app/config/loader.php";
/**
* Read services
*/
include __DIR__ . "/../mvc/app/config/services_api.php";
/**
* Handle the request
*/
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle($_SERVER['REQUEST_URI'])->getContent();
} catch (Exception $e) {
$response = array();
$response['errorMessage'] = $e->getMessage();
if (method_exists($e, 'getTitle')) {
$response['errorTitle'] = $e->getTitle();
} else {
$response['errorTitle'] = gettext("An API exception occured");
error_log($e);
}
header('HTTP', true, 500);
header("Content-Type: application/json;charset=utf-8");
echo json_encode($response, JSON_UNESCAPED_SLASHES);
} catch (ArgumentCountError $e) {
error_log($e);
$response = ['errorMessage' => 'endpoint parameter mismatch', 'errorTitle' => gettext("An API exception occured")];
header('HTTP', true, 500);
header("Content-Type: application/json;charset=utf-8");
echo json_encode($response, JSON_UNESCAPED_SLASHES);
}