mvc: style sweep, plist

This commit is contained in:
Franco Fichtner 2024-05-13 10:42:29 +02:00
parent 0a239dd688
commit 38dad806fb
11 changed files with 50 additions and 33 deletions

16
plist
View File

@ -213,8 +213,6 @@
/usr/local/opnsense/mvc/app/config/AppConfig.php
/usr/local/opnsense/mvc/app/config/config.php
/usr/local/opnsense/mvc/app/config/loader.php
/usr/local/opnsense/mvc/app/config/services.php
/usr/local/opnsense/mvc/app/config/services_api.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Base/ApiControllerBase.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableModelControllerBase.php
/usr/local/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableServiceControllerBase.php
@ -512,7 +510,6 @@
/usr/local/opnsense/mvc/app/library/OPNsense/Core/ConfigException.php
/usr/local/opnsense/mvc/app/library/OPNsense/Core/File.php
/usr/local/opnsense/mvc/app/library/OPNsense/Core/FileObject.php
/usr/local/opnsense/mvc/app/library/OPNsense/Core/Routing.php
/usr/local/opnsense/mvc/app/library/OPNsense/Core/SanitizeFilter.php
/usr/local/opnsense/mvc/app/library/OPNsense/Core/Shell.php
/usr/local/opnsense/mvc/app/library/OPNsense/Core/Singleton.php
@ -526,6 +523,19 @@
/usr/local/opnsense/mvc/app/library/OPNsense/Firewall/SNatRule.php
/usr/local/opnsense/mvc/app/library/OPNsense/Firewall/Util.php
/usr/local/opnsense/mvc/app/library/OPNsense/Interface/Autoconf.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Controller.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Dispatcher.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Exceptions/ClassNotFoundException.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Exceptions/DispatchException.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Exceptions/InvalidUriException.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Exceptions/MethodNotFoundException.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Exceptions/ParameterMismatchException.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Headers.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Request.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Response.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Router.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Security.php
/usr/local/opnsense/mvc/app/library/OPNsense/Mvc/Session.php
/usr/local/opnsense/mvc/app/library/OPNsense/OpenVPN/ArchiveOpenVPN.php
/usr/local/opnsense/mvc/app/library/OPNsense/OpenVPN/BaseExporter.php
/usr/local/opnsense/mvc/app/library/OPNsense/OpenVPN/ExportFactory.php

View File

@ -67,8 +67,7 @@ abstract class Controller
$volt->getCompiler()->addFunction('cache_safe', 'view_cache_safe');
$volt->getCompiler()->addFilter('safe', 'view_html_safe');
return $volt;
}]
);
}]);
}
/**
@ -84,5 +83,7 @@ abstract class Controller
$this->response->setContent($this->view->getContent());
}
public function initialize(){}
public function initialize()
{
}
}

View File

@ -36,7 +36,6 @@ use OPNsense\Mvc\Exceptions\ClassNotFoundException;
use OPNsense\Mvc\Exceptions\MethodNotFoundException;
use OPNsense\Mvc\Exceptions\ParameterMismatchException;
class Dispatcher
{
private string $namespace;
@ -117,12 +116,12 @@ class Dispatcher
* test if controller action method is callable with the parameters provided
* @return bool
*/
public function canExecute() : bool
public function canExecute(): bool
{
try {
$this->resolve();
return true;
} catch(Exception){
} catch (Exception) {
return false;
}
}
@ -138,7 +137,7 @@ class Dispatcher
* @throws ParameterMismatchException when expected required parameters do not match offered ones
* @throws ReflectionException when invoke fails
*/
public function dispatch(Request $request, Response $response, Session $session) : bool
public function dispatch(Request $request, Response $response, Session $session): bool
{
$this->resolve();

View File

@ -27,5 +27,6 @@
*/
namespace OPNsense\Mvc\Exceptions;
class ClassNotFoundException extends DispatchException{}
class ClassNotFoundException extends DispatchException
{
}

View File

@ -29,5 +29,6 @@ namespace OPNsense\Mvc\Exceptions;
use Exception;
class DispatchException extends Exception{}
class DispatchException extends Exception
{
}

View File

@ -27,5 +27,6 @@
*/
namespace OPNsense\Mvc\Exceptions;
class InvalidUriException extends DispatchException{}
class InvalidUriException extends DispatchException
{
}

View File

@ -27,4 +27,6 @@
*/
namespace OPNsense\Mvc\Exceptions;
class MethodNotFoundException extends DispatchException{}
class MethodNotFoundException extends DispatchException
{
}

View File

@ -27,4 +27,6 @@
*/
namespace OPNsense\Mvc\Exceptions;
class ParameterMismatchException extends DispatchException{}
class ParameterMismatchException extends DispatchException
{
}

View File

@ -64,14 +64,14 @@ class Router
$appconfig = new AppConfig();
foreach ((array)$appconfig->application->controllersDir as $controllersDir) {
// sort OPNsense namespace on top
$dirs = glob($controllersDir. "/*", GLOB_ONLYDIR);
usort($dirs, function($a, $b){
$dirs = glob($controllersDir . "/*", GLOB_ONLYDIR);
usort($dirs, function ($a, $b) {
if (basename($b) == 'OPNsense') {
return 1;
} else {
return strcmp(strtolower($a), strtolower($b));
}
}) ;
});
foreach ($dirs as $dirname) {
$basename = basename($dirname);
$new_namespace = "$basename\\$namespace";
@ -100,7 +100,7 @@ class Router
* @throws InvalidUriException
* @throws ReflectionException when invoke fails
*/
public function routeRequest(string $uri, array $defaults = []) : Response
public function routeRequest(string $uri, array $defaults = []): Response
{
$path = parse_url($uri)['path'];
@ -134,7 +134,7 @@ class Router
* @throws ParameterMismatchException
* @throws ReflectionException when invoke fails
*/
private function performRequest(Dispatcher $dispatcher) : Response
private function performRequest(Dispatcher $dispatcher): Response
{
$session = new Session();
$request = new Request();
@ -150,7 +150,8 @@ class Router
* @param array $default list of routing defaults (controller, acount)
* @return array containing expected controller action
*/
private function parsePath(string $path, array $defaults) : array {
private function parsePath(string $path, array $defaults): array
{
$pathElements = explode("/", rtrim($path, '/'));
$result = [
"namespace" => null,
@ -162,13 +163,13 @@ class Router
$result[$key] = $val;
}
foreach($pathElements as $idx => $element){
foreach ($pathElements as $idx => $element) {
if ($idx == 0) {
$result["namespace"] = str_replace('_', '', ucwords($element,'_'));
$result["namespace"] = str_replace('_', '', ucwords($element, '_'));
} elseif ($idx == 1) {
$result["controller"] = str_replace('_', '', ucwords($element,'_')) . 'Controller';
$result["controller"] = str_replace('_', '', ucwords($element, '_')) . 'Controller';
} elseif ($idx == 2) {
$result["action"] = lcfirst(str_replace('_', '', ucwords($element,'_'))) . "Action";
$result["action"] = lcfirst(str_replace('_', '', ucwords($element, '_'))) . "Action";
} else {
$result["parameters"][] = $element;
}

View File

@ -28,7 +28,6 @@
namespace OPNsense\Mvc;
class Security
{
private Session $session;
@ -57,7 +56,7 @@ class Security
* @param bool $new when not found, create new
* @return string|null token
*/
public function getToken(bool $new=true): ?string
public function getToken(bool $new = true): ?string
{
$token = $this->session->get('$PHALCON/CSRF$');
if (empty($token) && $new) {
@ -71,7 +70,7 @@ class Security
* @param bool $new when not found, create new
* @return string|null name of the token
*/
public function getTokenKey(bool $new=true): ?string
public function getTokenKey(bool $new = true): ?string
{
$token = $this->session->get('$PHALCON/CSRF/KEY$');
if (empty($token) && $new) {

View File

@ -1,9 +1,9 @@
<?php
function error_output($http_code, $e, $user_message)
function error_output($http_code, $e, $user_message)
{
$response = [];
if (!file_exists('/var/run/development')){
if (!file_exists('/var/run/development')) {
$response['errorMessage'] = $user_message;
} else {
$response['errorMessage'] = $e->getMessage();