* remove unused FactoryDefault() in tests
* refactor FactoryDefault() config access to new AppConfig class
* remove unused code in afterExecuteRoute() `$this->response->getHeaders()->get("Status")` will never be null
This commit is contained in:
Ad Schellevis 2024-05-04 20:21:35 +02:00
parent 3c17903ecb
commit ab76fb03c9
4 changed files with 15 additions and 28 deletions

View File

@ -395,19 +395,14 @@ class ApiControllerBase extends ControllerRoot
*/
public function afterExecuteRoute($dispatcher)
{
// exit when response headers are already set
if ($this->response->getHeaders()->get("Status") != null) {
return false;
} else {
// process response, serialize to json object
$data = $dispatcher->getReturnedValue();
if (is_array($data)) {
$this->response->setContentType('application/json', 'UTF-8');
if ($this->isExternalClient()) {
$this->response->setContent(json_encode($data));
} else {
$this->response->setContent(htmlspecialchars(json_encode($data), ENT_NOQUOTES));
}
// process response, serialize to json object
$data = $dispatcher->getReturnedValue();
if (is_array($data)) {
$this->response->setContentType('application/json', 'UTF-8');
if ($this->isExternalClient()) {
$this->response->setContent(json_encode($data));
} else {
$this->response->setContent(htmlspecialchars(json_encode($data), ENT_NOQUOTES));
}
}

View File

@ -28,7 +28,7 @@
namespace OPNsense\Core;
use Phalcon\Di\FactoryDefault;
use OPNsense\Core\AppConfig;
use OPNsense\Core\Syslog;
/**
@ -324,7 +324,7 @@ class Config extends Singleton
protected function init()
{
$this->statusIsLocked = false;
$this->config_file = FactoryDefault::getDefault()->get('config')->globals->config_path . "config.xml";
$this->config_file = (new AppConfig())->globals->config_path . "config.xml";
try {
$this->load();
} catch (\Exception $e) {

View File

@ -28,7 +28,7 @@
namespace OPNsense\Core;
use Phalcon\Di\FactoryDefault;
use OPNsense\Core\AppConfig;
/**
* Class Shell shell/command handling routines
@ -54,8 +54,9 @@ class Shell
public function __construct()
{
// init, set simulation mode / debug autoput
$this->simulate = FactoryDefault::getDefault()->get('config')->globals->simulate_mode;
$this->debug = FactoryDefault::getDefault()->get('config')->globals->debug;
$appconfig = new AppConfig();
$this->simulate = $appconfig->globals->simulate_mode;
$this->debug = $appconfig->globals->debug;
}
/**

View File

@ -1,7 +1,7 @@
<?php
/*
* Copyright (C) 2016 Deciso B.V.
* Copyright (C) 2016 - 2024 Deciso B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -26,9 +26,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
use Phalcon\Di\Di;
use Phalcon\Di\FactoryDefault;
/**
* Read the configuration
*/
@ -41,9 +38,3 @@ $config = include __DIR__ . "/app/config/config.php";
include __DIR__ . "/../app/config/loader.php";
$di = new FactoryDefault();
Di::reset();
$di->set('config', $config);
Di::setDefault($di);