Compare commits

...

10 Commits

Author SHA1 Message Date
Clemens Schwaighofer
4b3fbaa309 Updates based on latest phpstan run 2022-09-02 17:00:22 +09:00
Clemens Schwaighofer
1a6c65df0e Minor test updates, comment typo updates, DB_CONFIG_SET for default
$DB_CONFIG_SET is now default current selcted db config instead of
$DB_CONFIG so to not overwrite the array itself
2022-08-05 12:43:57 +09:00
Clemens Schwaighofer
24f553a17e Update comments for split element counter 2022-07-29 13:20:54 +09:00
Clemens Schwaighofer
9a3ea2f7db update strings class with split counter method 2022-07-29 13:19:45 +09:00
Clemens Schwaighofer
bcdb877d90 Phan/phpstan fixes 2022-07-29 11:06:53 +09:00
Clemens Schwaighofer
6d0e528c38 Combined\Datetime date/number to weekday conversion
Convert functions for date or weekday number to weekday name or date to
weekday number
2022-07-29 11:02:25 +09:00
Clemens Schwaighofer
7e6474195b String split format fix for non ascii characters
Currently just abort and return string as is
2022-07-29 10:38:32 +09:00
Clemens Schwaighofer
1795d3ba6c String convert class added
Currently with one method: splitFormatString

Converts a string to a string with separater characters based on a
format string
2022-07-29 07:00:02 +09:00
Clemens Schwaighofer
e1340acf55 Class header info string fix 2022-07-29 06:59:33 +09:00
Clemens Schwaighofer
b5ead3e266 Minor code block comment clean ups 2022-07-15 17:42:38 +09:00
25 changed files with 773 additions and 68 deletions

View File

@@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase;
*/
final class CoreLibsCombinedDateTimeTest extends TestCase
{
/**
* timestamps
*
@@ -618,13 +617,169 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
* @param array $expected
* @return void
*/
public function testCalcDaysInterval(string $input_a, string $input_b, bool $flag, $expected): void
{
public function testCalcDaysInterval(
string $input_a,
string $input_b,
bool $flag,
$expected
): void {
$this->assertEquals(
$expected,
\CoreLibs\Combined\DateTime::calcDaysInterval($input_a, $input_b, $flag)
);
}
/**
* Undocumented function
*
* @return array
*/
public function weekdayNumberProvider(): array
{
return [
'0 invalid' => [0, null, 'Inv',],
'0 invalid long' => [0, true, 'Invalid',],
'1 short' => [1, null, 'Mon',],
'1 long' => [1, true, 'Monday',],
'2 short' => [2, null, 'Tue',],
'2 long' => [2, true, 'Tuesday',],
'3 short' => [3, null, 'Wed',],
'3 long' => [3, true, 'Wednesday',],
'4 short' => [4, null, 'Thu',],
'4 long' => [4, true, 'Thursday',],
'5 short' => [5, null, 'Fri',],
'5 long' => [5, true, 'Friday',],
'6 short' => [6, null, 'Sat',],
'6 long' => [6, true, 'Saturday',],
'7 short' => [7, null, 'Sun',],
'7 long' => [7, true, 'Sunday',],
'8 invalid' => [8, null, 'Inv',],
'8 invalid long' => [8, true, 'Invalid',],
];
}
/**
* int weekday number to string weekday
*
* @covers ::setWeekdayNameFromIsoDow
* @dataProvider weekdayNumberProvider
* @testdox weekdayListProvider $input (short $flag) will be $expected [$_dataName]
*
* @param int $input
* @param bool|null $flag
* @param string $expected
* @return void
*/
public function testSetWeekdayNameFromIsoDow(
int $input,
?bool $flag,
string $expected
): void {
if ($flag === null) {
$output = \CoreLibs\Combined\DateTime::setWeekdayNameFromIsoDow($input);
} else {
$output = \CoreLibs\Combined\DateTime::setWeekdayNameFromIsoDow($input, $flag);
}
$this->assertEquals(
$expected,
$output
);
}
/**
* Undocumented function
*
* @return array
*/
public function weekdayDateProvider(): array
{
return [
'invalid date' => ['2022-02-31', -1],
'1: monday' => ['2022-07-25', 1],
'2: tuesday' => ['2022-07-26', 2],
'3: wednesday' => ['2022-07-27', 3],
'4: thursday' => ['2022-07-28', 4],
'5: friday' => ['2022-07-29', 5],
'6: saturday' => ['2022-07-30', 6],
'7: sunday' => ['2022-07-31', 7],
];
}
/**
* date to weekday number
*
* @covers ::setWeekdayNumberFromDate
* @dataProvider weekdayDateProvider
* @testdox setWeekdayNumberFromDate $input will be $expected [$_dataName]
*
* @param string $input
* @param int $expected
* @return void
*/
public function testSetWeekdayNumberFromDate(
string $input,
int $expected
): void {
$this->assertEquals(
$expected,
\CoreLibs\Combined\DateTime::setWeekdayNumberFromDate($input)
);
}
/**
* Undocumented function
*
* @return array
*/
public function weekdayDateNameProvider(): array
{
return [
'invalid date short' => ['2022-02-31', null, 'Inv'],
'invalid date long' => ['2022-02-31', true, 'Invalid'],
'Mon short' => ['2022-07-25', null, 'Mon'],
'Monday long' => ['2022-07-25', true, 'Monday'],
'Tue short' => ['2022-07-26', null, 'Tue'],
'Tuesday long' => ['2022-07-26', true, 'Tuesday'],
'Wed short' => ['2022-07-27', null, 'Wed'],
'Wednesday long' => ['2022-07-27', true, 'Wednesday'],
'Thu short' => ['2022-07-28', null, 'Thu'],
'Thursday long' => ['2022-07-28', true, 'Thursday'],
'Fri short' => ['2022-07-29', null, 'Fri'],
'Friday long' => ['2022-07-29', true, 'Friday'],
'Sat short' => ['2022-07-30', null, 'Sat'],
'Saturday long' => ['2022-07-30', true, 'Saturday'],
'Sun short' => ['2022-07-31', null, 'Sun'],
'Sunday long' => ['2022-07-31', true, 'Sunday'],
];
}
/**
* date to weekday name
*
* @covers ::setWeekdayNameFromDate
* @dataProvider weekdayDateNameProvider
* @testdox setWeekdayNameFromDate $input (short $flag) will be $expected [$_dataName]
*
* @param string $input
* @param bool|null $flag
* @param string $expected
* @return void
*/
public function testSetWeekdayNameFromDate(
string $input,
?bool $flag,
string $expected
): void {
if ($flag === null) {
$output = \CoreLibs\Combined\DateTime::setWeekdayNameFromDate($input);
} else {
$output = \CoreLibs\Combined\DateTime::setWeekdayNameFromDate($input, $flag);
}
$this->assertEquals(
$expected,
$output
);
}
}
// __END__

View File

@@ -0,0 +1,261 @@
<?php // phpcs:disable Generic.Files.LineLength
declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
/**
* Test class for Convert\Strings
* @coversDefaultClass \CoreLibs\Convert\Strings
* @testdox \CoreLibs\Convert\Strings method tests
*/
final class CoreLibsConvertStringsTest extends TestCase
{
/**
* Undocumented function
*
* @return array
*/
public function splitFormatStringProvider(): array
{
// 0: input
// 1: format
// 2: split characters as string, null for default
// 3: expected
return [
'all empty string' => [
'',
'',
null,
''
],
'empty input string' => [
'',
'2-2',
null,
''
],
'empty format string string' => [
'1234',
'',
null,
'1234'
],
'string format match' => [
'1234',
'2-2',
null,
'12-34'
],
'string format trailing match' => [
'1234',
'2-2-',
null,
'12-34'
],
'string format leading match' => [
'1234',
'-2-2',
null,
'12-34'
],
'string format double inside match' => [
'1234',
'2--2',
null,
'12--34',
],
'string format short first' => [
'1',
'2-2',
null,
'1'
],
'string format match first' => [
'12',
'2-2',
null,
'12'
],
'string format short second' => [
'123',
'2-2',
null,
'12-3'
],
'string format too long' => [
'1234567',
'2-2',
null,
'12-34-567'
],
'string format invalid format string' => [
'1234',
'2_2',
null,
'1234'
],
'different split character' => [
'1234',
'2_2',
'_',
'12_34'
],
'mixed split characters' => [
'123456',
'2-2_2',
'-_',
'12-34_56'
],
'length mixed' => [
'ABCD12345568ABC13',
'2-4_5-2#4',
'-_#',
'AB-CD12_34556-8A#BC13'
],
'split with split chars in string' => [
'12-34',
'2-2',
null,
'12--3-4'
],
'mutltibyte string' => [
'あいうえ',
'2-2',
null,
'あいうえ'
],
'mutltibyte split string' => [
'1234',
'-',
null,
'1234'
],
];
}
/**
* split format string
*
* @covers ::splitFormatString
* @dataProvider splitFormatStringProvider
* @testdox splitFormatString $input with format $format and splitters $split_characters will be $expected [$_dataName]
*
* @param string $input
* @param string $format
* @param string|null $split_characters
* @param string $expected
* @return void
*/
public function testSplitFormatString(
string $input,
string $format,
?string $split_characters,
string $expected
): void {
if ($split_characters === null) {
$output = \CoreLibs\Convert\Strings::splitFormatString(
$input,
$format
);
} else {
$output = \CoreLibs\Convert\Strings::splitFormatString(
$input,
$format,
$split_characters
);
}
$this->assertEquals(
$expected,
$output
);
}
/**
* Undocumented function
*
* @return array
*/
public function countSplitPartsProvider(): array
{
return [
'0 elements' => [
'',
null,
0
],
'1 element' => [
'1',
null,
1,
],
'2 elements, trailing' => [
'1-2-',
null,
2
],
'2 elements, leading' => [
'-1-2',
null,
2
],
'2 elements, midde double' => [
'1--2',
null,
2
],
'4 elements' => [
'1-2-3-4',
null,
4
],
'3 elemenst, other splitter' => [
'2-3_3',
'-_',
3
],
'illegal splitter' => [
'あsdf',
null,
0
]
];
}
/**
* count split parts
*
* @covers ::countSplitParts
* @dataProvider countSplitPartsProvider
* @testdox countSplitParts $input with splitters $split_characters will be $expected [$_dataName]
*
* @param string $input
* @param string|null $split_characters
* @param int $expected
* @return void
*/
public function testCountSplitParts(
string $input,
?string $split_characters,
int $expected
): void {
if ($split_characters === null) {
$output = \CoreLibs\Convert\Strings::countSplitParts(
$input
);
} else {
$output = \CoreLibs\Convert\Strings::countSplitParts(
$input,
$split_characters
);
}
$this->assertEquals(
$expected,
$output
);
}
}
// __END__

View File

@@ -1,72 +1,47 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$connection of function pg_connection_busy expects PgSql\\\\Connection, object\\|resource given\\.$#"
count: 3
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_connection_status expects PgSql\\\\Connection, object\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$connection of function pg_escape_bytea expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_get_result expects PgSql\\\\Connection, object\\|resource given\\.$#"
count: 2
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_meta_data expects PgSql\\\\Connection, object\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$connection of function pg_escape_identifier expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_send_query expects PgSql\\\\Connection, object\\|resource given\\.$#"
count: 2
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_socket expects PgSql\\\\Connection, object\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$connection of function pg_escape_literal expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$connection of function pg_version expects PgSql\\\\Connection\\|null, object\\|resource given\\.$#"
count: 2
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_affected_rows expects PgSql\\\\Result, object\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$connection of function pg_escape_string expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_fetch_all expects PgSql\\\\Result, object\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$connection of function pg_execute expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_fetch_array expects PgSql\\\\Result, object\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$connection of function pg_parameter_status expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_field_name expects PgSql\\\\Result, object\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$connection of function pg_prepare expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_num_fields expects PgSql\\\\Result, object\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$connection of function pg_query expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_num_rows expects PgSql\\\\Result, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
-
message: "#^Parameter \\#1 \\$result of function pg_result_error expects PgSql\\\\Result, object\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$connection of function pg_query_params expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
count: 1
path: www/lib/CoreLibs/DB/SQL/PgSQL.php

View File

@@ -49,11 +49,11 @@ parameters:
- www/vendor
# ignore errores with
ignoreErrors:
- # this error is ignore because of the PHP 8.0 to 8.1 change for pg_*, only for 8.0 or lower
message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects resource(\\|null)?, object\\|resource(\\|bool)? given\\.$#"
path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php
#- # this error is ignore because of the PHP 8.0 to 8.1 change for pg_*, only for 8.0 or lower
# message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects resource(\\|null)?, object\\|resource(\\|bool)? given\\.$#"
# path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php
- # this is for 8.1 or newer
message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects PgSql\\\\(Result|Connection(\\|null)?), object\\|resource given\\.$#"
message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects PgSql\\\\(Result|Connection(\\|string)?(\\|null)?), object\\|resource given\\.$#"
path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php
# this is ignored for now
# - '#Expression in empty\(\) is always falsy.#'

View File

@@ -139,6 +139,22 @@ foreach ($compare_dates as $compare_date) {
. DgS::printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1], true)) . "<br>";
}
// test date conversion
$dow = 2;
print "DOW[$dow]: " . DateTime::setWeekdayNameFromIsoDow($dow) . "<br>";
print "DOW[$dow],long: " . DateTime::setWeekdayNameFromIsoDow($dow, true) . "<br>";
$date = '2022-7-22';
print "DATE-dow[$date]: " . DateTime::setWeekdayNameFromDate($date) . "<br>";
print "DATE-dow[$date],long: " . DateTime::setWeekdayNameFromDate($date, true) . "<br>";
print "DOW-date[$date]: " . DateTime::setWeekdayNumberFromDate($date) . "<br>";
$dow = 11;
print "DOW[$dow];invalid: " . DateTime::setWeekdayNameFromIsoDow($dow) . "<br>";
print "DOW[$dow],long;invalid: " . DateTime::setWeekdayNameFromIsoDow($dow, true) . "<br>";
$date = '2022-70-242';
print "DATE-dow[$date];invalid: " . DateTime::setWeekdayNameFromDate($date) . "<br>";
print "DATE-dow[$date],long;invalid: " . DateTime::setWeekdayNameFromDate($date, true) . "<br>";
print "DOW-date[$date];invalid: " . DateTime::setWeekdayNumberFromDate($date) . "<br>";
// error message
print $log->printErrorMsg();

View File

@@ -209,13 +209,12 @@ print "INSERT WITH NO PRIMARY KEY WITH RETURNING STATUS: " . Support::printToStr
print "</pre>";
// READ PREPARE
if (
$db->dbPrepare(
'sel_test_foo',
"SELECT test_foo_id, test, some_bool, string_a, number_a, number_a_numeric, some_time "
. "FROM test_foo ORDER BY test_foo_id DESC LIMIT 5"
) === false
) {
$q_prep = "SELECT test_foo_id, test, some_bool, string_a, number_a, "
. "number_a_numeric, some_time "
. "FROM test_foo "
. "WHERE test = $1 "
. "ORDER BY test_foo_id DESC LIMIT 5";
if ($db->dbPrepare('sel_test_foo', $q_prep) === false) {
print "Error in sel_test_foo prepare<br>";
} else {
$max_rows = 6;
@@ -229,6 +228,29 @@ if (
$i++;
}
}
// prepre a second time on normal connection
if ($db->dbPrepare('sel_test_foo', $q_prep) === false) {
print "Error prepareing<br>";
print "ERROR (dbPrepare on same query): "
. $db->dbGetLastError() . "/" . $db->dbGetLastWarning() . "/"
. "<pre>" . print_r($db->dbGetCombinedErrorHistory(), true) . "</pre><br>";
}
// NOTE: try to replacate connection still exists if script is run a second time
// open pg bouncer connection
$db_pgb = new CoreLibs\DB\IO($DB_CONFIG['test_pgbouncer'], $log);
print "[PGB] DBINFO: " . $db_pgb->dbInfo() . "<br>";
if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) {
print "[PGB] [1] Error in pgb_sel_test_foo prepare<br>";
} else {
print "[PGB] [1] pgb_sel_test_foo prepare OK<br>";
}
// second prepare
if ($db->dbPrepare('pgb_sel_test_foo', $q_prep) === false) {
print "[PGB] [2] Error in pgb_sel_test_foo prepare<br>";
} else {
print "[PGB] [2] pgb_sel_test_foo prepare OK<br>";
}
$db_pgb->dbClose();
# db write class test
$table = 'test_foo';

View File

@@ -70,6 +70,7 @@ print '<div><a href="class_test.hash.php">Class Test: HASH</a></div>';
print '<div><a href="class_test.encoding.php">Class Test: ENCODING (CHECK/CONVERT/MIME)</a></div>';
print '<div><a href="class_test.image.php">Class Test: IMAGE</a></div>';
print '<div><a href="class_test.byte.php">Class Test: BYTE CONVERT</a></div>';
print '<div><a href="class_test.strings.php">Class Test: STRING CONVERT</a></div>';
print '<div><a href="class_test.datetime.php">Class Test: DATE/TIME</a></div>';
print '<div><a href="class_test.array.php">Class Test: ARRAY HANDLER</a></div>';
print '<div><a href="class_test.file.php">Class Test: FILE</a></div>';

View File

@@ -0,0 +1,86 @@
<?php // phpcs:ignore warning
declare(strict_types=1);
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL) {
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
}
ob_start();
// basic class test file
define('USE_DATABASE', false);
// sample config
require 'config.php';
// define log file id
$LOG_FILE_ID = 'classTest-string';
ob_end_flush();
$log = new CoreLibs\Debug\Logging([
'log_folder' => BASE . LOG,
'file_id' => $LOG_FILE_ID,
// add file date
'print_file_date' => true,
// set debug and print flags
'debug_all' => $DEBUG_ALL ?? false,
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
$byte_class = 'CoreLibs\Convert\Strings';
$PAGE_NAME = 'TEST CLASS: STRINGS CONVERT';
print "<!DOCTYPE html>";
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
$split = '4-4-4';
$test_strings = [
'13',
'1234',
'12341',
'12341234',
'123412341',
'123412341234',
'1234123412341234512345',
];
foreach ($test_strings as $string) {
print "Convert: $string with $split to: "
. \CoreLibs\Convert\Strings::splitFormatString($string, $split)
. "<br>";
}
$split = '2_2';
$string = '1234';
print "Convert: $string with $split to: "
. \CoreLibs\Convert\Strings::splitFormatString($string, $split)
. "<br>";
$split = '2-2';
$string = 'あいうえ';
print "Convert: $string with $split to: "
. \CoreLibs\Convert\Strings::splitFormatString($string, $split)
. "<br>";
$test_splits = [
'',
'2',
'2-2',
'2-3-4',
];
foreach ($test_splits as $split) {
print "$split with count: " . \CoreLibs\Convert\Strings::countSplitParts($split) . "<br>";
}
// error message
print $log->printErrorMsg();
print "</body></html>";
// __END__

View File

@@ -17,7 +17,20 @@ $DB_CONFIG = [
'db_user' => $_ENV['DB_USER.TEST'] ?? '',
'db_pass' => $_ENV['DB_PASS.TEST'] ?? '',
'db_host' => $_ENV['DB_HOST.TEST'] ?? '',
'db_port' => 5432,
'db_port' => $_ENV['DB_PORT.PG'] ?? 5432,
'db_schema' => 'public',
'db_type' => 'pgsql',
'db_encoding' => '',
'db_ssl' => 'allow', // allow, disable, require, prefer
'db_debug' => true, // turn on logging or not
],
// same as above, but uses pg bouncer
'test_pgbouncer' => [
'db_name' => $_ENV['DB_NAME.TEST'] ?? '',
'db_user' => $_ENV['DB_USER.TEST'] ?? '',
'db_pass' => $_ENV['DB_PASS.TEST'] ?? '',
'db_host' => $_ENV['DB_HOST.TEST'] ?? '',
'db_port' => $_ENV['DB_PORT.PG_BOUNCER'] ?? 5432,
'db_schema' => 'public',
'db_type' => 'pgsql',
'db_encoding' => '',

View File

@@ -252,7 +252,7 @@ if ($is_secure) {
define('DB_CONFIG_NAME', $SITE_CONFIG[HOST_NAME]['db_host']);
define('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME] ?? []);
// because we can't change constant, but we want to for db debug flag
$GLOBALS['DB_CONFIG'] = DB_CONFIG;
$GLOBALS['DB_CONFIG_SET'] = DB_CONFIG;
// define('DB_CONFIG_TARGET', SITE_CONFIG[$HOST_NAME]['db_host_target']);
// define('DB_CONFIG_OTHER', SITE_CONFIG[$HOST_NAME]['db_host_other']);
// override for login and global schemas

View File

@@ -2,9 +2,9 @@
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2008/08/14
* CREATED:
* SHORT DESCRIPTION:
* URL redirect header
*
* HISTORY:
*********************************************************************/

View File

@@ -2,8 +2,9 @@
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2008/08/01
* CREATED:
* SHORT DESCRIPTION:
*
* HISTORY:
*********************************************************************/

View File

@@ -1287,6 +1287,7 @@ class Login
. $strings['PASSWORD_CHANGE_BUTTON_VALUE']
. '" OnClick="ShowHideDiv(\'pw_change_div\');">'
]);
// TODO: submit or JS to set target page as ajax call
// NOTE: for the HTML block I ignore line lengths
// phpcs:disable
$this->login_template['password_change'] = <<<EOM
@@ -1329,9 +1330,11 @@ EOM;
}
// now check templates
// TODO: submit or JS to set target page as ajax call
if (!$this->login_template['template']) {
$this->login_template['template'] = <<<EOM
<html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>{HTML_TITLE}</title>
<style type="text/css">
@@ -1485,7 +1488,6 @@ EOM;
}
// initial the session if there is no session running already
// check if session exists and could be created
// TODO: move session creation and check to outside?
if ($this->session->checkActiveSession() === false) {
$this->login_error = 2;
echo '<b>No active session found</b>';

View File

@@ -1,7 +1,7 @@
<?php
/*
* DEPRECATED: Use correct Json:: instead
* DEPRECATED: Use correct Convert\Json:: instead
*/
declare(strict_types=1);

View File

@@ -1,7 +1,7 @@
<?php
/*
* html convert functions
* array search and transform functions
*/
declare(strict_types=1);

View File

@@ -1,7 +1,7 @@
<?php
/*
* image thumbnail, rotate, etc
* date convert and check functions
*/
declare(strict_types=1);
@@ -193,6 +193,54 @@ class DateTime
}
}
/**
* Returns long or short day of week name based on ISO day of week number
* 1: Monday
* ...
* 7: Sunday
*
* @param int $isodow 1: Monday, 7: Sunday
* @param bool $long Default false 'Mon', if true 'Monday'
* @return string Day of week string either short 'Mon' or long 'Monday'
*/
public static function setWeekdayNameFromIsoDow(int $isodow, bool $long = false): string
{
// if not valid, set to invalid
if ($isodow < 1 || $isodow > 7) {
return $long ? 'Invalid' : 'Inv';
}
return date($long ? 'l' : 'D', strtotime("Sunday +{$isodow} days") ?: null);
}
/**
* Get the day of week Name from date
*
* @param string $date Any valid date
* @param bool $long Default false 'Mon', if true 'Monday'
* @return string Day of week string either short 'Mon' or long 'Monday'
*/
public static function setWeekdayNameFromDate(string $date, bool $long = false): string
{
if (!self::checkDate($date)) {
return $long ? 'Invalid' : 'Inv';
}
return date($long ? 'l' : 'D', strtotime($date) ?: null);
}
/**
* Get the day of week Name from date
*
* @param string $date Any valid date
* @return int ISO Weekday number 1: Monday, 7: Sunday, -1 for invalid date
*/
public static function setWeekdayNumberFromDate(string $date): int
{
if (!self::checkDate($date)) {
return -1;
}
return (int)date('N', strtotime($date) ?: null);
}
/**
* splits & checks date, wrap around for check_date function
*

View File

@@ -1,7 +1,7 @@
<?php
/*
* image thumbnail, rotate, etc
* byte conversion from and to human readable
*/
declare(strict_types=1);

View File

@@ -1,7 +1,7 @@
<?php
/*
* check if string is valid in target encoding
* convert string frmo one encdoing to another with auto detect flags
*/
declare(strict_types=1);

View File

@@ -0,0 +1,123 @@
<?php
/*
* string convert and transform functions
*/
declare(strict_types=1);
namespace CoreLibs\Convert;
class Strings
{
/**
* return the number of elements in the split list
* 0 if nothing / invalid split
* 1 if no split character found
* n for the numbers in the split list
*
* @param string $split_format
* @param string $split_characters
* @return int
*/
public static function countSplitParts(
string $split_format,
string $split_characters = '-'
): int {
if (
empty($split_format) ||
// non valid characters inside, abort
!preg_match("/^[0-9" . $split_characters . "]/", $split_format) ||
preg_match('/[^\x20-\x7e]/', $split_characters)
) {
return 0;
}
$split_list = preg_split(
// allowed split characters
"/([" . $split_characters . "]{1})/",
$split_format
);
if (!is_array($split_list)) {
return 0;
}
return count(array_filter($split_list));
}
/**
* split format a string base on a split format string
* split format string is eg
* 4-4-4 that means 4 characters DASH 4 characters DASH 4 characters
* So a string in the format of
* ABCD1234EFGH will be ABCD-1234-EFGH
* Note a string LONGER then the maxium will be attached with the LAST
* split character. In above exmaple
* ABCD1234EFGHTOOLONG will be ABCD-1234-EFGH-TOOLONG
*
* @param string $value string value to split
* @param string $split_format split format
* @param string $split_characters list of charcters with which we split
* if not set uses dash ('-')
* @return string split formatted string or original value if not chnaged
*/
public static function splitFormatString(
string $value,
string $split_format,
string $split_characters = '-'
): string {
if (
// abort if split format is empty
empty($split_format) ||
// if not in the valid ASCII character range for any of the strings
preg_match('/[^\x20-\x7e]/', $value) ||
// preg_match('/[^\x20-\x7e]/', $split_format) ||
preg_match('/[^\x20-\x7e]/', $split_characters) ||
// only numbers and split characters in split_format
!preg_match("/[0-9" . $split_characters . "]/", $split_format)
) {
return $value;
}
// split format list
$split_list = preg_split(
// allowed split characters
"/([" . $split_characters . "]{1})/",
$split_format,
-1,
PREG_SPLIT_DELIM_CAPTURE
);
// if this is false, or only one array, abort split
if (!is_array($split_list) || count($split_list) == 1) {
return $value;
}
$out = '';
$pos = 0;
$last_split = '';
foreach ($split_list as $offset) {
if (is_numeric($offset)) {
$_part = substr($value, $pos, (int)$offset);
if (empty($_part)) {
break;
}
$out .= $_part;
$pos += (int)$offset;
} elseif ($pos) { // if first, do not add
$out .= $offset;
$last_split = $offset;
}
}
if (!empty($out) && $pos < strlen($value)) {
$out .= $last_split . substr($value, $pos);
}
// if last is not alphanumeric remove, remove
if (!strcspn(substr($out, -1, 1), $split_characters)) {
$out = substr($out, 0, -1);
}
// overwrite only if out is set
if (!empty($out)) {
return $out;
} else {
return $value;
}
}
}
// __END__

View File

@@ -1,7 +1,7 @@
<?php
/*
* html convert functions
* random key functions
*/
declare(strict_types=1);

View File

@@ -2580,9 +2580,9 @@ class IO
// loop through the write array and each field to build the query
foreach ($write_array as $field) {
if (
(empty($primary_key['value']) ||
(!empty($primary_key['value']) &&
!in_array($field, $not_write_update_array))
(
empty($primary_key['value']) ||
!in_array($field, $not_write_update_array)
) &&
!in_array($field, $not_write_array)
) {
@@ -2963,7 +2963,7 @@ class IO
* Either as single array level for single insert
* Or nested array for multiple insert values
*
* If key was set only returns tghose values directly or as array
* If key was set only returns those values directly or as array
*
* On multiple insert return the position for which to return can be set too
*
@@ -2978,7 +2978,7 @@ class IO
// return as is if key is null
if ($key === null) {
if (count($this->insert_id_arr) == 1) {
// return as nul if not found
// return as null if not found
return $this->insert_id_arr[0] ?? null;
} else {
return $this->insert_id_arr;

View File

@@ -173,7 +173,7 @@ class Logging
// can be overridden with basicSetLogFileId later
if (!empty($this->options['file_id'])) {
$this->setLogId($this->options['file_id'] ?? '');
$this->setLogId($this->options['file_id']);
} elseif (!empty($GLOBALS['LOG_FILE_ID'])) {
// legacy flow, should be removed and only set via options
$this->setLogId($GLOBALS['LOG_FILE_ID']);

View File

@@ -423,7 +423,7 @@ class SmartyExtend extends \Smarty
$this->DATA['ADMIN'] = $cms->acl['admin'] ?? 0;
// top menu
$this->DATA['nav_menu'] = $cms->adbTopMenu();
$this->DATA['nav_menu_count'] = is_array($this->DATA['nav_menu']) ? count($this->DATA['nav_menu']) : 0;
$this->DATA['nav_menu_count'] = count($this->DATA['nav_menu']);
// messages = ['msg' =>, 'class' => 'error/warning/...']
$this->DATA['messages'] = $cms->messages;
} else { /** @phpstan-ignore-line Because I assume object for phpstan */

View File

@@ -27,6 +27,7 @@ return array(
'CoreLibs\\Convert\\Math' => $baseDir . '/lib/CoreLibs/Convert/Math.php',
'CoreLibs\\Convert\\MimeAppName' => $baseDir . '/lib/CoreLibs/Convert/MimeAppName.php',
'CoreLibs\\Convert\\MimeEncode' => $baseDir . '/lib/CoreLibs/Convert/MimeEncode.php',
'CoreLibs\\Convert\\Strings' => $baseDir . '/lib/CoreLibs/Convert/Strings.php',
'CoreLibs\\Create\\Email' => $baseDir . '/lib/CoreLibs/Create/Email.php',
'CoreLibs\\Create\\Hash' => $baseDir . '/lib/CoreLibs/Create/Hash.php',
'CoreLibs\\Create\\RandomKey' => $baseDir . '/lib/CoreLibs/Create/RandomKey.php',

View File

@@ -92,6 +92,7 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9
'CoreLibs\\Convert\\Math' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Math.php',
'CoreLibs\\Convert\\MimeAppName' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/MimeAppName.php',
'CoreLibs\\Convert\\MimeEncode' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/MimeEncode.php',
'CoreLibs\\Convert\\Strings' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Strings.php',
'CoreLibs\\Create\\Email' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Email.php',
'CoreLibs\\Create\\Hash' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Hash.php',
'CoreLibs\\Create\\RandomKey' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/RandomKey.php',