mirror of
https://github.com/lucaspalomodevelop/opnsense-core.git
synced 2026-03-13 00:07:27 +00:00
mvc: add "make validate" target and script
This commit is contained in:
parent
10e726113b
commit
ca2609efbd
3
Makefile
3
Makefile
@ -528,6 +528,9 @@ push:
|
||||
migrate:
|
||||
@src/opnsense/mvc/script/run_migrations.php
|
||||
|
||||
validate:
|
||||
@src/opnsense/mvc/script/run_validations.php
|
||||
|
||||
test: debug
|
||||
@if [ "$$(${VERSIONBIN} -v)" != "${CORE_PKGVERSION}" ]; then \
|
||||
echo "Installed version does not match, expected ${CORE_PKGVERSION}"; \
|
||||
|
||||
1
plist
1
plist
@ -810,6 +810,7 @@
|
||||
/usr/local/opnsense/mvc/app/views/layouts/default.volt
|
||||
/usr/local/opnsense/mvc/script/load_phalcon.php
|
||||
/usr/local/opnsense/mvc/script/run_migrations.php
|
||||
/usr/local/opnsense/mvc/script/run_validations.php
|
||||
/usr/local/opnsense/mvc/tests/PHPunit.xml
|
||||
/usr/local/opnsense/mvc/tests/app/config/config.php
|
||||
/usr/local/opnsense/mvc/tests/app/models/OPNsense/Base/BaseModel/Migrations/M0_0_1.php
|
||||
|
||||
63
src/opnsense/mvc/script/run_validations.php
Executable file
63
src/opnsense/mvc/script/run_validations.php
Executable file
@ -0,0 +1,63 @@
|
||||
#!/usr/local/bin/php
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Deciso B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
require_once('script/load_phalcon.php');
|
||||
|
||||
use OPNsense\Core\Config;
|
||||
|
||||
$classprefix = !empty($argv[1]) ? str_replace('/', '\\', $argv[1]) : '';
|
||||
$class_info = new \ReflectionClass("OPNsense\\Base\\BaseModel");
|
||||
$model_dir = dirname($class_info->getFileName()) . "/../../";
|
||||
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($model_dir)) as $x) {
|
||||
if (strtolower(substr($x->getPathname(), -4)) == '.php') {
|
||||
$classname = str_replace('/', '\\', explode('.', str_replace($model_dir, '', $x->getPathname()))[0]);
|
||||
/* XXX we match the prefix here, but should eventually switch to component exploded by "\" */
|
||||
if (!empty($classprefix) && strpos($classname, $classprefix) !== 0) {
|
||||
/* not our requested class */
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$mdl_class_info = new \ReflectionClass($classname);
|
||||
$parent = $mdl_class_info->getParentClass();
|
||||
if ($parent && $parent->name == 'OPNsense\Base\BaseModel') {
|
||||
$name = $mdl_class_info->getName();
|
||||
$mdl = $mdl_class_info->newInstance();
|
||||
if (!$mdl->isVolatile()) {
|
||||
$msgs = $mdl->validate();
|
||||
foreach ($msgs as $key => $msg) {
|
||||
echo sprintf('%s.%s => %s', $name, $key, $msg) . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\ReflectionException $e) {
|
||||
/* cannot construct, skip */
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user