Phalcon5 migration: provide compatibility layer between v4 and v5 (#5711)

* phalcon5: update namespaces

* phalcon5 Autoload: rename registerDirs() to setDirectories()

* phalcon5: remove trailing slash

* phalcon5: default to php74-phalcon

* phalcon5: provide 4/5 compatibility layer except for AbstractValidator

* MVC - Phalcon 5 migration and options to lose dependency of phalcon validation classes.

Since Validation() in 5 moves to Filter\Validation (https://docs.phalcon.io/5.0/en/upgrade#general-notes) and the class is used in strict parameter passing,
it will be difficult to import a situation which works both on 4 and 5.

To prevent future issues, but keep the current situation functional with minimal changes, we wrapped Validation() into a class of our own. When validators inherit from BaseValidator, these are assumed to
be less strict and bound to our own handling. Phalcon validations will follow the old path for now.

Migrating existing validations on our end, should be as simple as changing the following lines:

-use Phalcon\Validation\AbstractValidator;
-use Phalcon\Validation\ValidatorInterface;
-use Phalcon\Validation;
+use OPNsense\Base\BaseValidator;

-class CallbackValidator extends AbstractValidator implements ValidatorInterface
+class CallbackValidator extends BaseValidator

-    public function validate(Validation $validator, $attribute): bool
+    public function validate($validator, $attribute): bool

Todo: choose the "correct" Validation() based on phalcon version.

* phalcon5: complete migration to compatibility layer.

uses bc881b9c11 to remove the need
for AbstractValidator and Validator(Interface).

This commit changes the relevant includes and provides some changes to make the unit tests
run correctly.

* MVC - Phalcon 5 migration and options to lose dependency of phalcon validation classes. part duex

Although our previous strategy should work according to how bind() and validation() are being implemented (https://github.com/phalcon/cphalcon/blob/4.2.x/phalcon/Validation.zep),
in reality it seems they aren't the same. Our previous attempt failed some validations (such as booleans) for no valid reasons.

Long term we should remove the phalcon dependency as these effects are highly unpredictable.

phalcon5: update Validation class to now pick the right Phalcon Validation based on version

* MVC - Phalcon 5 migration and options to lose dependency of phalcon validation classes.

Minor regression in previous commit, performValidation()'s return type didn't match. Ideally we would rather switch to plain array's, but since performValidation()
is used in multiple areas (including plugins) we better opt for compatiblity now.

ref  https://github.com/opnsense/core/pull/5711

* phalcon5: switch back to using count() on Messages object, adjust unit tests as needed

See 6814f32755 as to why
this is the case.

* phalcon5: remove PhalconGenerator and references, use checked-in files instead

* Update Makefile

Co-authored-by: Franco Fichtner <franco@opnsense.org>

Co-authored-by: Ad Schellevis <ad@opnsense.org>
Co-authored-by: Franco Fichtner <franco@opnsense.org>
This commit is contained in:
Stephan de Wit 2022-04-20 10:05:26 +02:00 committed by GitHub
parent d236c7a1b9
commit cfd4b7635f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
91 changed files with 469 additions and 221 deletions

View File

@ -130,9 +130,8 @@ CORE_DEPENDS_amd64?= beep \
suricata-devel
# transition helpers for PHP 8/Phalcon 5 migration
CORE_DEPENDS_PHP74= php74-json php74-openssl php74-phalcon${CORE_PHALCON}
CORE_DEPENDS_PHP74= php74-json php74-openssl php74-phalcon
CORE_DEPENDS_PHP80= php80-phalcon
CORE_PHALCON?= 4
CORE_DEPENDS?= ca_root_nss \
choparp \

View File

@ -1,6 +1,10 @@
<?php
return new \Phalcon\Config(array(
/* Autoloader doesn't exist yet */
include('/usr/local/opnsense/mvc/app/library/OPNsense/Phalcon/Config/Config.php');
include('/usr/local/opnsense/mvc/app/library/OPNsense/Phalcon/Autoload/Loader.php');
return new OPNsense\Phalcon\Config\Config(array(
'application' => array(
'controllersDir' => __DIR__ . '/../../app/controllers/',
'modelsDir' => __DIR__ . '/../../app/models/',
@ -17,3 +21,4 @@ return new \Phalcon\Config(array(
'simulate_mode' => false
)
));

View File

@ -1,11 +1,11 @@
<?php
$loader = new \Phalcon\Loader();
$loader = new OPNsense\Phalcon\Autoload\Loader();
/**
* We're a registering a set of directories taken from the configuration file
*/
$loader->registerDirs(
$loader->setDirectories(
array(
$config->application->controllersDir,
$config->application->modelsDir,

View File

@ -1,6 +1,6 @@
<?php
use Phalcon\DI\FactoryDefault;
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;

View File

@ -27,10 +27,9 @@
*/
// Service definition for API
use Phalcon\DI\FactoryDefault;
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
use Phalcon\Session\Manager;
use Phalcon\Session\Adapter\Stream;
use OPNsense\Core\Config;

View File

@ -184,7 +184,7 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
* @param string $node reference node, to use as relative offset
* @param string $prefix prefix to use when $node is provided (defaults to static::$internalModelName)
* @return array result / validation output
* @throws \Phalcon\Validation\Exception on validation issues
* @throws \Phalcon\Filter\Validation\Exception on validation issues
* @throws \ReflectionException when binding to the model class fails
* @throws UserException when denied write access
*/
@ -246,7 +246,7 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
/**
* Save model after update or insertion, validate() first to avoid raising exceptions
* @return array result / validation output
* @throws \Phalcon\Validation\Exception on validation issues
* @throws \Phalcon\Filter\Validation\Exception on validation issues
* @throws \ReflectionException when binding to the model class fails
* @throws \OPNsense\Base\UserException when denied write access
*/
@ -278,7 +278,7 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
/**
* Update model settings
* @return array status / validation errors
* @throws \Phalcon\Validation\Exception on validation issues
* @throws \Phalcon\Filter\Validation\Exception on validation issues
* @throws \ReflectionException when binding to the model class fails
* @throws UserException when denied write access
*/
@ -362,7 +362,7 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
* @param string $path relative model path
* @param array|null $overlay properties to overlay when available (call setNodes)
* @return array
* @throws \Phalcon\Validation\Exception on validation issues
* @throws \Phalcon\Filter\Validation\Exception on validation issues
* @throws \ReflectionException when binding to the model class fails
* @throws UserException when denied write access
*/
@ -401,7 +401,7 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
* @param string $path relative model path
* @param null|string $uuid node key
* @return array
* @throws \Phalcon\Validation\Exception on validation issues
* @throws \Phalcon\Filter\Validation\Exception on validation issues
* @throws \ReflectionException when binding to the model class fails
* @throws UserException when denied write access
*/
@ -436,7 +436,7 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
* @param string $uuid node key
* @param array|null $overlay properties to overlay when available (call setNodes)
* @return array
* @throws \Phalcon\Validation\Exception on validation issues
* @throws \Phalcon\Filter\Validation\Exception on validation issues
* @throws \ReflectionException when binding to the model class fails
* @throws UserException when denied write access
*/
@ -472,7 +472,7 @@ abstract class ApiMutableModelControllerBase extends ApiControllerBase
* @param string $uuid node key
* @param string $enabled desired state enabled(1)/disabled(0), leave empty for toggle
* @return array
* @throws \Phalcon\Validation\Exception on validation issues
* @throws \Phalcon\Filter\Validation\Exception on validation issues
* @throws \ReflectionException when binding to the model class fails
* @throws UserException when denied write access
*/

View File

@ -30,7 +30,7 @@ namespace OPNsense\Base;
use OPNsense\Core\Config;
use Phalcon\Mvc\Controller;
use Phalcon\Logger;
use OPNsense\Phalcon\Logger\Logger;
use Phalcon\Logger\Adapter\Syslog;
use Phalcon\Translate\InterpolatorFactory;
use OPNsense\Core\ACL;

View File

@ -351,7 +351,7 @@ class FirmwareController extends ApiControllerBase
$this->sessionClose(); // long running action, close session
$filter = new \Phalcon\Filter([
$filter = new \OPNsense\Phalcon\Filter\Filter([
'version' => function ($value) {
return preg_replace('/[^0-9a-zA-Z\.]/', '', $value);
}
@ -383,7 +383,7 @@ class FirmwareController extends ApiControllerBase
if ($this->request->isPost()) {
// sanitize package name
$filter = new \Phalcon\Filter([
$filter = new \OPNsense\Phalcon\Filter\Filter([
'scrub' => function ($value) {
return preg_replace('/[^0-9a-zA-Z._-]/', '', $value);
}
@ -554,7 +554,7 @@ class FirmwareController extends ApiControllerBase
if ($this->request->isPost()) {
$response['status'] = 'ok';
// sanitize package name
$filter = new \Phalcon\Filter([
$filter = new \OPNsense\Phalcon\Filter\Filter([
'pkgname' => function ($value) {
return preg_replace('/[^0-9a-zA-Z._-]/', '', $value);
}
@ -624,7 +624,7 @@ class FirmwareController extends ApiControllerBase
if ($this->request->isPost()) {
$response['status'] = 'ok';
// sanitize package name
$filter = new \Phalcon\Filter([
$filter = new \OPNsense\Phalcon\Filter\Filter([
'pkgname' => function ($value) {
return preg_replace('/[^0-9a-zA-Z._-]/', '', $value);
}
@ -654,7 +654,7 @@ class FirmwareController extends ApiControllerBase
if ($this->request->isPost()) {
$response['status'] = 'ok';
// sanitize package name
$filter = new \Phalcon\Filter([
$filter = new \OPNsense\Phalcon\Filter\Filter([
'pkgname' => function ($value) {
return preg_replace('/[^0-9a-zA-Z._-]/', '', $value);
}
@ -682,7 +682,7 @@ class FirmwareController extends ApiControllerBase
$response = array();
if ($this->request->isPost()) {
$filter = new \Phalcon\Filter([
$filter = new \OPNsense\Phalcon\Filter\Filter([
'pkgname' => function ($value) {
return preg_replace('/[^0-9a-zA-Z._-]/', '', $value);
}
@ -715,7 +715,7 @@ class FirmwareController extends ApiControllerBase
$response = array();
if ($this->request->isPost()) {
$filter = new \Phalcon\Filter([
$filter = new \OPNsense\Phalcon\Filter\Filter([
'pkgname' => function ($value) {
return preg_replace('/[^0-9a-zA-Z._-]/', '', $value);
}
@ -786,7 +786,7 @@ class FirmwareController extends ApiControllerBase
if ($this->request->isPost()) {
// sanitize package name
$filter = new \Phalcon\Filter([
$filter = new \OPNsense\Phalcon\Filter\Filter([
'scrub' => function ($value) {
return preg_replace('/[^0-9a-zA-Z._-]/', '', $value);
}

View File

@ -103,7 +103,7 @@ class SettingsController extends ApiMutableModelControllerBase
* add new job and set with attributes from post
* @return array save result + validation output
* @throws \OPNsense\Base\ModelException when not bound to model
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException
*/
public function addJobAction()
@ -116,7 +116,7 @@ class SettingsController extends ApiMutableModelControllerBase
* delete job by uuid ( only if origin is cron)
* @param string $uuid item unique id
* @return array status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
* @throws \OPNsense\Base\ModelException when not bound to model
*/
@ -136,7 +136,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $uuid item unique id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function toggleJobAction($uuid, $enabled = null)

View File

@ -28,7 +28,7 @@
namespace OPNsense\Diagnostics\Api;
use Phalcon\Filter;
use OPNsense\Phalcon\Filter\Filter;
use OPNsense\Base\ApiControllerBase;
use OPNsense\Core\Backend;
use OPNsense\Core\Config;

View File

@ -30,7 +30,7 @@ namespace OPNsense\Diagnostics\Api;
use OPNsense\Base\ApiControllerBase;
use OPNsense\Core\Backend;
use Phalcon\Filter;
use OPNsense\Phalcon\Filter\Filter;
/**
* @inherit

View File

@ -74,7 +74,7 @@ class NetflowController extends ApiControllerBase
/**
* update netflow configuration fields
* @return array
* @throws \Phalcon\Validation\Exception
* @throws \Phalcon\Filter\Validation\Exception
*/
public function setconfigAction()
{

View File

@ -69,7 +69,7 @@ class AliasController extends ApiMutableModelControllerBase
* Update alias with given properties
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setItemAction($uuid)
@ -90,7 +90,7 @@ class AliasController extends ApiMutableModelControllerBase
* Add new alias and set with attributes from post
* @return array save result + validation output
* @throws \OPNsense\Base\ModelException when not bound to model
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function addItemAction()
@ -141,7 +141,7 @@ class AliasController extends ApiMutableModelControllerBase
* Delete alias by uuid, save contents to tmp for removal on apply
* @param string $uuid internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
* @throws \OPNsense\Base\UserException when unable to delete
*/
@ -168,7 +168,7 @@ class AliasController extends ApiMutableModelControllerBase
* @param string $uuid id to toggled
* @param string|null $enabled set enabled by default
* @return array status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function toggleItemAction($uuid, $enabled = null)

View File

@ -69,7 +69,7 @@ class CategoryController extends ApiMutableModelControllerBase
* Update category with given properties
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setItemAction($uuid)
@ -90,7 +90,7 @@ class CategoryController extends ApiMutableModelControllerBase
* Add new category and set with attributes from post
* @return array save result + validation output
* @throws \OPNsense\Base\ModelException when not bound to model
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function addItemAction()
@ -113,7 +113,7 @@ class CategoryController extends ApiMutableModelControllerBase
* Delete alias by uuid, save contents to tmp for removal on apply
* @param string $uuid internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
* @throws \OPNsense\Base\UserException when unable to delete
*/

View File

@ -33,7 +33,7 @@ use OPNsense\Core\Backend;
use OPNsense\Core\Config;
use OPNsense\Cron\Cron;
use OPNsense\IDS\IDS;
use Phalcon\Filter;
use OPNsense\Phalcon\Filter\Filter;
use Phalcon\Filter\FilterFactory;
/**
@ -52,7 +52,7 @@ class ServiceController extends ApiMutableServiceControllerBase
* @return array result status
* @throws \Exception when configd action fails
* @throws \OPNsense\Base\ModelException when unable to construct model
* @throws \Phalcon\Validation\Exception when one or more model validations fail
* @throws \Phalcon\Filter\Validation\Exception when one or more model validations fail
*/
public function reconfigureAction()
{

View File

@ -298,7 +298,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Update ruleset properties
* @return array result status
* @throws \Exception when config action fails
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setRulesetpropertiesAction()
@ -387,7 +387,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $filename rule filename (key)
* @return array result status
* @throws \Exception when configd action fails
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setRulesetAction($filename)
@ -424,7 +424,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array status 0/1 or error
* @throws \Exception
* @throws \Phalcon\Validation\Exception
* @throws \Phalcon\Filter\Validation\Exception
*/
public function toggleRulesetAction($filenames, $enabled = null)
{
@ -467,7 +467,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param string|int $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array empty
* @throws \Exception when configd action fails
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function toggleRuleAction($sids, $enabled = null)
@ -522,7 +522,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $sid item unique id
* @return array result status
* @throws \Exception when configd action fails
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setRuleAction($sid)
@ -563,7 +563,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Update user defined rules
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setUserRuleAction($uuid)
@ -574,7 +574,7 @@ class SettingsController extends ApiMutableModelControllerBase
/**
* Add new user defined rule
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function addUserRuleAction()
@ -597,7 +597,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Delete user rule item
* @param string $uuid user rule internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function delUserRuleAction($uuid)
@ -610,7 +610,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $uuid user defined rule internal id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array save result
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function toggleUserRuleAction($uuid, $enabled = null)
@ -632,7 +632,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Update policy
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setPolicyAction($uuid)
@ -643,7 +643,7 @@ class SettingsController extends ApiMutableModelControllerBase
/**
* Add new policy
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function addPolicyAction()
@ -666,7 +666,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Delete policy item
* @param string $uuid user rule internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function delPolicyAction($uuid)
@ -679,7 +679,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $uuid user defined rule internal id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array save result
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function togglePolicyAction($uuid, $enabled = null)
@ -701,7 +701,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Update policy rule adjustment
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setPolicyRuleAction($uuid)
@ -712,7 +712,7 @@ class SettingsController extends ApiMutableModelControllerBase
/**
* Add new policy rule adjustment
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function addPolicyRuleAction()
@ -735,7 +735,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Delete policy rule adjustment item
* @param string $uuid internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function delPolicyRuleAction($uuid)
@ -748,7 +748,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $uuid user internal id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array save result
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function togglePolicyRuleAction($uuid, $enabled = null)

View File

@ -69,7 +69,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Update alert with given properties
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setAlertAction($uuid)
@ -80,7 +80,7 @@ class SettingsController extends ApiMutableModelControllerBase
/**
* Add alert with given properties
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function addAlertAction()
@ -92,7 +92,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Delete alert by uuid
* @param string $uuid internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function delAlertAction($uuid)
@ -119,7 +119,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $uuid alert internal id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array save result
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function toggleAlertAction($uuid, $enabled = null)
@ -142,7 +142,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Update service with given properties
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setServiceAction($uuid)
@ -153,7 +153,7 @@ class SettingsController extends ApiMutableModelControllerBase
/**
* Add service with given properties
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function addServiceAction()
@ -165,7 +165,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Delete service by uuid
* @param string $uuid internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function delServiceAction($uuid)
@ -188,7 +188,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $uuid service internal id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array save result
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function toggleServiceAction($uuid, $enabled = null)
@ -211,7 +211,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Update test with given properties
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setTestAction($uuid)
@ -222,7 +222,7 @@ class SettingsController extends ApiMutableModelControllerBase
/**
* Add test with given properties
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function addTestAction()
@ -234,7 +234,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Delete test by uuid
* @param string $uuid internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function delTestAction($uuid)

View File

@ -74,7 +74,7 @@ class SettingsController extends ApiMutableModelControllerBase
* update remote blacklist item
* @param string $uuid
* @return array result status
* @throws \Phalcon\Validation\Exception
* @throws \Phalcon\Filter\Validation\Exception
*/
public function setRemoteBlacklistAction($uuid)
{
@ -182,7 +182,7 @@ class SettingsController extends ApiMutableModelControllerBase
* update PAC Rule
* @param string $uuid
* @return array result status
* @throws \Phalcon\Validation\Exception
* @throws \Phalcon\Filter\Validation\Exception
*/
public function setPACRuleAction($uuid)
{
@ -246,7 +246,7 @@ class SettingsController extends ApiMutableModelControllerBase
* update PAC Proxy
* @param string $uuid
* @return array result status
* @throws \Phalcon\Validation\Exception
* @throws \Phalcon\Filter\Validation\Exception
*/
public function setPACProxyAction($uuid)
{
@ -299,7 +299,7 @@ class SettingsController extends ApiMutableModelControllerBase
* update PAC Rule
* @param string $uuid
* @return array result status
* @throws \Phalcon\Validation\Exception
* @throws \Phalcon\Filter\Validation\Exception
*/
public function setPACMatchAction($uuid)
{

View File

@ -43,7 +43,7 @@ class TemplateController extends ApiMutableModelControllerBase
/**
* save template
* @return array status
* @throws \Phalcon\Validation\Exception on validation issues
* @throws \Phalcon\Filter\Validation\Exception on validation issues
* @throws \ReflectionException when binding to the model class fails
* @throws UserException when denied write access
*/

View File

@ -60,7 +60,7 @@ class RoutesController extends ApiMutableModelControllerBase
* Update route with given properties
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setrouteAction($uuid)
@ -80,7 +80,7 @@ class RoutesController extends ApiMutableModelControllerBase
* Add new route and set with attributes from post
* @return array save result + validation output
* @throws \OPNsense\Base\ModelException when not bound to model
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException
*/
public function addrouteAction()
@ -103,7 +103,7 @@ class RoutesController extends ApiMutableModelControllerBase
* Delete route by uuid, save contents to tmp for removal on apply
* @param string $uuid internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
* @throws \OPNsense\Base\ModelException when not bound to model
*/
@ -123,7 +123,7 @@ class RoutesController extends ApiMutableModelControllerBase
* @param string $uuid id to toggled
* @param string|null $disabled set disabled by default
* @return array status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
* @throws \OPNsense\Base\ModelException when not bound to model
*/

View File

@ -28,7 +28,7 @@
namespace OPNsense\Syslog\Api;
use Phalcon\Filter;
use OPNsense\Phalcon\Filter\Filter;
use OPNsense\Base\ApiMutableModelControllerBase;
use OPNsense\Core\Backend;
use OPNsense\Core\Config;
@ -72,7 +72,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Update destination with given properties
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setDestinationAction($uuid)
@ -84,7 +84,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Add new destination and set with attributes from post
* @return array save result + validation output
* @throws \OPNsense\Base\ModelException when not bound to model
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
*/
public function addDestinationAction()
{
@ -94,7 +94,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Delete destination by uuid
* @param string $uuid internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function delDestinationAction($uuid)
@ -107,7 +107,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $uuid user defined rule internal id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array save result
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function toggleDestinationAction($uuid, $enabled = null)

View File

@ -59,7 +59,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Update pipe with given properties
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setPipeAction($uuid)
@ -71,7 +71,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Add new pipe and set with attributes from post
* @return array save result + validation output
* @throws \OPNsense\Base\ModelException when not bound to model
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
*/
public function addPipeAction()
{
@ -85,7 +85,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Delete pipe by uuid
* @param string $uuid internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function delPipeAction($uuid)
@ -99,7 +99,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $uuid user defined rule internal id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array save result
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function togglePipeAction($uuid, $enabled = null)
@ -151,7 +151,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Update queue with given properties
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setQueueAction($uuid)
@ -175,7 +175,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Delete queue by uuid
* @param string $uuid internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function delQueueAction($uuid)
@ -188,7 +188,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $uuid user defined rule internal id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array save result
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function toggleQueueAction($uuid, $enabled = null)
@ -232,7 +232,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Update rule with given properties
* @param string $uuid internal id
* @return array save result + validation output
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function setRuleAction($uuid)
@ -244,7 +244,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Add new rule and set with attributes from post
* @return array save result + validation output
* @throws \OPNsense\Base\ModelException when not bound to model
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
*/
public function addRuleAction()
{
@ -254,7 +254,7 @@ class SettingsController extends ApiMutableModelControllerBase
* Delete rule by uuid
* @param string $uuid internal id
* @return array save status
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function delRuleAction($uuid)
@ -267,7 +267,7 @@ class SettingsController extends ApiMutableModelControllerBase
* @param $uuid user defined rule internal id
* @param $enabled desired state enabled(1)/disabled(1), leave empty for toggle
* @return array save result
* @throws \Phalcon\Validation\Exception when field validations fail
* @throws \Phalcon\Filter\Validation\Exception when field validations fail
* @throws \ReflectionException when not bound to model
*/
public function toggleRuleAction($uuid, $enabled = null)

View File

@ -28,7 +28,7 @@
namespace OPNsense\Core;
use Phalcon\Logger;
use OPNsense\Phalcon\Logger\Logger;
use Phalcon\Logger\Adapter\Syslog;
use Phalcon\Logger\Formatter\Line;

View File

@ -28,8 +28,8 @@
namespace OPNsense\Core;
use Phalcon\DI\FactoryDefault;
use Phalcon\Logger;
use Phalcon\Di\FactoryDefault;
use OPNsense\Phalcon\Logger\Logger;
use Phalcon\Logger\Adapter\Syslog;
/**

View File

@ -28,7 +28,7 @@
namespace OPNsense\Core;
use Phalcon\DI\FactoryDefault;
use Phalcon\Di\FactoryDefault;
/**
* Class Shell shell/command handling routines

View File

@ -0,0 +1,26 @@
<?php
namespace OPNsense\Phalcon\Autoload;
use Phalcon\Autoload\Loader as PhalconLoader;
use Phalcon\Loader as PhalconLoader4;
if (class_exists("Phalcon\Autoload\Loader", false)) {
class LoaderWrapper extends PhalconLoader {}
} else {
class LoaderWrapper extends PhalconLoader4 {}
}
class Loader extends LoaderWrapper
{
public function __call($fName, $args) {
if (method_exists($this, $fName)) {
return $this->fName(...$args);
} elseif ($fName == 'setDirectories') {
/* Phalcon5 renamed registerDirs to setDirectories */
return $this->registerDirs(...$args);
}
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace OPNsense\Phalcon\Config;
use Phalcon\Config\Config as PhalconConfig;
use Phalcon\Config as PhalconConfig4;
if (class_exists("Phalcon\Config\Config", false)) {
class ConfigWrapper extends PhalconConfig {}
} else {
class ConfigWrapper extends PhalconConfig4 {}
}
class Config extends ConfigWrapper
{
}

View File

@ -0,0 +1,17 @@
<?php
namespace OPNsense\Phalcon\Di;
use Phalcon\Di\Di as PhalconDi;
use Phalcon\Di as PhalconDi4;
if (class_exists("Phalcon\Di\Di", false)) {
class DiWrapper extends PhalconDi {}
} else {
class DiWrapper extends PhalconDi4 {}
}
class Di extends DiWrapper
{
}

View File

@ -0,0 +1,17 @@
<?php
namespace OPNsense\Phalcon\Encryption\Security;
use Phalcon\Encryption\Security\Random as PhalconRandom;
use Phalcon\Security\Random as PhalconRandom4;
if (class_exists("Phalcon\Encryption\Security\Random", false)) {
class RandomWrapper extends PhalconRandom {}
} else {
class RandomWrapper extends PhalconRandom4 {}
}
class Random extends RandomWrapper
{
}

View File

@ -0,0 +1,17 @@
<?php
namespace OPNsense\Phalcon\Filter;
use Phalcon\Filter\Filter as PhalconFilter;
use Phalcon\Filter as PhalconFilter4;
if (class_exists("Phalcon\Filter\Filter", false)) {
class FilterWrapper extends PhalconFilter {}
} else {
class FilterWrapper extends PhalconFilter4 {}
}
class Filter extends FilterWrapper
{
}

View File

@ -0,0 +1,17 @@
<?php
namespace OPNsense\Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Exception as PhalconException;
use Phalcon\Validation\Exception as PhalconException4;
if (class_exists("Phalcon\Filter\Validation\Exception", false)) {
class ExceptionWrapper extends PhalconException {}
} else {
class ExceptionWrapper extends PhalconException4 {}
}
class Exception extends ExceptionWrapper
{
}

View File

@ -0,0 +1,17 @@
<?php
namespace OPNsense\Phalcon\Filter\Validation\Validator;
use Phalcon\Filter\Validation\Validator\Email as PhalconEmail;
use Phalcon\Validation\Validator\Email as PhalconEmail4;
if (class_exists("Phalcon\Filter\Validation\Validator\Email", false)) {
class EmailWrapper extends PhalconEmail {}
} else {
class EmailWrapper extends PhalconEmail4 {}
}
class Email extends EmailWrapper
{
}

View File

@ -0,0 +1,17 @@
<?php
namespace OPNsense\Phalcon\Filter\Validation\Validator;
use Phalcon\Filter\Validation\Validator\ExclusionIn as PhalconExclusionIn;
use Phalcon\Validation\Validator\ExclusionIn as PhalconExclusionIn4;
if (class_exists("Phalcon\Filter\Validation\Validator\ExclusionIn", false)) {
class ExclusionInWrapper extends PhalconExclusionIn {}
} else {
class ExclusionInWrapper extends PhalconExclusionIn4 {}
}
class ExclusionIn extends ExclusionInWrapper
{
}

View File

@ -0,0 +1,17 @@
<?php
namespace OPNsense\Phalcon\Filter\Validation\Validator;
use Phalcon\Filter\Validation\Validator\InclusionIn as PhalconInclusionIn;
use Phalcon\Validation\Validator\InclusionIn as PhalconInclusionIn4;
if (class_exists("Phalcon\Filter\Validation\Validator\InclusionIn", false)) {
class InclusionInWrapper extends PhalconInclusionIn {}
} else {
class InclusionInWrapper extends PhalconInclusionIn4 {}
}
class InclusionIn extends InclusionInWrapper
{
}

View File

@ -0,0 +1,17 @@
<?php
namespace OPNsense\Phalcon\Filter\Validation\Validator;
use Phalcon\Filter\Validation\Validator\Numericality as PhalconNumericality;
use Phalcon\Validation\Validator\Numericality as PhalconNumericality4;
if (class_exists("Phalcon\Filter\Validation\Validator\Numericality", false)) {
class NumericalityWrapper extends PhalconNumericality {}
} else {
class NumericalityWrapper extends PhalconNumericality4 {}
}
class Numericality extends NumericalityWrapper
{
}

View File

@ -0,0 +1,17 @@
<?php
namespace OPNsense\Phalcon\Filter\Validation\Validator;
use Phalcon\Filter\Validation\Validator\PresenceOf as PhalconPresenceOf;
use Phalcon\Validation\Validator\PresenceOf as PhalconPresenceOf4;
if (class_exists("Phalcon\Filter\Validation\Validator\PresenceOf", false)) {
class PresenceOfWrapper extends PhalconPresenceOf {}
} else {
class PresenceOfWrapper extends PhalconPresenceOf4 {}
}
class PresenceOf extends PresenceOfWrapper
{
}

View File

@ -0,0 +1,17 @@
<?php
namespace OPNsense\Phalcon\Filter\Validation\Validator;
use Phalcon\Filter\Validation\Validator\Regex as PhalconRegex;
use Phalcon\Validation\Validator\Regex as PhalconRegex4;
if (class_exists("Phalcon\Filter\Validation\Validator\Regex", false)) {
class RegexWrapper extends PhalconRegex {}
} else {
class RegexWrapper extends PhalconRegex4 {}
}
class Regex extends RegexWrapper
{
}

View File

@ -0,0 +1,17 @@
<?php
namespace OPNsense\Phalcon\Logger;
use Phalcon\Logger\Logger as PhalconLogger;
use Phalcon\Logger as PhalconLogger4;
if (class_exists("Phalcon\Logger\Logger", false)) {
class LoggerWrapper extends PhalconLogger {}
} else {
class LoggerWrapper extends PhalconLogger4 {}
}
class Logger extends LoggerWrapper
{
}

View File

@ -29,9 +29,10 @@
namespace OPNsense\Base;
use Exception;
use http\Message;
use OPNsense\Base\FieldTypes\ContainerField;
use OPNsense\Core\Config;
use Phalcon\Logger;
use OPNsense\Phalcon\Logger\Logger;
use Phalcon\Logger\Adapter\Syslog;
use Phalcon\Messages\Messages;
use ReflectionClass;
@ -425,8 +426,8 @@ abstract class BaseModel
*/
public function performValidation($validateFullModel = false)
{
// create a Phalcon validator and collect all model validations
$validation = new Validation();
// create a wrapped validator and collect all model validations.
$validation = new \OPNsense\Base\Validation();
$validation_data = array();
$all_nodes = $this->internalData->getFlatNodes();
@ -570,7 +571,7 @@ abstract class BaseModel
$logger->error($exception_msg_part);
}
if (!$disable_validation) {
throw new Phalcon\Validation\Exception($exception_msg);
throw new \OPNsense\Phalcon\Filter\Validation\Exception($exception_msg);
}
}
$this->internalSerializeToConfig();

View File

@ -31,15 +31,25 @@ namespace OPNsense\Base;
abstract class BaseValidator
{
private $options = [];
public function __construct($options)
public function __construct($options = [])
{
$this->options = $options;
}
public function getOption($option, $default = null)
{
return isset($this->options[$option]) ? $this->options[$option] : $default;
}
/**
* Only used by tests
*/
public function setOption($key, $value)
{
$this->options[$key] = $value;
}
abstract public function validate($validator, $attribute): bool;
}

View File

@ -39,11 +39,11 @@ class AllOrNoneConstraint extends BaseConstraint
/**
* Executes validation
*
* @param \Phalcon\Validation $validator
* @param $validator
* @param string $attribute
* @return boolean
*/
public function validate(\Phalcon\Validation $validator, $attribute): bool
public function validate($validator, $attribute): bool
{
$node = $this->getOption('node');
if ($node) {

View File

@ -28,11 +28,10 @@
namespace OPNsense\Base\Constraints;
use Phalcon\Validation\AbstractValidator;
use Phalcon\Validation\ValidatorInterface;
use OPNsense\Base\BaseValidator;
use Phalcon\Messages\Message;
abstract class BaseConstraint extends AbstractValidator implements ValidatorInterface
abstract class BaseConstraint extends BaseValidator
{
/**
* check if field is empty (either boolean field as false or an empty field)
@ -51,10 +50,10 @@ abstract class BaseConstraint extends AbstractValidator implements ValidatorInte
}
/**
* @param \Phalcon\Validation $validator
* @param $validator
* @param $attribute
*/
protected function appendMessage(\Phalcon\Validation $validator, $attribute)
protected function appendMessage($validator, $attribute)
{
$message = $this->getOption('ValidationMessage');
$name = $this->getOption('name');

View File

@ -45,11 +45,11 @@ class ComparedToFieldConstraint extends BaseConstraint
* &lt;field&gt;name of another field which has the same parent node&lt;/field&gt;
* &lt;operator&gt;operator to check; one of gt|gte|lt|lte|eq|neq&lt;/operator&gt;
*
* @param \Phalcon\Validation $validator
* @param $validator
* @param string $attribute
* @return boolean
*/
public function validate(\Phalcon\Validation $validator, $attribute): bool
public function validate($validator, $attribute): bool
{
$node = $this->getOption('node');
$field_name = $this->getOption('field');

View File

@ -41,11 +41,11 @@ class DependConstraint extends BaseConstraint
* Executes validation, expects a list of fields in "addFields" which to check for content.
* Fields are concerned empty if boolean false or containing an empty string
*
* @param \Phalcon\Validation $validator
* @param $validator
* @param string $attribute
* @return boolean
*/
public function validate(\Phalcon\Validation $validator, $attribute): bool
public function validate($validator, $attribute): bool
{
$node = $this->getOption('node');
if ($node) {

View File

@ -45,11 +45,11 @@ class SetIfConstraint extends BaseConstraint
* &lt;field&gt;name of another field which has the same parent node&lt;/field&gt;
* &lt;check&gt;the value to check for as a string (for example the value of a OptionField)&lt;/check&gt;
*
* @param \Phalcon\Validation $validator
* @param $validator
* @param string $attribute
* @return boolean
*/
public function validate(\Phalcon\Validation $validator, $attribute): bool
public function validate($validator, $attribute): bool
{
$node = $this->getOption('node');
$field_name = $this->getOption('field');

View File

@ -40,11 +40,11 @@ class SingleSelectConstraint extends BaseConstraint
/**
* Executes validation
*
* @param \Phalcon\Validation $validator
* @param $validator
* @param string $attribute
* @return boolean
*/
public function validate(\Phalcon\Validation $validator, $attribute): bool
public function validate($validator, $attribute): bool
{
$node = $this->getOption('node');
if ($node) {

View File

@ -39,11 +39,11 @@ class UniqueConstraint extends BaseConstraint
/**
* Executes validation
*
* @param \Phalcon\Validation $validator
* @param $validator
* @param string $attribute
* @return boolean
*/
public function validate(\Phalcon\Validation $validator, $attribute): bool
public function validate($validator, $attribute): bool
{
$node = $this->getOption('node');
$fieldSeparator = chr(10) . chr(0);

View File

@ -31,7 +31,7 @@ namespace OPNsense\Base\FieldTypes;
use Exception;
use Generator;
use InvalidArgumentException;
use Phalcon\Validation\Validator\PresenceOf;
use OPNsense\Phalcon\Filter\Validation\Validator\PresenceOf;
use ReflectionClass;
use ReflectionException;
use SimpleXMLElement;

View File

@ -28,7 +28,7 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\InclusionIn;
use OPNsense\Phalcon\Filter\Validation\Validator\InclusionIn;
use OPNsense\Base\Validators\CsvListValidator;
/**

View File

@ -28,7 +28,7 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\Regex;
use OPNsense\Phalcon\Filter\Validation\Validator\Regex;
/**
* Class TextField

View File

@ -28,7 +28,7 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\Regex;
use OPNsense\Phalcon\Filter\Validation\Validator\Regex;
/**
* Class CSVListField

View File

@ -28,7 +28,7 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\InclusionIn;
use OPNsense\Phalcon\Filter\Validation\Validator\InclusionIn;
use OPNsense\Base\Validators\CsvListValidator;
/**

View File

@ -28,7 +28,7 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\Email;
use OPNsense\Phalcon\Filter\Validation\Validator\Email;
/**
* Class EmailField

View File

@ -28,7 +28,7 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\InclusionIn;
use OPNsense\Phalcon\Filter\Validation\Validator\InclusionIn;
use OPNsense\Base\Validators\CsvListValidator;
/**

View File

@ -29,7 +29,7 @@
namespace OPNsense\Base\FieldTypes;
use OPNsense\Base\Validators\MinMaxValidator;
use Phalcon\Validation\Validator\Numericality;
use OPNsense\Phalcon\Filter\Validation\Validator\Numericality;
/**
* Class NumericField

View File

@ -28,7 +28,7 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\InclusionIn;
use OPNsense\Phalcon\Filter\Validation\Validator\InclusionIn;
/**
* Class PortField field type for ports, includes validation for services in /etc/services or valid number ranges.

View File

@ -28,8 +28,8 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\Regex;
use Phalcon\Validation\Validator\PresenceOf;
use OPNsense\Phalcon\Filter\Validation\Validator\Regex;
use OPNsense\Phalcon\Filter\Validation\Validator\PresenceOf;
/**
* Class TextField

View File

@ -28,7 +28,7 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\InclusionIn;
use OPNsense\Phalcon\Filter\Validation\Validator\InclusionIn;
/**
* Class UniqueIdField

View File

@ -28,8 +28,8 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\Regex;
use Phalcon\Validation\Validator\PresenceOf;
use OPNsense\Phalcon\Filter\Validation\Validator\Regex;
use OPNsense\Phalcon\Filter\Validation\Validator\PresenceOf;
/**
* Class update only TextField (can be practical for password type fields)

View File

@ -28,7 +28,7 @@
namespace OPNsense\Base\FieldTypes;
use Phalcon\Validation\Validator\Url as UrlValidator;
use OPNsense\Phalcon\Filter\Validation\Validator\Url as UrlValidator;
/**
* Class EmailField

View File

@ -30,7 +30,7 @@
namespace OPNsense\Base\Menu;
use OPNsense\Core\Config;
use Phalcon\DI\FactoryDefault;
use Phalcon\Di\FactoryDefault;
/**
* Class MenuSystem

View File

@ -37,7 +37,9 @@ class Validation
public function __construct($validators = [])
{
$this->validators = $validators;
$this->phalcon_validation = new \Phalcon\Validation();
$this->phalcon_validation = explode('.', phpversion("phalcon"))[0] < 5
? new \Phalcon\Validation()
: new \Phalcon\Filter\Validation();
$this->messages = new Messages();
$this->data = [];
}
@ -101,4 +103,12 @@ class Validation
{
return isset($this->data[$attribute]) ? $this->data[$attribute] : null;
}
/**
* Only used by tests
*/
public function getMessages()
{
return $this->messages;
}
}

View File

@ -30,16 +30,14 @@
namespace OPNsense\Base\Validators;
use Phalcon\Validation\AbstractValidator;
use Phalcon\Validation\ValidatorInterface;
use Phalcon\Validation;
use OPNsense\Base\BaseValidator;
use Phalcon\Messages\Message;
/**
* Class CallbackValidator
* @package OPNsense\Base\Validators
*/
class CallbackValidator extends AbstractValidator implements ValidatorInterface
class CallbackValidator extends BaseValidator
{
/**
* Executes callback validator, which should return validation messages on failure
@ -48,7 +46,7 @@ class CallbackValidator extends AbstractValidator implements ValidatorInterface
* @param string $attribute
* @return boolean
*/
public function validate(Validation $validator, $attribute): bool
public function validate($validator, $attribute): bool
{
$callback = $this->getOption('callback');
if ($callback) {

View File

@ -30,24 +30,23 @@
namespace OPNsense\Base\Validators;
use Phalcon\Validation\AbstractValidator;
use Phalcon\Validation\ValidatorInterface;
use OPNsense\Base\BaseValidator;
use Phalcon\Messages\Message;
/**
* Class CsvListValidator validate a string list against a list of options
* @package OPNsense\Base\Validators
*/
class CsvListValidator extends AbstractValidator implements ValidatorInterface
class CsvListValidator extends BaseValidator
{
/**
* Executes validation
*
* @param \Phalcon\Validation $validator
* @param $validator
* @param string $attribute
* @return boolean
*/
public function validate(\Phalcon\Validation $validator, $attribute): bool
public function validate($validator, $attribute): bool
{
$value = $validator->getValue($attribute);
$domain = $this->getOption('domain');

View File

@ -30,23 +30,22 @@
namespace OPNsense\Base\Validators;
use Phalcon\Validation\AbstractValidator;
use Phalcon\Validation\ValidatorInterface;
use OPNsense\Base\BaseValidator;
use Phalcon\Messages\Message;
/**
* Class NetworkValidator validate domain and hostnames
* @package OPNsense\Base\Validators
*/
class HostValidator extends AbstractValidator implements ValidatorInterface
class HostValidator extends BaseValidator
{
/**
*
* @param \Phalcon\Validation $validator
* @param $validator
* @param string $attribute
* @return boolean
*/
public function validate(\Phalcon\Validation $validator, $attribute): bool
public function validate($validator, $attribute): bool
{
$result = true;
$msg = $this->getOption('message');

View File

@ -30,24 +30,23 @@
namespace OPNsense\Base\Validators;
use Phalcon\Validation\AbstractValidator;
use Phalcon\Validation\ValidatorInterface;
use OPNsense\Base\BaseValidator;
use Phalcon\Messages\Message;
/**
* Class IntegerValidator
* @package OPNsense\Base\Validators
*/
class IntegerValidator extends AbstractValidator implements ValidatorInterface
class IntegerValidator extends BaseValidator
{
/**
* Executes Integer validation
*
* @param \Phalcon\Validation $validator
* @param $validator
* @param string $attribute
* @return boolean
*/
public function validate(\Phalcon\Validation $validator, $attribute): bool
public function validate($validator, $attribute): bool
{
$value = $validator->getValue($attribute);
$msg = $this->getOption('message');

View File

@ -30,24 +30,23 @@
namespace OPNsense\Base\Validators;
use Phalcon\Validation\AbstractValidator;
use Phalcon\Validation\ValidatorInterface;
use OPNsense\Base\BaseValidator;
use Phalcon\Messages\Message;
/**
* Class MinMaxValidator
* @package OPNsense\Base\Validators
*/
class MinMaxValidator extends AbstractValidator implements ValidatorInterface
class MinMaxValidator extends BaseValidator
{
/**
* Executes MinMax validation
*
* @param \Phalcon\Validation $validator
* @param $validator
* @param string $attribute
* @return boolean
*/
public function validate(\Phalcon\Validation $validator, $attribute): bool
public function validate($validator, $attribute): bool
{
$value = $validator->getValue($attribute);

View File

@ -30,15 +30,14 @@
namespace OPNsense\Base\Validators;
use Phalcon\Validation\AbstractValidator;
use Phalcon\Validation\ValidatorInterface;
use OPNsense\Base\BaseValidator;
use Phalcon\Messages\Message;
/**
* Class NetworkValidator validate networks and ip addresses
* @package OPNsense\Base\Validators
*/
class NetworkValidator extends AbstractValidator implements ValidatorInterface
class NetworkValidator extends BaseValidator
{
/**
* Executes network / ip validation, accepts the following parameters as attributes:
@ -49,11 +48,11 @@ class NetworkValidator extends AbstractValidator implements ValidatorInterface
* netMaskRequired : true, false (default)
*
*
* @param \Phalcon\Validation $validator
* @param $validator
* @param string $attribute
* @return boolean
*/
public function validate(\Phalcon\Validation $validator, $attribute): bool
public function validate($validator, $attribute): bool
{
$result = true;
$msg = $this->getOption('message');

View File

@ -32,8 +32,8 @@ namespace OPNsense\Firewall\FieldTypes;
use OPNsense\Base\FieldTypes\BaseField;
use OPNsense\Base\Validators\CallbackValidator;
use Phalcon\Validation\Validator\Regex;
use Phalcon\Validation\Validator\ExclusionIn;
use OPNsense\Phalcon\Filter\Validation\Validator\Regex;
use OPNsense\Phalcon\Filter\Validation\Validator\ExclusionIn;
use Phalcon\Messages\Message;
use OPNsense\Firewall\Util;

View File

@ -32,8 +32,8 @@ namespace OPNsense\Firewall\FieldTypes;
use OPNsense\Base\FieldTypes\BaseField;
use OPNsense\Base\Validators\CallbackValidator;
use Phalcon\Validation\Validator\Regex;
use Phalcon\Validation\Validator\ExclusionIn;
use OPNsense\Phalcon\Filter\Validation\Validator\Regex;
use OPNsense\Phalcon\Filter\Validation\Validator\ExclusionIn;
/**
* Class AliasNameField

View File

@ -26,14 +26,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
use Phalcon\DI\FactoryDefault;
use Phalcon\Loader;
use Phalcon\Di\FactoryDefault;
$di = new FactoryDefault();
$phalcon_config = include("/usr/local/opnsense/mvc/app/config/config.php");
$loader = new Loader();
$loader->registerDirs(
$loader = new OPNsense\Phalcon\Autoload\Loader();
$loader->setDirectories(
array(
$phalcon_config->application->controllersDir,
$phalcon_config->application->modelsDir,

View File

@ -1,6 +1,9 @@
<?php
return new \Phalcon\Config(array(
include('/usr/local/opnsense/mvc/app/library/OPNsense/Phalcon/Config/Config.php');
include('/usr/local/opnsense/mvc/app/library/OPNsense/Phalcon/Autoload/Loader.php');
return new OPNsense\Phalcon\Config\Config(array(
'application' => array(
'controllersDir' => __DIR__ . '/../../../app/controllers/',
'modelsDir' => __DIR__ . '/../../../app/models/',

View File

@ -170,7 +170,7 @@ class BaseModelTest extends \PHPUnit\Framework\TestCase
*/
public function testValidationNOK()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("not a valid number");
// replace all numbers
foreach (BaseModelTest::$model->arraytypes->item->iterateItems() as $nodeid => $node) {
@ -244,7 +244,7 @@ class BaseModelTest extends \PHPUnit\Framework\TestCase
*/
public function testConstraintsNok()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("number should be unique");
$count = 2;
foreach (BaseModelTest::$model->arraytypes->item->iterateItems() as $nodeid => $node) {

View File

@ -40,17 +40,17 @@ class ComparedToFieldConstraintTest extends \PHPUnit\Framework\TestCase
// lesser then
public function test_if_it_validates_number_ranges_correctly_with_lt_and_no_error()
{
$validator = new \Phalcon\Validation();
$validator = new \OPNsense\Base\Validation();
$validate = $this->make_validator(2, 3, 'test', 'lt');
$ret = $validate->validate($validator, '');
$messages = $validator->getMessages();
$this->assertEquals(null, $messages);
$this->assertEquals(0, $messages->count());
$this->assertEquals(true, $ret);
}
public function test_if_it_validates_number_ranges_correctly_with_lt_and_error()
{
$validator = new \Phalcon\Validation();
$validator = new \OPNsense\Base\Validation();
$validate = $this->make_validator(3, 3, 'test', 'lt');
$ret = $validate->validate($validator, '');
$messages = $validator->getMessages();
@ -60,17 +60,17 @@ class ComparedToFieldConstraintTest extends \PHPUnit\Framework\TestCase
// greater then
public function test_if_it_validates_number_ranges_correctly_with_gt_and_no_error()
{
$validator = new \Phalcon\Validation();
$validator = new \OPNsense\Base\Validation();
$validate = $this->make_validator(5, 3, 'test', 'gt');
$ret = $validate->validate($validator, '');
$messages = $validator->getMessages();
$this->assertEquals(null, $messages);
$this->assertEquals(0, $messages->count());
$this->assertEquals(true, $ret);
}
public function test_if_it_validates_number_ranges_correctly_with_gt_and_error()
{
$validator = new \Phalcon\Validation();
$validator = new \OPNsense\Base\Validation();
$validate = $this->make_validator(2, 3, 'test', 'gt');
$ret = $validate->validate($validator, '');
$messages = $validator->getMessages();

View File

@ -35,7 +35,7 @@ require_once 'Field_Framework_TestCase.php';
// @CodingStandardsIgnoreEnd
use OPNsense\Base\FieldTypes\AuthGroupField;
use Phalcon\DI\FactoryDefault;
use Phalcon\Di\FactoryDefault;
use OPNsense\Core\Config;
class AuthGroupFieldTest extends Field_Framework_TestCase
@ -70,7 +70,7 @@ class AuthGroupFieldTest extends Field_Framework_TestCase
*/
public function testSelectSetWithUnknownValue()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("CsvListValidator");
// init field
$field = new AuthGroupField();
@ -99,7 +99,7 @@ class AuthGroupFieldTest extends Field_Framework_TestCase
*/
public function testSelectSetOnSingleValue()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("InclusionIn");
// init field
$field = new AuthGroupField();

View File

@ -35,7 +35,7 @@ require_once 'Field_Framework_TestCase.php';
// @CodingStandardsIgnoreEnd
use OPNsense\Base\FieldTypes\AuthenticationServerField;
use Phalcon\DI\FactoryDefault;
use Phalcon\Di\FactoryDefault;
use OPNsense\Core\Config;
class AuthenticationServerFieldTest extends Field_Framework_TestCase
@ -83,7 +83,7 @@ class AuthenticationServerFieldTest extends Field_Framework_TestCase
*/
public function testSelectSetWithUnknownValue()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("CsvListValidator");
// init field
$field = new AuthenticationServerField();
@ -112,7 +112,7 @@ class AuthenticationServerFieldTest extends Field_Framework_TestCase
*/
public function testSelectSetOnSingleValue()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("InclusionIn");
// init field
$field = new AuthenticationServerField();

View File

@ -45,7 +45,7 @@ class Base64FieldTest extends Field_Framework_TestCase
public function testRequiredEmpty()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("PresenceOf");
$field = new Base64Field();
$field->setRequired("Y");

View File

@ -50,7 +50,7 @@ class BooleanFieldTest extends Field_Framework_TestCase
*/
public function testShouldNotBeANumber()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("Regex");
$field = new BooleanField();
$field->setValue("90");
@ -61,7 +61,7 @@ class BooleanFieldTest extends Field_Framework_TestCase
*/
public function testShouldNotBeAString()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("Regex");
$field = new BooleanField();
$field->setValue("xx");
@ -73,7 +73,7 @@ class BooleanFieldTest extends Field_Framework_TestCase
*/
public function testRequiredEmpty()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("PresenceOf");
$field = new BooleanField();
$field->setRequired("Y");

View File

@ -35,7 +35,7 @@ require_once 'Field_Framework_TestCase.php';
// @CodingStandardsIgnoreEnd
use OPNsense\Base\FieldTypes\CertificateField;
use Phalcon\DI\FactoryDefault;
use Phalcon\Di\FactoryDefault;
use OPNsense\Core\Config;
class CertificateFieldTest extends Field_Framework_TestCase
@ -83,7 +83,7 @@ class CertificateFieldTest extends Field_Framework_TestCase
*/
public function testSelectSetWithUnknownValue()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("CsvListValidator");
// init field
$field = new CertificateField();
@ -112,7 +112,7 @@ class CertificateFieldTest extends Field_Framework_TestCase
*/
public function testSelectSetOnSingleValue()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("InclusionIn");
// init field
$field = new CertificateField();

View File

@ -50,7 +50,7 @@ class CountryFieldTest extends Field_Framework_TestCase
*/
public function testRequiredEmpty()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("PresenceOf");
$field = new CountryField();
$field->eventPostLoading();
@ -101,7 +101,7 @@ class CountryFieldTest extends Field_Framework_TestCase
*/
public function testSelectSetWithUnknownValue()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("CsvListValidator");
// init field
$field = new CountryField();
@ -144,7 +144,7 @@ class CountryFieldTest extends Field_Framework_TestCase
*/
public function testSelectSetOnSingleValue()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("InclusionIn");
// init field
$field = new CountryField();

View File

@ -37,11 +37,11 @@ class Field_Framework_TestCase extends \PHPUnit\Framework\TestCase
/**
* Validate and throw exception
* @param string $field field type
* @throws \Phalcon\Validation\Exception
* @throws \Phalcon\Filter\Validation\Exception
*/
public function validateThrow($field)
{
$validation = new \Phalcon\Validation();
$validation = new \OPNsense\Base\Validation();
foreach ($field->getValidators() as $validator) {
$validation->add("testfield", $validator);
}
@ -49,7 +49,7 @@ class Field_Framework_TestCase extends \PHPUnit\Framework\TestCase
$messages = $validation->validate(array("testfield" => (string)$field));
if (count($messages)) {
foreach ($messages as $message) {
throw new \Phalcon\Validation\Exception($message->getType());
throw new \OPNsense\Phalcon\Filter\Validation\Exception($message->getType());
}
}
return;
@ -63,7 +63,7 @@ class Field_Framework_TestCase extends \PHPUnit\Framework\TestCase
public function validate($field)
{
$result = array();
$validation = new \Phalcon\Validation();
$validation = new \OPNsense\Base\Validation();
foreach ($field->getValidators() as $validator) {
$validation->add("testfield", $validator);
}

View File

@ -50,7 +50,7 @@ class IntegerFieldTest extends Field_Framework_TestCase
*/
public function testValueLargerThenMax()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("MinMaxValidator");
$field = new IntegerField();
$field->setMaximumValue(100);
@ -64,7 +64,7 @@ class IntegerFieldTest extends Field_Framework_TestCase
*/
public function testValueSmallerThenMin()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("MinMaxValidator");
$field = new IntegerField();
$field->setMaximumValue(100);
@ -104,7 +104,7 @@ class IntegerFieldTest extends Field_Framework_TestCase
*/
public function testRequiredEmpty()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("PresenceOf");
$field = new IntegerField();
$field->setRequired("Y");

View File

@ -35,7 +35,7 @@ require_once 'Field_Framework_TestCase.php';
// @CodingStandardsIgnoreEnd
use OPNsense\Base\FieldTypes\InterfaceField;
use Phalcon\DI\FactoryDefault;
use Phalcon\Di\FactoryDefault;
use OPNsense\Core\Config;
class InterfaceFieldTest extends Field_Framework_TestCase
@ -70,7 +70,7 @@ class InterfaceFieldTest extends Field_Framework_TestCase
*/
public function testSelectHasNoParents()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("InclusionIn");
// init field
$field = new InterfaceField();
@ -111,7 +111,7 @@ class InterfaceFieldTest extends Field_Framework_TestCase
*/
public function testSelectSetWithUnknownValue()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("CsvListValidator");
// init field
$field = new InterfaceField();
@ -140,7 +140,7 @@ class InterfaceFieldTest extends Field_Framework_TestCase
*/
public function testSelectSetOnSingleValue()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("InclusionIn");
// init field
$field = new InterfaceField();

View File

@ -34,7 +34,7 @@ require_once __DIR__ . '/../BaseModel/TestModel.php';
// @CodingStandardsIgnoreEnd
use OPNsense\Base\FieldTypes\ModelRelationField;
use Phalcon\DI\FactoryDefault;
use Phalcon\Di\FactoryDefault;
use OPNsense\Core\Config;
class ModelRelationFieldTest extends Field_Framework_TestCase
@ -86,7 +86,7 @@ class ModelRelationFieldTest extends Field_Framework_TestCase
));
$field->eventPostLoading();
$field->setValue("5ea2a35c-b02b-485a-912b-d077e639bf9f,60e1bc02-6817-4940-bbd3-61d0cf439a8a");
$this->assertEquals($this->validate($field), ['Phalcon\Validation\Validator\InclusionIn']);
$this->assertEquals($this->validate($field), ['OPNsense\Phalcon\Filter\Validation\Validator\InclusionIn']);
}
/**
@ -123,7 +123,7 @@ class ModelRelationFieldTest extends Field_Framework_TestCase
));
$field->eventPostLoading();
$field->setValue("");
$this->assertEquals($this->validate($field), ['Phalcon\Validation\Validator\PresenceOf']);
$this->assertEquals($this->validate($field), ['OPNsense\Phalcon\Filter\Validation\Validator\PresenceOf']);
}
/**
@ -267,7 +267,7 @@ class ModelRelationFieldTest extends Field_Framework_TestCase
));
$field->eventPostLoading();
$field->setValue("XX5ea2a35c-b02b-485a-912b-d077e639bf9f");
$this->assertEquals($this->validate($field), ['Phalcon\Validation\Validator\InclusionIn']);
$this->assertEquals($this->validate($field), ['OPNsense\Phalcon\Filter\Validation\Validator\InclusionIn']);
}
/**
@ -324,7 +324,7 @@ class ModelRelationFieldTest extends Field_Framework_TestCase
));
$field->eventPostLoading();
$field->setValue("4d0e2835-7a19-4a19-8c23-e12383827594,5ea2a35c-b02b-485a-912b-d077e639bf9f");
$this->assertEquals($this->validate($field), ['Phalcon\Validation\Validator\InclusionIn']);
$this->assertEquals($this->validate($field), ['OPNsense\Phalcon\Filter\Validation\Validator\InclusionIn']);
}
/**

View File

@ -35,7 +35,7 @@ require_once 'Field_Framework_TestCase.php';
// @CodingStandardsIgnoreEnd
use OPNsense\Base\FieldTypes\NetworkAliasField;
use Phalcon\DI\FactoryDefault;
use Phalcon\Di\FactoryDefault;
use OPNsense\Core\Config;
class NetworkAliasFieldTest extends Field_Framework_TestCase

View File

@ -50,7 +50,7 @@ class OptionFieldTest extends Field_Framework_TestCase
*/
public function testRequiredEmpty()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("PresenceOf");
$field = new OptionField();
$field->setRequired("Y");

View File

@ -50,7 +50,7 @@ class PortFieldTest extends Field_Framework_TestCase
*/
public function testRequiredEmpty()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("PresenceOf");
$field = new PortField();
$field->setRequired("Y");

View File

@ -50,7 +50,7 @@ class ProtocolFieldTest extends Field_Framework_TestCase
*/
public function testRequiredEmpty()
{
$this->expectException(\Phalcon\Validation\Exception::class);
$this->expectException(\OPNsense\Phalcon\Filter\Validation\Exception::class);
$this->expectExceptionMessage("PresenceOf");
$field = new ProtocolField();
$field->eventPostLoading();

View File

@ -35,7 +35,7 @@ require_once 'Field_Framework_TestCase.php';
// @CodingStandardsIgnoreEnd
use OPNsense\Base\FieldTypes\VirtualIPField;
use Phalcon\DI\FactoryDefault;
use Phalcon\Di\FactoryDefault;
use OPNsense\Core\Config;
class VirtualIPFieldTest extends Field_Framework_TestCase

View File

@ -26,7 +26,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
use Phalcon\Di;
use OPNsense\Phalcon\Di\Di;
use Phalcon\Di\FactoryDefault;
ini_set('display_errors', 1);

View File

@ -71,7 +71,7 @@ class LegacyCSRF
private function newToken()
{
$random = new \Phalcon\Security\Random();
$random = new \OPNsense\Phalcon\Encryption\Security\Random();
// only request new token when session has none
if (empty($_SESSION['$PHALCON/CSRF/KEY$']) || empty($_SESSION['$PHALCON/CSRF$'])) {
$_SESSION['$PHALCON/CSRF$'] = $random->base64Safe(16);