Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cced63c4b | ||
|
|
06c2ea5e0d | ||
|
|
2e9239ec23 | ||
|
|
0c89840dba | ||
|
|
db144493f3 | ||
|
|
5cec54d508 | ||
|
|
8e60c992f1 | ||
|
|
1b5437b675 | ||
|
|
ef80cba561 | ||
|
|
2d71e760e8 | ||
|
|
a8d07634ff | ||
|
|
aa2b60973e | ||
|
|
554dd5f73c | ||
|
|
e6f9559fbb | ||
|
|
770d6f30a4 | ||
|
|
f94f6cbe87 | ||
|
|
9b69390fa2 | ||
|
|
0524d8ac1b | ||
|
|
e933022671 | ||
|
|
c549d34e65 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
.libs
|
||||
node_modules/
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phive xmlns="https://phar.io/phive">
|
||||
<phar name="phpunit" version="^9.6" installed="9.6.19" location="./tools/phpunit" copy="false"/>
|
||||
<phar name="phpcbf" version="^3.7.2" installed="3.9.1" location="./tools/phpcbf" copy="false"/>
|
||||
<phar name="phpcs" version="^3.7.2" installed="3.9.1" location="./tools/phpcs" copy="false"/>
|
||||
<phar name="phpstan" version="^1.10.37" installed="1.10.67" location="./tools/phpstan" copy="false"/>
|
||||
<phar name="phpunit" version="^9.6" installed="9.6.21" location="./tools/phpunit" copy="false"/>
|
||||
<phar name="phpcbf" version="^3.7.2" installed="3.10.3" location="./tools/phpcbf" copy="false"/>
|
||||
<phar name="phpcs" version="^3.7.2" installed="3.10.3" location="./tools/phpcs" copy="false"/>
|
||||
<phar name="phpstan" version="^1.10.37" installed="1.12.4" location="./tools/phpstan" copy="false"/>
|
||||
<phar name="phan" version="^5.4.2" installed="5.4.3" location="./tools/phan" copy="false"/>
|
||||
<phar name="psalm" version="^5.15.0" installed="5.23.1" location="./tools/psalm" copy="false"/>
|
||||
<phar name="psalm" version="^5.15.0" installed="5.24.0" location="./tools/psalm" copy="false"/>
|
||||
<phar name="phpdox" version="^0.12.0" installed="0.12.0" location="./tools/phpdox" copy="false"/>
|
||||
<phar name="phpdocumentor" version="^3.4.2" installed="3.4.3" location="./tools/phpDocumentor" copy="false"/>
|
||||
<phar name="php-cs-fixer" version="^3.34.1" installed="3.53.0" location="./tools/php-cs-fixer" copy="false"/>
|
||||
<phar name="php-cs-fixer" version="^3.34.1" installed="3.57.2" location="./tools/php-cs-fixer" copy="false"/>
|
||||
</phive>
|
||||
|
||||
2
.shellcheckrc
Normal file
2
.shellcheckrc
Normal file
@@ -0,0 +1,2 @@
|
||||
shell=bash
|
||||
external-sources=true
|
||||
@@ -1,19 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
BASE_FOLDER=$(dirname $(readlink -f $0))"/";
|
||||
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
|
||||
# Assume script is in 4dev/bin
|
||||
base_folder="${BASE_FOLDER}../../www/";
|
||||
|
||||
# locale gettext po to mo translator master
|
||||
for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
|
||||
file=$(basename $file .po);
|
||||
for file in "${base_folder}"../4dev/locale/*.po; do
|
||||
[[ -e "$file" ]] || break
|
||||
file=$(basename "$file" .po);
|
||||
locale=$(echo "${file}" | cut -d "-" -f 1);
|
||||
domain=$(echo "${file}" | cut -d "-" -f 2);
|
||||
echo "- Translate language file '${file}' for locale '${locale}' and domain '${domain}':";
|
||||
if [ ! -d "${base_folder}/includes/locale/${locale}/LC_MESSAGES/" ]; then
|
||||
mkdir -p "${base_folder}/includes/locale/${locale}/LC_MESSAGES/";
|
||||
fi;
|
||||
msgfmt -o ${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo ${base_folder}../4dev/locale/${locale}-${domain}.po;
|
||||
msgfmt -o "${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo" "${base_folder}../4dev/locale/${locale}-${domain}.po";
|
||||
done;
|
||||
|
||||
# __END__
|
||||
|
||||
@@ -2,16 +2,18 @@
|
||||
|
||||
# read source mo files and writes target js files in object form
|
||||
|
||||
# check for ARG 1 is "mv"
|
||||
# then move the files directly and don't do manual check (don't create temp files)
|
||||
FILE_MOVE=0;
|
||||
if [ "${1}" = "mv" ]; then
|
||||
# check for ARG 1 is "no-move"
|
||||
# then do not move the files directly for manual check
|
||||
FILE_MOVE=1;
|
||||
if [ "${1}" = "no-move" ]; then
|
||||
echo "+++ CREATE TEMPORARY FILES +++";
|
||||
FILE_MOVE=0;
|
||||
else
|
||||
echo "*** Direct write ***";
|
||||
FILE_MOVE=1;
|
||||
fi;
|
||||
|
||||
target='';
|
||||
BASE_FOLDER=$(dirname $(readlink -f $0))"/";
|
||||
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
|
||||
# Assume script is in 4dev/bin
|
||||
base_folder="${BASE_FOLDER}../../www/";
|
||||
po_folder='../4dev/locale/'
|
||||
@@ -26,7 +28,7 @@ if [ "${target}" == '' ]; then
|
||||
echo "*** Non smarty ***";
|
||||
TEXTDOMAINDIR=${base_folder}${mo_folder}.
|
||||
# default is admin
|
||||
TEXTDOMAIN=admin;
|
||||
TEXTDOMAIN="admin";
|
||||
fi;
|
||||
js_folder="${TEXTDOMAIN}/layout/javascript/";
|
||||
|
||||
@@ -44,15 +46,16 @@ if [ ${error} -eq 1 ]; then
|
||||
fi;
|
||||
|
||||
# locale gettext po to mo translator master
|
||||
for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
|
||||
file=$(basename $file .po);
|
||||
echo "Translate language ${file}";
|
||||
for file in "${base_folder}"../4dev/locale/*.po; do
|
||||
[[ -e "$file" ]] || break
|
||||
file=$(basename "$file" .po);
|
||||
locale=$(echo "${file}" | cut -d "-" -f 1);
|
||||
domain=$(echo "${file}" | cut -d "-" -f 2);
|
||||
echo "- Translate language file '${file}' for locale '${locale}' and domain '${domain}':";
|
||||
if [ ! -d "${base_folder}/includes/locale/${locale}/LC_MESSAGES/" ]; then
|
||||
mkdir -p "${base_folder}/includes/locale/${locale}/LC_MESSAGES/";
|
||||
fi;
|
||||
msgfmt -o ${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo ${base_folder}${po_folder}${locale}-${domain}.po;
|
||||
msgfmt -o "${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo" "${base_folder}${po_folder}${locale}-${domain}.po";
|
||||
done;
|
||||
|
||||
rx_msgid_empty="^msgid \"\"";
|
||||
@@ -62,7 +65,7 @@ rx_msgstr="^msgstr \""
|
||||
# quick copy string at the end
|
||||
quick_copy='';
|
||||
|
||||
for language in ${language_list[*]}; do
|
||||
for language in "${language_list[@]}"; do
|
||||
# I don't know which one must be set, but I think at least LANGUAGE
|
||||
case ${language} in
|
||||
ja)
|
||||
@@ -79,7 +82,8 @@ for language in ${language_list[*]}; do
|
||||
esac;
|
||||
# write only one for language and then symlink files
|
||||
template_file=$(echo ${template_file_stump} | sed -e "s/##SUFFIX##//" | sed -e "s/##LANGUAGE##/${LANG}/");
|
||||
original_file=$(echo ${template_file} | sed -e 's/\.TMP//g');
|
||||
# original_file=$(echo ${template_file} | sed -e 's/\.TMP//g');
|
||||
original_file=${template_file//.TMP/};
|
||||
if [ "${FILE_MOVE}" -eq 0 ]; then
|
||||
file=${target_folder}${template_file};
|
||||
else
|
||||
@@ -88,16 +92,18 @@ for language in ${language_list[*]}; do
|
||||
echo "===> Write translation file ${file}";
|
||||
echo ". = normal, : = escape, x = skip";
|
||||
# init line [aka don't touch this file]
|
||||
echo "// AUTO FILL, changes will be overwritten" > $file;
|
||||
echo "// source: ${suffix}, language: ${language}" >> $file;
|
||||
echo "// Translation strings in the format" >> $file;
|
||||
echo "// \"Original\":\"Translated\""$'\n' >> $file;
|
||||
echo "var i18n = {" >> $file;
|
||||
echo "// AUTO FILL, changes will be overwritten" > "$file";
|
||||
{
|
||||
echo "// source: ${suffix}, language: ${language}";
|
||||
echo "// Translation strings in the format";
|
||||
echo "// \"Original\":\"Translated\""$'\n'
|
||||
echo "var i18n = {"
|
||||
} >> "$file"
|
||||
# translations stuff
|
||||
# read the po file
|
||||
pos=0; # do we add a , for the next line
|
||||
cat "${base_folder}${po_folder}${language}-${TEXTDOMAIN}.po" |
|
||||
while read str; do
|
||||
while read -r str; do
|
||||
# echo "S: ${str}";
|
||||
# skip empty
|
||||
if [[ "${str}" =~ ${rx_msgid_empty} ]]; then
|
||||
@@ -112,12 +118,13 @@ for language in ${language_list[*]}; do
|
||||
str_source=$(echo "${str}" | sed -e "s/^msgid \"//" | sed -e "s/\"$//");
|
||||
# close right side, if not last add ,
|
||||
if [ "${pos}" -eq 1 ]; then
|
||||
echo -n "," >> $file;
|
||||
echo -n "," >> "$file";
|
||||
fi;
|
||||
# all " inside string need to be escaped
|
||||
str_source=$(echo "${str_source}" | sed -e 's/"/\\"/g');
|
||||
# str_source=$(echo "${str_source}" | sed -e 's/"/\\"/g');
|
||||
str_source=${str_source//\"/\\\"}
|
||||
# fix with proper layout
|
||||
echo -n "\"$str_source\":\"$(TEXTDOMAINDIR=${TEXTDOMAINDIR} LANGUAGE=${language} LANG=${LANG} gettext ${TEXTDOMAIN} "${str_source}")\"" >> $file;
|
||||
echo -n "\"$str_source\":\"$(TEXTDOMAINDIR=${TEXTDOMAINDIR} LANGUAGE=${language} LANG=${LANG} gettext "${TEXTDOMAIN}" "${str_source}")\"" >> "$file";
|
||||
pos=1;
|
||||
elif [[ "${str}" =~ ${rx_msgstr} ]]; then
|
||||
# open right side (ignore)
|
||||
@@ -128,8 +135,8 @@ for language in ${language_list[*]}; do
|
||||
fi;
|
||||
done;
|
||||
|
||||
echo "" >> $file;
|
||||
echo "};" >> $file;
|
||||
echo "" >> "$file";
|
||||
echo "};" >> "$file";
|
||||
echo " [DONE]";
|
||||
|
||||
# on no move
|
||||
@@ -140,19 +147,19 @@ for language in ${language_list[*]}; do
|
||||
fi;
|
||||
|
||||
# symlink to master file
|
||||
for suffix in ${source_list[*]}; do
|
||||
for suffix in "${source_list[@]}"; do
|
||||
# symlink with full lang name
|
||||
symlink_file[0]=$(echo ${template_file_stump} | sed -e "s/##SUFFIX##/${suffix}_/" | sed -e "s/##LANGUAGE##/${LANG}/" | sed -e 's/\.TMP//g');
|
||||
# create second one with lang (no country) + encoding
|
||||
symlink_file[1]=$(echo ${template_file_stump} | sed -e "s/##SUFFIX##/${suffix}_/" | sed -e "s/##LANGUAGE##/${LANGUAGE}\.${ENCODING}/" | sed -e 's/\.TMP//g');
|
||||
for template_file in ${symlink_file[@]}; do
|
||||
for template_file in "${symlink_file[@]}"; do
|
||||
# if this is not symlink, create them
|
||||
if [ ! -h "${template_file}" ]; then
|
||||
echo "Create symlink: ${template_file}";
|
||||
# symlik to original
|
||||
cd "${target_folder}";
|
||||
cd "${target_folder}" || exit;
|
||||
ln -sf "${original_file}" "${template_file}";
|
||||
cd - >/dev/null;
|
||||
cd - >/dev/null || exit;
|
||||
fi;
|
||||
done;
|
||||
done;
|
||||
|
||||
@@ -12,7 +12,7 @@ if [ "${1}" = "t" ] || [ "${2}" = "t" ]; then
|
||||
opt_testdox="--testdox";
|
||||
fi;
|
||||
php_bin="";
|
||||
if [ ! -z "${1}" ]; then
|
||||
if [ -n "${1}" ]; then
|
||||
case "${1}" in
|
||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||
# "7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
@@ -23,7 +23,7 @@ if [ ! -z "${1}" ]; then
|
||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||
esac;
|
||||
fi;
|
||||
if [ ! -z "${2}" ] && [ -z "${php_bin}" ]; then
|
||||
if [ -n "${2}" ] && [ -z "${php_bin}" ]; then
|
||||
case "${2}" in
|
||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||
# "7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
|
||||
@@ -13,6 +13,8 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class CoreLibsConvertStringsTest extends TestCase
|
||||
{
|
||||
private const DATA_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -330,6 +332,52 @@ final class CoreLibsConvertStringsTest extends TestCase
|
||||
\CoreLibs\Convert\Strings::stripMultiplePathSlashes($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerStripUTF8BomBytes(): array
|
||||
{
|
||||
return [
|
||||
"utf8-bom" => [
|
||||
"file" => "UTF8BOM.csv",
|
||||
"expect" => "Asset Type,Epic,File Name\n",
|
||||
],
|
||||
"utf8" => [
|
||||
"file" => "UTF8.csv",
|
||||
"expect" => "Asset Type,Epic,File Name\n",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test utf8 bom remove
|
||||
*
|
||||
* @covers ::stripUTF8BomBytes
|
||||
* @dataProvider providerStripUTF8BomBytes
|
||||
* @testdox stripUTF8BomBytes $file will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testStripUTF8BomBytes(string $file, string $expected): void
|
||||
{
|
||||
// load sample file
|
||||
if (!is_file(self::DATA_FOLDER . $file)) {
|
||||
$this->markTestSkipped('File: ' . $file . ' could not be opened');
|
||||
}
|
||||
$file = file_get_contents(self::DATA_FOLDER . $file);
|
||||
if ($file === false) {
|
||||
$this->markTestSkipped('File: ' . $file . ' could not be read');
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Strings::stripUTF8BomBytes($file)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
1
4dev/tests/Convert/data/UTF8.csv
Normal file
1
4dev/tests/Convert/data/UTF8.csv
Normal file
@@ -0,0 +1 @@
|
||||
Asset Type,Epic,File Name
|
||||
|
1
4dev/tests/Convert/data/UTF8BOM.csv
Normal file
1
4dev/tests/Convert/data/UTF8BOM.csv
Normal file
@@ -0,0 +1 @@
|
||||
Asset Type,Epic,File Name
|
||||
|
@@ -216,6 +216,29 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::getIpAddresses
|
||||
* @testdox getIpAddresses check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetIpAddresses()
|
||||
{
|
||||
// response must have "REMOTE_ADDR" entry, others are optional
|
||||
// NOTE: we have no IP addresses on command line
|
||||
$this->assertTrue(
|
||||
true,
|
||||
"We do not have REMOTE_ADDR on command line"
|
||||
);
|
||||
// $this->assertContains(
|
||||
// 'REMOTE_ADDR',
|
||||
// array_keys(\CoreLibs\Get\System::getIpAddresses()),
|
||||
// 'failed REMOTE_ADDR assert'
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -39,6 +39,11 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'OK',
|
||||
'expected' => 'ok',
|
||||
],
|
||||
'success' => [
|
||||
'level' => 'success',
|
||||
'str' => 'SUCCESS',
|
||||
'expected' => 'success',
|
||||
],
|
||||
'info' => [
|
||||
'level' => 'info',
|
||||
'str' => 'INFO',
|
||||
@@ -225,6 +230,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'ERROR MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ERROR> ERROR MESSAGE',
|
||||
],
|
||||
'error, logged' => [
|
||||
@@ -233,6 +239,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'ERROR MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => true,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ERROR> ERROR MESSAGE',
|
||||
],
|
||||
'error, logged, message' => [
|
||||
@@ -241,14 +248,43 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'ERROR MESSAGE',
|
||||
'message' => 'OTHER ERROR MESSAGE',
|
||||
'log_error' => true,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ERROR> OTHER ERROR MESSAGE',
|
||||
],
|
||||
'warn, not logged' => [
|
||||
'id' => '300',
|
||||
'level' => 'warn',
|
||||
'str' => 'WARNING MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<WARNING> WARNING MESSAGE',
|
||||
],
|
||||
'warn, logged' => [
|
||||
'id' => '300',
|
||||
'level' => 'warn',
|
||||
'str' => 'WARNING MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => true,
|
||||
'expected' => '<WARNING> WARNING MESSAGE',
|
||||
],
|
||||
'warn, logged, message' => [
|
||||
'id' => '300',
|
||||
'level' => 'warn',
|
||||
'str' => 'WARNING MESSAGE',
|
||||
'message' => 'OTHER WARNING MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => true,
|
||||
'expected' => '<WARNING> OTHER WARNING MESSAGE',
|
||||
],
|
||||
'notice' => [
|
||||
'id' => '100',
|
||||
'level' => 'notice',
|
||||
'str' => 'NOTICE MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<NOTICE> NOTICE MESSAGE',
|
||||
],
|
||||
'notice, message' => [
|
||||
@@ -257,6 +293,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'NOTICE MESSAGE',
|
||||
'message' => 'OTHER NOTICE MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<NOTICE> OTHER NOTICE MESSAGE',
|
||||
],
|
||||
'crash' => [
|
||||
@@ -265,6 +302,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'CRASH MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ALERT> CRASH MESSAGE',
|
||||
],
|
||||
'crash, message' => [
|
||||
@@ -273,6 +311,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'CRASH MESSAGE',
|
||||
'message' => 'OTHER CRASH MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ALERT> OTHER CRASH MESSAGE',
|
||||
],
|
||||
'abort' => [
|
||||
@@ -281,6 +320,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'ABORT MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<CRITICAL> ABORT MESSAGE',
|
||||
],
|
||||
'abort, message' => [
|
||||
@@ -289,6 +329,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'ABORT MESSAGE',
|
||||
'message' => 'OTHER ABORT MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<CRITICAL> OTHER ABORT MESSAGE',
|
||||
],
|
||||
'unknown' => [
|
||||
@@ -297,6 +338,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'WRONG LEVEL MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<EMERGENCY> WRONG LEVEL MESSAGE',
|
||||
],
|
||||
'unknown, message' => [
|
||||
@@ -305,6 +347,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'WRONG LEVEL MESSAGE',
|
||||
'message' => 'OTHER WRONG LEVEL MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<EMERGENCY> OTHER WRONG LEVEL MESSAGE',
|
||||
],
|
||||
];
|
||||
@@ -321,6 +364,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
* @param string $str
|
||||
* @param string|null $message
|
||||
* @param bool|null $log_error
|
||||
* @param bool|null $log_warning
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
@@ -330,6 +374,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
string $str,
|
||||
?string $message,
|
||||
?bool $log_error,
|
||||
?bool $log_warning,
|
||||
string $expected
|
||||
): void {
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
@@ -344,7 +389,8 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
$level,
|
||||
$str,
|
||||
message: $message,
|
||||
log_error: $log_error
|
||||
log_error: $log_error,
|
||||
log_warning: $log_warning
|
||||
);
|
||||
$file_content = '';
|
||||
if (is_file($log->getLogFolder() . $log->getLogFile())) {
|
||||
@@ -358,6 +404,11 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
} elseif ($level == 'warn' && ($log_warning === null || $log_warning === false)) {
|
||||
$this->assertStringNotContainsString(
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
} else {
|
||||
$this->assertStringContainsString(
|
||||
$expected,
|
||||
@@ -377,6 +428,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
* @param string $str
|
||||
* @param string|null $message
|
||||
* @param bool|null $log_error
|
||||
* @param bool|null $log_warning
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
@@ -386,6 +438,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
string $str,
|
||||
?string $message,
|
||||
?bool $log_error,
|
||||
?bool $log_warning,
|
||||
string $expected
|
||||
): void {
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
@@ -400,7 +453,8 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
$level,
|
||||
$str,
|
||||
message: $message,
|
||||
log_error: $log_error
|
||||
log_error: $log_error,
|
||||
log_warning: $log_warning
|
||||
);
|
||||
$file_content = '';
|
||||
if (is_file($log->getLogFolder() . $log->getLogFile())) {
|
||||
@@ -414,6 +468,11 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
} elseif ($level == 'warn' && $log_warning === false) {
|
||||
$this->assertStringNotContainsString(
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
} else {
|
||||
$this->assertStringContainsString(
|
||||
$expected,
|
||||
|
||||
@@ -46,12 +46,34 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
||||
public function testEncryptDecryptSuccess(string $input, string $expected): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
$encrypted = SymmetricEncryption::encrypt($input, $key);
|
||||
$decrypted = SymmetricEncryption::decrypt($encrypted, $key);
|
||||
|
||||
// test class
|
||||
$crypt = new SymmetricEncryption($key);
|
||||
$encrypted = $crypt->encrypt($input);
|
||||
$decrypted = $crypt->decrypt($encrypted);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$decrypted,
|
||||
'Class call',
|
||||
);
|
||||
|
||||
// test indirect
|
||||
$encrypted = SymmetricEncryption::getInstance($key)->encrypt($input);
|
||||
$decrypted = SymmetricEncryption::getInstance($key)->decrypt($encrypted);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$decrypted,
|
||||
'Class Instance call',
|
||||
);
|
||||
|
||||
// test static
|
||||
$encrypted = SymmetricEncryption::encryptKey($input, $key);
|
||||
$decrypted = SymmetricEncryption::decryptKey($encrypted, $key);
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$decrypted
|
||||
$decrypted,
|
||||
'Static call',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -86,10 +108,24 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
||||
public function testEncryptFailed(string $input, string $exception_message): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
$encrypted = SymmetricEncryption::encrypt($input, $key);
|
||||
$wrong_key = CreateKey::generateRandomKey();
|
||||
|
||||
// wrong key in class call
|
||||
$crypt = new SymmetricEncryption($key);
|
||||
$encrypted = $crypt->encrypt($input);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::decrypt($encrypted, $wrong_key);
|
||||
$crypt->setKey($key);
|
||||
$crypt->decrypt($encrypted);
|
||||
|
||||
// class instance
|
||||
$encrypted = SymmetricEncryption::getInstance($key)->encrypt($input);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::getInstance($wrong_key)->decrypt($encrypted);
|
||||
|
||||
// class static
|
||||
$encrypted = SymmetricEncryption::encryptKey($input, $key);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::decryptKey($encrypted, $wrong_key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +143,6 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
||||
'too short hex key' => [
|
||||
'key' => '1cabd5cba9e042f12522f4ff2de5c31d233b',
|
||||
'excpetion_message' => 'Key is not the correct size (must be '
|
||||
. 'SODIUM_CRYPTO_SECRETBOX_KEYBYTES bytes long).'
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -126,13 +161,33 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
||||
*/
|
||||
public function testWrongKey(string $key, string $exception_message): void
|
||||
{
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::encrypt('test', $key);
|
||||
// we must encrypt valid thing first so we can fail with the wrong kjey
|
||||
$enc_key = CreateKey::generateRandomKey();
|
||||
$encrypted = SymmetricEncryption::encrypt('test', $enc_key);
|
||||
|
||||
// class
|
||||
$crypt = new SymmetricEncryption($key);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::decrypt($encrypted, $key);
|
||||
$crypt->encrypt('test');
|
||||
$crypt->setKey($enc_key);
|
||||
$encrypted = $crypt->encrypt('test');
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
$crypt->setKey($key);
|
||||
$crypt->decrypt($encrypted);
|
||||
|
||||
// class instance
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::getInstance($key)->encrypt('test');
|
||||
// we must encrypt valid thing first so we can fail with the wrong key
|
||||
$encrypted = SymmetricEncryption::getInstance($enc_key)->encrypt('test');
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::getInstance($key)->decrypt($encrypted);
|
||||
|
||||
// class static
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::encryptKey('test', $key);
|
||||
// we must encrypt valid thing first so we can fail with the wrong key
|
||||
$encrypted = SymmetricEncryption::encryptKey('test', $enc_key);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::decryptKey($encrypted, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +200,7 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
||||
return [
|
||||
'too short ciphertext' => [
|
||||
'input' => 'short',
|
||||
'exception_message' => 'Invalid ciphertext (too short)'
|
||||
'exception_message' => 'Decipher message failed: '
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -164,8 +219,18 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
||||
public function testWrongCiphertext(string $input, string $exception_message): void
|
||||
{
|
||||
$key = CreateKey::generateRandomKey();
|
||||
// class
|
||||
$crypt = new SymmetricEncryption($key);
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::decrypt($input, $key);
|
||||
$crypt->decrypt($input);
|
||||
|
||||
// class instance
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::getInstance($key)->decrypt($input);
|
||||
|
||||
// class static
|
||||
$this->expectExceptionMessage($exception_message);
|
||||
SymmetricEncryption::decryptKey($input, $key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
includes:
|
||||
- phpstan-conditional.php
|
||||
parameters:
|
||||
tmpDir: /tmp/phpstan-corelibs
|
||||
tmpDir: %currentWorkingDirectory%/tmp/phpstan-corelibs
|
||||
level: 8 # max is now 9
|
||||
checkMissingCallableSignature: true
|
||||
treatPhpDocTypesAsCertain: false
|
||||
|
||||
2
tmp/.gitignore
vendored
Normal file
2
tmp/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
@@ -1 +1 @@
|
||||
/home/clemens/.phive/phars/php-cs-fixer-3.53.0.phar
|
||||
/home/clemens/.phive/phars/php-cs-fixer-3.57.2.phar
|
||||
@@ -1 +1 @@
|
||||
/home/clemens/.phive/phars/phpcbf-3.9.1.phar
|
||||
/home/clemens/.phive/phars/phpcbf-3.10.3.phar
|
||||
@@ -1 +1 @@
|
||||
/home/clemens/.phive/phars/phpcs-3.9.1.phar
|
||||
/home/clemens/.phive/phars/phpcs-3.10.3.phar
|
||||
@@ -1 +1 @@
|
||||
/home/clemens/.phive/phars/phpstan-1.10.67.phar
|
||||
/home/clemens/.phive/phars/phpstan-1.12.4.phar
|
||||
@@ -1 +1 @@
|
||||
/home/clemens/.phive/phars/phpunit-9.6.19.phar
|
||||
/home/clemens/.phive/phars/phpunit-9.6.21.phar
|
||||
@@ -1 +1 @@
|
||||
/home/clemens/.phive/phars/psalm-5.23.1.phar
|
||||
/home/clemens/.phive/phars/psalm-5.24.0.phar
|
||||
@@ -46,7 +46,7 @@ use CoreLibs\Debug\Support;
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: ADMIN BACKEND';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
@@ -55,7 +55,25 @@ print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
print "SETACL[]: <br>";
|
||||
$backend->setACL(['EMPTY' => 'EMPTY']);
|
||||
print "ADBEDITLOG: <br>";
|
||||
$backend->adbEditLog('CLASSTEST-ADMIN', 'Some info string');
|
||||
$backend->adbEditLog('CLASSTEST-ADMIN-BINARY', 'Some info string', 'BINARY');
|
||||
$backend->adbEditLog('CLASSTEST-ADMIN-ZLIB', 'Some info string', 'ZLIB');
|
||||
$backend->adbEditLog('CLASSTEST-ADMIN-SERIAL', 'Some info string', 'SERIAL');
|
||||
$backend->adbEditLog('CLASSTEST-ADMIN-INVALID', 'Some info string', 'INVALID');
|
||||
// test with various
|
||||
$backend->action = 'TEST ACTION';
|
||||
$backend->action_id = 'TEST ACTION ID';
|
||||
$backend->action_yes = 'TEST ACTION YES';
|
||||
$backend->action_flag = 'TEST ACTION FLAG';
|
||||
$backend->action_menu = 'TEST ACTION MENU';
|
||||
$backend->action_loaded = 'TEST ACTION LOADED';
|
||||
$backend->action_value = 'TEST ACTION VALUE';
|
||||
$backend->action_type = 'TEST ACTION TYPE';
|
||||
$backend->action_error = 'TEST ACTION ERROR';
|
||||
$backend->adbEditLog('CLASSTEST-ADMIN-JSON', [
|
||||
"_GET" => $_GET,
|
||||
"_POST" => $_POST,
|
||||
], 'JSON');
|
||||
|
||||
print "ADBTOPMENU(0): " . Support::printAr($backend->adbTopMenu(CONTENT_PATH)) . "<br>";
|
||||
print "ADBMSG: <br>";
|
||||
$backend->adbMsg('info', 'Message: %1$d', [1]);
|
||||
|
||||
@@ -21,7 +21,7 @@ ob_end_flush();
|
||||
use CoreLibs\Combined\ArrayHandler;
|
||||
use CoreLibs\Debug\Support as DgS;
|
||||
use CoreLibs\Convert\SetVarType;
|
||||
use PHPUnit\Framework\Constraint\ArrayHasKey;
|
||||
// use PHPUnit\Framework\Constraint\ArrayHasKey;
|
||||
|
||||
$log = new CoreLibs\Logging\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
@@ -33,7 +33,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: ARRAY HANDLER';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -23,7 +23,7 @@ use CoreLibs\Convert\Byte;
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: AUTOLOADER';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -29,7 +29,7 @@ $byte_class = 'CoreLibs\Convert\Byte';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: BYTE CONVERT';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -29,7 +29,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: CHECK COLORS';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -28,7 +28,7 @@ $db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: CLASS CALLS';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -26,7 +26,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: CONFIG DIRECT';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -26,7 +26,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: CONFIG LINK';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -31,7 +31,7 @@ $color_class = 'CoreLibs\Convert\Colors';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: CONVERT COLORS';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -33,7 +33,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: CREATE EMAIL';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -30,7 +30,7 @@ $datetime_class = 'CoreLibs\Combined\DateTime';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: DATE/TIME';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
@@ -451,6 +451,7 @@ function intervalStringFormatDeprecated(
|
||||
$value = $interval->days;
|
||||
$skip = true;
|
||||
} else {
|
||||
/** @phan-suppress-next-line PhanUndeclaredProperty */
|
||||
$value = $interval->$part;
|
||||
}
|
||||
if ($value == 0 && $skip_last_zero === true) {
|
||||
|
||||
@@ -34,7 +34,7 @@ $db->log->debug('START', '=============================>');
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: DB dbReturn';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title></head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><a href="class_test.db.php">Class Test DB</a></div>';
|
||||
|
||||
@@ -35,7 +35,7 @@ $db->log->debug('START', '=============================>');
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: DB';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title></head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><a href="class_test.db.type.php">Class Test DB row type convert to PHP type</a></div>';
|
||||
|
||||
@@ -20,7 +20,7 @@ $LOG_FILE_ID = 'classTest-db-query-placeholder';
|
||||
ob_end_flush();
|
||||
|
||||
use CoreLibs\Debug\Support;
|
||||
use CoreLibs\DB\Support\ConvertPlaceholder;
|
||||
// use CoreLibs\DB\Support\ConvertPlaceholder;
|
||||
|
||||
$log = new CoreLibs\Logging\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
@@ -33,7 +33,7 @@ $db->log->debug('START', '=============================>');
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: DB QUERY PLACEHOLDER';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -19,7 +19,7 @@ require 'config.php';
|
||||
$LOG_FILE_ID = 'classTest-db-query-placeholders';
|
||||
ob_end_flush();
|
||||
|
||||
use CoreLibs\Debug\Support;
|
||||
// use CoreLibs\Debug\Support;
|
||||
|
||||
$log = new CoreLibs\Logging\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
@@ -32,7 +32,7 @@ $db->log->debug('START', '=============================>');
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: DB QUERY PLACEHOLDERS';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -33,7 +33,7 @@ $db->log->debug('START', '=============================>');
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: DB COLUMN TYPES';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -43,7 +43,7 @@ $debug_logging_class = 'CoreLibs\Debug\LoggingLegacy';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: DEBUG';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -29,7 +29,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: HTML/ELEMENTS';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -35,7 +35,7 @@ $chk_enc = 'CoreLibs\Check\Encoding';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: ENCODING (CHECK/CONVERT/MIME)';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -31,7 +31,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: ENCRYPTION';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
@@ -40,16 +40,33 @@ $key = CreateKey::generateRandomKey();
|
||||
print "Secret Key: " . $key . "<br>";
|
||||
|
||||
$string = "I a some deep secret";
|
||||
$encrypted = SymmetricEncryption::encrypt($string, $key);
|
||||
$decrypted = SymmetricEncryption::decrypt($encrypted, $key);
|
||||
//
|
||||
$crypt = new SymmetricEncryption($key);
|
||||
$encrypted = $crypt->encrypt($string);
|
||||
$decrypted = $crypt->decrypt($encrypted);
|
||||
print "[C] Encrypted: " . $encrypted . "<br>";
|
||||
print "[C] Decrytped: " . $decrypted . "<br>";
|
||||
$encrypted = SymmetricEncryption::getInstance($key)->encrypt($string);
|
||||
$decrypted = SymmetricEncryption::getInstance($key)->decrypt($encrypted);
|
||||
print "[S] Original: " . $string . "<br>";
|
||||
print "[S] Encrypted: " . $encrypted . "<br>";
|
||||
print "[S] Decrytped: " . $decrypted . "<br>";
|
||||
$encrypted = SymmetricEncryption::encryptKey($string, $key);
|
||||
$decrypted = SymmetricEncryption::decryptKey($encrypted, $key);
|
||||
print "[SS] Encrypted: " . $encrypted . "<br>";
|
||||
print "[SS] Decrytped: " . $decrypted . "<br>";
|
||||
|
||||
print "Original: " . $string . "<br>";
|
||||
print "Encrypted: " . $encrypted . "<br>";
|
||||
print "Decrytped: " . $decrypted . "<br>";
|
||||
print "<br>INIT KEY MISSING<br>";
|
||||
try {
|
||||
$crypt = new SymmetricEncryption();
|
||||
$encrypted = $crypt->decrypt($string);
|
||||
} catch (Exception $e) {
|
||||
print("Error: " . $e->getMessage() . "<br>");
|
||||
}
|
||||
|
||||
print "<br>WRONG CIPHERTEXT<br>";
|
||||
try {
|
||||
$decrypted = SymmetricEncryption::decrypt('flupper', $key);
|
||||
$decrypted = SymmetricEncryption::decryptKey('flupper', $key);
|
||||
} catch (Exception $e) {
|
||||
print "Error: " . $e->getMessage() . "<br>";
|
||||
}
|
||||
@@ -57,7 +74,7 @@ try {
|
||||
print "<br>SHORT and WRONG KEY<br>";
|
||||
$key = 'wrong_key';
|
||||
try {
|
||||
$encrypted = SymmetricEncryption::encrypt($string, $key);
|
||||
$encrypted = SymmetricEncryption::encryptKey($string, $key);
|
||||
} catch (Exception $e) {
|
||||
print "Error: " . $e->getMessage() . "<br>";
|
||||
}
|
||||
@@ -65,7 +82,7 @@ try {
|
||||
print "<br>INVALID HEX KEY<br>";
|
||||
$key = '1cabd5cba9e042f12522f4ff2de5c31d233b';
|
||||
try {
|
||||
$encrypted = SymmetricEncryption::encrypt($string, $key);
|
||||
$encrypted = SymmetricEncryption::encryptKey($string, $key);
|
||||
} catch (Exception $e) {
|
||||
print "Error: " . $e->getMessage() . "<br>";
|
||||
}
|
||||
@@ -73,21 +90,10 @@ try {
|
||||
print "<br>WRONG KEY TO DECRYPT<br>";
|
||||
$key = CreateKey::generateRandomKey();
|
||||
$string = "I a some deep secret";
|
||||
$encrypted = SymmetricEncryption::encrypt($string, $key);
|
||||
$key = CreateKey::generateRandomKey();
|
||||
try {
|
||||
$decrypted = SymmetricEncryption::decrypt($encrypted, $key);
|
||||
} catch (Exception $e) {
|
||||
print "Error: " . $e->getMessage() . "<br>";
|
||||
}
|
||||
|
||||
print "<br>WRONG KEY TO DECRYPT<br>";
|
||||
$key = CreateKey::generateRandomKey();
|
||||
$string = "I a some deep secret";
|
||||
$encrypted = SymmetricEncryption::encrypt($string, $key);
|
||||
$encrypted = SymmetricEncryption::encryptKey($string, $key);
|
||||
$key = 'wrong_key';
|
||||
try {
|
||||
$decrypted = SymmetricEncryption::decrypt($encrypted, $key);
|
||||
$decrypted = SymmetricEncryption::decryptKey($encrypted, $key);
|
||||
} catch (Exception $e) {
|
||||
print "Error: " . $e->getMessage() . "<br>";
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: ERROR MSG';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
@@ -45,6 +45,8 @@ $em->setErrorMsg('123', 'error', 'msg this is bad, auto logged if debug');
|
||||
$em->setErrorMsg('123', 'error', 'msg this is bad, auto logged if debug', 'target-id', 'other-style');
|
||||
$em->setErrorMsg('123', 'error', 'msg this is bad, logged always', log_error:true);
|
||||
$em->setErrorMsg('123', 'error', 'msg this is bad, never logged', log_error:false);
|
||||
$em->setErrorMsg('500', 'warning', 'This is perhaps not super good, logged_always', log_warning:true);
|
||||
$em->setErrorMsg('500', 'warning', 'This is perhaps not super good, logged_never', log_warning:false);
|
||||
$em->setErrorMsg('1000', 'info', 'This is good');
|
||||
$em->setErrorMsg('9999', 'abort', 'BAD: This is critical (abort)');
|
||||
$em->setErrorMsg('10-1000', 'wrong', 'Wrong level: This is emergency');
|
||||
@@ -59,6 +61,8 @@ print "ErrorsIds: <pre>" . $log->prAr($em->getErrorIds()) . "</pre>";
|
||||
print "Errors: <pre>" . $log->prAr($em->getErrorMsg()) . "</pre>";
|
||||
print "JumpTargets: <pre>" . $log->prAr($em->getJumpTarget()) . "</pre>";
|
||||
|
||||
print "IS info > ok: " . ml::fromName('info')->isHigherThan(ml::ok) . "<br>";
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
$log->debug('[END]', '==========================================>');
|
||||
|
||||
@@ -28,7 +28,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: FILE';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -31,7 +31,7 @@ $hash_class = 'CoreLibs\Create\Hash';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: HASH';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -35,19 +35,21 @@ $elements_class = 'CoreLibs\Output\Form\Elements';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: HTML/ELEMENTS';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
$string = "Something < = > Other <br> Next line";
|
||||
print "HTMLENT: " . Html::htmlent($string) . ": " . $_html->htmlent($string) . "<br>";
|
||||
$string = "Something < = > Other <br> Next line and Quotes '\"";
|
||||
echo "String: <pre>$string</pre><br>";
|
||||
$log->debug('HTMLENT', Html::htmlent($string));
|
||||
print "HTMLENT: " . Html::htmlent($string) . ": " . $_html->htmlent($string) . " (" . htmlentities($string) . ")<br>";
|
||||
print "REMOVELB: " . Html::htmlent($string) . ": " . $_html->removeLB($string) . "<br>";
|
||||
$date_str = [2021, 5, 1, 11, 10];
|
||||
print "PRINTDATETIME: "
|
||||
. $_elements->printDateTime($date_str[0], $date_str[1], $date_str[2], $date_str[3], $date_str[4]) . "<br>";
|
||||
// STATIC
|
||||
$string = "Something < = > Other <br> Next line";
|
||||
// $string = "Something < = > Other <br> Next line and Quotes '\"";
|
||||
print "S::HTMLENT: " . Html::htmlent($string) . ": " . $html_class::htmlent($string) . "<br>";
|
||||
print "S::REMOVELB: " . Html::htmlent($string) . ": " . $html_class::removeLB($string) . "<br>";
|
||||
$date_str = [2021, 5, 1, 11, 10];
|
||||
@@ -67,8 +69,10 @@ $checked_list = [
|
||||
['foo', ['bar']],
|
||||
];
|
||||
foreach ($checked_list as $check) {
|
||||
print "CHECKED(0): $check[0]: " . Html::checked($check[1], $check[0]) . "<br>";
|
||||
print "CHECKED(1): $check[0]: " . Html::checked($check[1], $check[0], Html::CHECKED) . "<br>";
|
||||
print "CHECKED(0): " . $check[0] . " -> " . print_r($check[1], true) . ": "
|
||||
. Html::checked($check[1], $check[0]) . "<br>";
|
||||
print "CHECKED(1): " . $check[0] . " -> " . print_r($check[1], true) . ": "
|
||||
. Html::checked($check[1], $check[0], Html::CHECKED) . "<br>";
|
||||
}
|
||||
|
||||
// magic link creation test
|
||||
|
||||
@@ -30,7 +30,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: HTML BUILD: BLOCK';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -33,7 +33,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: HTML BUILD';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -30,7 +30,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: HTML BUILD: STRING REPLACE';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -32,7 +32,7 @@ $image_class = 'CoreLibs\Output\Image';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: IMAGE';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -32,7 +32,7 @@ $json_class = 'CoreLibs\Convert\Json';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: JSON';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -20,7 +20,7 @@ ob_end_flush();
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: LANG';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -38,7 +38,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: LOGGING';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -44,7 +44,7 @@ $login->loginMainCall();
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: LOGIN';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -30,7 +30,7 @@ $math_class = 'CoreLibs\Convert\Math';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: MATH';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -29,7 +29,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: MEMORY USAGE';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -27,7 +27,7 @@ $_mime = new CoreLibs\Convert\MimeAppName();
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: MIME';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -74,7 +74,7 @@ $form = new CoreLibs\Output\Form\Generate(
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: FORM GENERATE';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -32,7 +32,7 @@ $password_class = 'CoreLibs\Security\Password';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: PASSWORD';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -63,7 +63,7 @@ $backend->db->dbInfo(true);
|
||||
ob_end_flush();
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS</title><head>";
|
||||
print "<html><head><title>TEST CLASS</title></head>";
|
||||
print "<body>";
|
||||
|
||||
// key: file name, value; name
|
||||
@@ -178,7 +178,7 @@ $log->debug('SOME MARK', 'Some error output');
|
||||
print "EDIT ACCESS ID: " . $backend->edit_access_id . "<br>";
|
||||
if (is_object($login)) {
|
||||
// print "ACL: <br>".$backend->print_ar($login->loginGetAcl())."<br>";
|
||||
$log->debug('ACL', "ACL: " . \CoreLibs\Debug\Support::dumpVar($login->loginGetAcl()));
|
||||
// $log->debug('ACL', "ACL: " . \CoreLibs\Debug\Support::dumpVar($login->loginGetAcl()));
|
||||
// print "DEFAULT ACL: <br>".$backend->print_ar($login->default_acl_list)."<br>";
|
||||
// print "DEFAULT ACL: <br>".$backend->print_ar($login->default_acl_list)."<br>";
|
||||
// $result = array_flip(
|
||||
|
||||
@@ -32,7 +32,7 @@ $phpv_class = 'CoreLibs\Check\PhpVersion';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: PHP VERSION';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -29,7 +29,7 @@ $array_class = 'CoreLibs\Create\RandomKey';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: RANDOM KEY';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -27,7 +27,7 @@ $ref_class = 'CoreLibs\Get\ReadEnvFile';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: READ ENV FILE';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -28,7 +28,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: RUNNING TIME';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -50,7 +50,7 @@ $session = new Session();
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: SESSION';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -50,7 +50,7 @@ $session = new Session();
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: SESSION (READ)';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -47,7 +47,7 @@ $adm->DATA['adm_set'] = 'SET from admin class';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: SMARTY';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
@@ -97,7 +97,7 @@ $smarty->DATA['drop_down_test'] = [
|
||||
'foobar' => 'Foo Bar',
|
||||
];
|
||||
$smarty->DATA['drop_down_test_selected'] = 'bar';
|
||||
$smarty->DATA['drop_down_test_nested'] = [
|
||||
$smarty->DATA['drop_down_test_nested'] = [
|
||||
'' => '選択してください',
|
||||
'4/25(木)' => [
|
||||
'4/25(木) 11:00-11:50' => '4/25(木) 11:00-11:50',
|
||||
|
||||
@@ -23,7 +23,7 @@ $byte_class = 'CoreLibs\Convert\Strings';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: STRINGS CONVERT';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -29,7 +29,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: SYSTEM';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
@@ -41,7 +41,7 @@ print "GETPAGENAME(0): " . System::getPageName() . "<br>";
|
||||
print "GETPAGENAME(1): " . System::getPageName(System::NO_EXTENSION) . "<br>";
|
||||
print "GETPAGENAME(2): " . System::getPageName(System::FULL_PATH) . "<br>";
|
||||
print "System::getPageNameArray():<br>";
|
||||
print "GETPAGENAMEARRAY: " . \CoreLibs\Debug\Support::printAr(System::getPageNameArray()) . "<br>";
|
||||
print "GETPAGENAMEARRAY: " . DgS::printAr(System::getPageNameArray()) . "<br>";
|
||||
// seting errro codes file upload
|
||||
print "System::fileUploadErrorMessage():<br>";
|
||||
print "FILEUPLOADERRORMESSAGE(): " . System::fileUploadErrorMessage(-1) . "<br>";
|
||||
@@ -51,4 +51,6 @@ print "FILEUPLOADERRORMESSAGE(UPLOAD_ERR_CANT_WRITE): "
|
||||
print "System::checkCLI():<br>";
|
||||
print "Are we in an CLI: " . (System::checkCLI() ? 'Yes' : 'No') . "<br>";
|
||||
|
||||
print "Get Addresses: " . DgS::printAr(System::getIpAddresses()) . "<br>";
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
@@ -28,7 +28,7 @@ $token_class = 'CoreLibs\Output\Form\Token';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: FORM TOKEN';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -29,7 +29,7 @@ $uids_class = 'CoreLibs\Create\Uids';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: UIDS';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -30,7 +30,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: CONVERT\VARISTYPE';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* general edit javascript */
|
||||
/* jquery version */
|
||||
|
||||
/* jshint esversion: 6 */
|
||||
/* jshint esversion: 11 */
|
||||
|
||||
/* global i18n */
|
||||
|
||||
@@ -931,7 +931,7 @@ function rel(base) // eslint-disable-line no-unused-vars
|
||||
/**
|
||||
* searches and removes style from css array
|
||||
* @param {Object} _element element to work one
|
||||
* @param {String css style sheet to remove (name)
|
||||
* @param {String} css style sheet to remove (name)
|
||||
* @return {Object} returns full element
|
||||
*/
|
||||
function rcssel(_element, css)
|
||||
|
||||
@@ -26,7 +26,7 @@ $log = new CoreLibs\Logging\Logging([
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: CONFIG DIRECT SUB';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
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>';
|
||||
|
||||
@@ -47,7 +47,7 @@ $l10n = new \CoreLibs\Language\L10n(
|
||||
);
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>GROUP TESTER</title><head>";
|
||||
print "<html><head><title>GROUP TESTER</title></head>";
|
||||
print "<body>";
|
||||
|
||||
print '<form method="post" name="loginlogout">';
|
||||
|
||||
12
www/composer.lock
generated
12
www/composer.lock
generated
@@ -38,16 +38,16 @@
|
||||
},
|
||||
{
|
||||
"name": "gullevek/dotenv",
|
||||
"version": "v2.0.8",
|
||||
"version": "v2.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/gullevek/dotEnv.git",
|
||||
"reference": "e29f9fcd8853a09bb89b0eb8ee555b754ecee36e"
|
||||
"reference": "b9feacaded4e48effff9da7d1173752aef3dc27f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/gullevek/dotEnv/zipball/e29f9fcd8853a09bb89b0eb8ee555b754ecee36e",
|
||||
"reference": "e29f9fcd8853a09bb89b0eb8ee555b754ecee36e",
|
||||
"url": "https://api.github.com/repos/gullevek/dotEnv/zipball/b9feacaded4e48effff9da7d1173752aef3dc27f",
|
||||
"reference": "b9feacaded4e48effff9da7d1173752aef3dc27f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -86,9 +86,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/gullevek/dotEnv/issues",
|
||||
"source": "https://github.com/gullevek/dotEnv/tree/v2.0.8"
|
||||
"source": "https://github.com/gullevek/dotEnv/tree/v2.1.0"
|
||||
},
|
||||
"time": "2023-03-03T00:32:02+00:00"
|
||||
"time": "2024-08-21T02:41:15+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/log",
|
||||
|
||||
@@ -24,35 +24,29 @@ declare(strict_types=1);
|
||||
// ];
|
||||
|
||||
$__LOCAL_CONFIG = [
|
||||
// db config selection
|
||||
'db_host' => 'test',
|
||||
// other db connections
|
||||
// 'db_host_target' => '',
|
||||
// 'db_host_other' => '',
|
||||
// location flagging (test/dev/live) for debug output
|
||||
'location' => 'test',
|
||||
// show DEBUG override
|
||||
'debug_level' => 'debug',
|
||||
// site locale
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
// site encoding
|
||||
'site_encoding' => 'UTF-8',
|
||||
// enable/disable login override
|
||||
'login_enabled' => true
|
||||
];
|
||||
|
||||
// each host has a different db_host
|
||||
$SITE_CONFIG = [
|
||||
// development host
|
||||
'soba.tokyo.tequila.jp' => [
|
||||
// db config selection
|
||||
'db_host' => 'test',
|
||||
// other db connections
|
||||
// 'db_host_target' => '',
|
||||
// 'db_host_other' => '',
|
||||
// location flagging (test/dev/live) for debug output
|
||||
'location' => 'test',
|
||||
// show DEBUG override
|
||||
'debug_level' => 'debug',
|
||||
// site locale
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
// site encoding
|
||||
'site_encoding' => 'UTF-8',
|
||||
// enable/disable login override
|
||||
'login_enabled' => true
|
||||
],
|
||||
'soba.tokyo.tequila.jp' => $__LOCAL_CONFIG,
|
||||
// 'other.host.com' => $__LOCAL_CONFIG
|
||||
'soba.egplusww.jp' => $__LOCAL_CONFIG,
|
||||
'soba-dev.tequila.jp' => $__LOCAL_CONFIG,
|
||||
'soba.tequila.jp' => $__LOCAL_CONFIG,
|
||||
'soba.teq.jp' => $__LOCAL_CONFIG,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||
|
||||
/********************************************************************
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
@@ -11,6 +11,20 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// find trigger name "admin/" or "frontend/" in the getcwd() folder
|
||||
$folder = '';
|
||||
foreach (['admin', 'frontend'] as $_folder) {
|
||||
if (strstr(getcwd() ?: '', DIRECTORY_SEPARATOR . $_folder)) {
|
||||
$folder = $_folder;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if content path is empty, fallback is default
|
||||
if (empty($folder)) {
|
||||
$folder = 'default';
|
||||
}
|
||||
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
|
||||
|
||||
// File and Folder paths
|
||||
// ID is TARGET (first array element)
|
||||
/*$PATHS = [
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php // phpcs:ignore warning
|
||||
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||
|
||||
/********************************************************************
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
@@ -53,19 +53,6 @@ for (
|
||||
\gullevek\dotEnv\DotEnv::readEnvFile(
|
||||
$__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH
|
||||
);
|
||||
// find trigger name "admin/" or "frontend/" in the getcwd() folder
|
||||
$folder = '';
|
||||
foreach (['admin', 'frontend'] as $_folder) {
|
||||
if (strstr(getcwd() ?: '', DIRECTORY_SEPARATOR . $_folder)) {
|
||||
$folder = $_folder;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if content path is empty, fallback is default
|
||||
if (empty($folder)) {
|
||||
$folder = 'default';
|
||||
}
|
||||
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
|
||||
// load master config file that loads all other config files
|
||||
require $__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php';
|
||||
break;
|
||||
|
||||
@@ -31,6 +31,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Admin;
|
||||
|
||||
use CoreLibs\Convert\Json;
|
||||
|
||||
class Backend
|
||||
{
|
||||
// page name
|
||||
@@ -42,7 +44,7 @@ class Backend
|
||||
/** @var array<string> */
|
||||
public array $action_list = [
|
||||
'action', 'action_id', 'action_sub_id', 'action_yes', 'action_flag',
|
||||
'action_menu', 'action_value', 'action_error', 'action_loaded'
|
||||
'action_menu', 'action_value', 'action_type', 'action_error', 'action_loaded'
|
||||
];
|
||||
/** @var string */
|
||||
public string $action;
|
||||
@@ -61,20 +63,31 @@ class Backend
|
||||
/** @var string */
|
||||
public string $action_value;
|
||||
/** @var string */
|
||||
public string $action_type;
|
||||
/** @var string */
|
||||
public string $action_error;
|
||||
|
||||
// ACL array variable if we want to set acl data from outisde
|
||||
/** @var array<mixed> */
|
||||
public array $acl = [];
|
||||
/** @var int */
|
||||
public int $default_acl;
|
||||
|
||||
// queue key
|
||||
/** @var string */
|
||||
public string $queue_key;
|
||||
|
||||
/** @var array<string> list of allowed types for edit log write */
|
||||
private const WRITE_TYPES = ['BINARY', 'BZIP2', 'LZIP', 'STRING', 'SERIAL', 'JSON'];
|
||||
/** @var array<string> list of available write types for log */
|
||||
private array $write_types_available = [];
|
||||
|
||||
// the current active edit access id
|
||||
/** @var int|null */
|
||||
public int|null $edit_access_id;
|
||||
/** @var string */
|
||||
public string $page_name;
|
||||
|
||||
// error/warning/info messages
|
||||
/** @var array<mixed> */
|
||||
public array $messages = [];
|
||||
@@ -84,6 +97,7 @@ class Backend
|
||||
public bool $warning = false;
|
||||
/** @var bool */
|
||||
public bool $info = false;
|
||||
|
||||
// internal lang & encoding vars
|
||||
/** @var string */
|
||||
public string $lang_dir = '';
|
||||
@@ -95,6 +109,7 @@ class Backend
|
||||
public string $domain;
|
||||
/** @var string */
|
||||
public string $encoding;
|
||||
|
||||
/** @var \CoreLibs\Logging\Logging logger */
|
||||
public \CoreLibs\Logging\Logging $log;
|
||||
/** @var \CoreLibs\DB\IO database */
|
||||
@@ -103,6 +118,7 @@ class Backend
|
||||
public \CoreLibs\Language\L10n $l;
|
||||
/** @var \CoreLibs\Create\Session session class */
|
||||
public \CoreLibs\Create\Session $session;
|
||||
|
||||
// smarty publics [end processing in smarty class]
|
||||
/** @var array<mixed> */
|
||||
public array $DATA = [];
|
||||
@@ -117,18 +133,20 @@ class Backend
|
||||
/**
|
||||
* main class constructor
|
||||
*
|
||||
* @param \CoreLibs\DB\IO $db Database connection class
|
||||
* @param \CoreLibs\Logging\Logging $log Logging class
|
||||
* @param \CoreLibs\Create\Session $session Session interface class
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||
* @param int|null $set_default_acl_level Default ACL level
|
||||
* @param \CoreLibs\DB\IO $db Database connection class
|
||||
* @param \CoreLibs\Logging\Logging $log Logging class
|
||||
* @param \CoreLibs\Create\Session $session Session interface class
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||
* @param int|null $set_default_acl_level [default=null] Default ACL level
|
||||
* @param bool $init_action_vars [default=true] If the action vars should be set
|
||||
*/
|
||||
public function __construct(
|
||||
\CoreLibs\DB\IO $db,
|
||||
\CoreLibs\Logging\Logging $log,
|
||||
\CoreLibs\Create\Session $session,
|
||||
\CoreLibs\Language\L10n $l10n,
|
||||
?int $set_default_acl_level = null
|
||||
?int $set_default_acl_level = null,
|
||||
bool $init_action_vars = true
|
||||
) {
|
||||
// attach db class
|
||||
$this->db = $db;
|
||||
@@ -151,9 +169,9 @@ class Backend
|
||||
// set the page name
|
||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||
|
||||
// set the action ids
|
||||
foreach ($this->action_list as $_action) {
|
||||
$this->$_action = $_POST[$_action] ?? '';
|
||||
// NOTE: if any of the "action" vars are used somewhere, it is recommended to NOT set them here
|
||||
if ($init_action_vars) {
|
||||
$this->adbSetActionVars();
|
||||
}
|
||||
|
||||
if ($set_default_acl_level === null) {
|
||||
@@ -170,9 +188,12 @@ class Backend
|
||||
}
|
||||
|
||||
// queue key
|
||||
if (preg_match("/^(add|save|delete|remove|move|up|down|push_live)$/", $this->action)) {
|
||||
if (preg_match("/^(add|save|delete|remove|move|up|down|push_live)$/", $this->action ?? '')) {
|
||||
$this->queue_key = \CoreLibs\Create\RandomKey::randomKeyGen(3);
|
||||
}
|
||||
|
||||
// check what edit log data write types are allowed
|
||||
$this->adbSetEditLogWriteTypeAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,7 +204,26 @@ class Backend
|
||||
// NO OP
|
||||
}
|
||||
|
||||
// PUBLIC METHODS |=================================================>
|
||||
// MARK: PRIVATE METHODS
|
||||
|
||||
/**
|
||||
* set the write types that are allowed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function adbSetEditLogWriteTypeAvailable()
|
||||
{
|
||||
// check what edit log data write types are allowed
|
||||
$this->write_types_available = self::WRITE_TYPES;
|
||||
if (!function_exists('bzcompress')) {
|
||||
$this->write_types_available = array_diff($this->write_types_available, ['BINARY', 'BZIP']);
|
||||
}
|
||||
if (!function_exists('gzcompress')) {
|
||||
$this->write_types_available = array_diff($this->write_types_available, ['LZIP']);
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: PUBLIC METHODS |=================================================>
|
||||
|
||||
/**
|
||||
* set internal ACL from login ACL
|
||||
@@ -195,30 +235,83 @@ class Backend
|
||||
$this->acl = $acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current set ACL
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function adbGetAcl(): array
|
||||
{
|
||||
return $this->acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set _POST action vars if needed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function adbSetActionVars()
|
||||
{
|
||||
// set the action ids
|
||||
foreach ($this->action_list as $_action) {
|
||||
$this->$_action = $_POST[$_action] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* writes all action vars plus other info into edit_log table
|
||||
*
|
||||
* @param string $event any kind of event description,
|
||||
* @param string|array<mixed> $data any kind of data related to that event
|
||||
* @param string $write_type write type can bei STRING or BINARY
|
||||
* @param string|null $db_schema override target schema
|
||||
* @param string $event [default=''] any kind of event description,
|
||||
* @param string|array<mixed> $data [default=''] any kind of data related to that event
|
||||
* @param string $write_type [default=JSON] write type can be
|
||||
* JSON, STRING/SERIEAL, BINARY/BZIP or ZLIB
|
||||
* @param string|null $db_schema [default=null] override target schema
|
||||
* @return void
|
||||
*/
|
||||
public function adbEditLog(
|
||||
string $event = '',
|
||||
string|array $data = '',
|
||||
string $write_type = 'STRING',
|
||||
string $write_type = 'JSON',
|
||||
?string $db_schema = null
|
||||
): void {
|
||||
$data_binary = '';
|
||||
$data_write = '';
|
||||
if ($write_type == 'BINARY') {
|
||||
$data_binary = $this->db->dbEscapeBytea((string)bzcompress(serialize($data)));
|
||||
$data_write = 'see bzip compressed data_binary field';
|
||||
// check if write type is valid, if not fallback to JSON
|
||||
if (!in_array($write_type, $this->write_types_available)) {
|
||||
$this->log->warning('Write type not in allowed array, fallback to JSON', context:[
|
||||
"write_type" => $write_type,
|
||||
"write_list" => $this->write_types_available,
|
||||
]);
|
||||
$write_type = 'JSON';
|
||||
}
|
||||
if ($write_type == 'STRING') {
|
||||
$data_binary = '';
|
||||
$data_write = $this->db->dbEscapeString(serialize($data));
|
||||
switch ($write_type) {
|
||||
case 'BINARY':
|
||||
case 'BZIP':
|
||||
$data_binary = $this->db->dbEscapeBytea((string)bzcompress(serialize($data)));
|
||||
$data_write = 'see bzip compressed data_binary field';
|
||||
break;
|
||||
case 'ZLIB':
|
||||
$data_binary = $this->db->dbEscapeBytea((string)gzcompress(serialize($data)));
|
||||
$data_write = 'see zlib compressed data_binary field';
|
||||
break;
|
||||
case 'STRING':
|
||||
case 'SERIAL':
|
||||
$data_binary = '';
|
||||
$data_write = serialize($data);
|
||||
break;
|
||||
case 'JSON':
|
||||
$data_binary = '';
|
||||
// must be converted to array
|
||||
if (!is_array($data)) {
|
||||
$data = ["data" => $data];
|
||||
}
|
||||
$data_write = Json::jsonConvertArrayTo($data);
|
||||
break;
|
||||
default:
|
||||
$this->log->alert('Invalid type for data compression was set', context:[
|
||||
"write_type" => $write_type
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
/** @var string $DB_SCHEMA check schema */
|
||||
@@ -228,44 +321,62 @@ class Backend
|
||||
} elseif (!empty($this->db->dbGetSchema())) {
|
||||
$DB_SCHEMA = $this->db->dbGetSchema();
|
||||
}
|
||||
$q = "INSERT INTO " . $DB_SCHEMA . ".edit_log "
|
||||
. "(euid, event_date, event, data, data_binary, page, "
|
||||
. "ip, user_agent, referer, script_name, query_string, server_name, http_host, "
|
||||
. "http_accept, http_accept_charset, http_accept_encoding, session_id, "
|
||||
. "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) "
|
||||
. "VALUES "
|
||||
. "(" . $this->db->dbEscapeString(isset($_SESSION['EUID']) && is_numeric($_SESSION['EUID']) ?
|
||||
$_SESSION['EUID'] :
|
||||
'NULL')
|
||||
. ", "
|
||||
. "NOW(), "
|
||||
. "'" . $this->db->dbEscapeString((string)$event) . "', "
|
||||
. "'" . $data_write . "', "
|
||||
. "'" . $data_binary . "', "
|
||||
. "'" . $this->db->dbEscapeString((string)$this->page_name) . "', "
|
||||
. "'" . ($_SERVER["REMOTE_ADDR"] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_USER_AGENT'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_REFERER'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['SCRIPT_FILENAME'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['QUERY_STRING'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['SERVER_NAME'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_HOST'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_ACCEPT'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_ACCEPT_CHARSET'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_ACCEPT_ENCODING'] ?? '') . "', "
|
||||
. ($this->session->getSessionId() === false ?
|
||||
"NULL" :
|
||||
"'" . $this->session->getSessionId() . "'")
|
||||
. ", "
|
||||
. "'" . $this->db->dbEscapeString($this->action) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_id) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_yes) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_flag) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_menu) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_loaded) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_value) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_error) . "')";
|
||||
$this->db->dbExec($q, 'NULL');
|
||||
$q = <<<SQL
|
||||
INSERT INTO {DB_SCHEMA}.edit_log (
|
||||
euid, event_date, event, data, data_binary, page,
|
||||
ip, user_agent, referer, script_name, query_string, server_name, http_host,
|
||||
http_accept, http_accept_charset, http_accept_encoding, session_id,
|
||||
action, action_id, action_yes, action_flag, action_menu, action_loaded,
|
||||
action_value, action_type, action_error
|
||||
) VALUES (
|
||||
$1, NOW(), $2, $3, $4, $5,
|
||||
$6, $7, $8, $9, $10, $11, $12,
|
||||
$13, $14, $15, $16,
|
||||
$17, $18, $19, $20, $21, $22,
|
||||
$23, $24, $25
|
||||
)
|
||||
SQL;
|
||||
$this->db->dbExecParams(
|
||||
str_replace(
|
||||
['{DB_SCHEMA}'],
|
||||
[$DB_SCHEMA],
|
||||
$q
|
||||
),
|
||||
[
|
||||
// row 1
|
||||
isset($_SESSION['EUID']) && is_numeric($_SESSION['EUID']) ?
|
||||
$_SESSION['EUID'] : null,
|
||||
(string)$event,
|
||||
$data_write,
|
||||
$data_binary,
|
||||
(string)$this->page_name,
|
||||
// row 2
|
||||
$_SERVER["REMOTE_ADDR"] ?? '',
|
||||
$_SERVER['HTTP_USER_AGENT'] ?? '',
|
||||
$_SERVER['HTTP_REFERER'] ?? '',
|
||||
$_SERVER['SCRIPT_FILENAME'] ?? '',
|
||||
$_SERVER['QUERY_STRING'] ?? '',
|
||||
$_SERVER['SERVER_NAME'] ?? '',
|
||||
$_SERVER['HTTP_HOST'] ?? '',
|
||||
// row 3
|
||||
$_SERVER['HTTP_ACCEPT'] ?? '',
|
||||
$_SERVER['HTTP_ACCEPT_CHARSET'] ?? '',
|
||||
$_SERVER['HTTP_ACCEPT_ENCODING'] ?? '',
|
||||
$this->session->getSessionId() !== false ?
|
||||
$this->session->getSessionId() : null,
|
||||
// row 4
|
||||
$this->action ?? '',
|
||||
$this->action_id ?? '',
|
||||
$this->action_yes ?? '',
|
||||
$this->action_flag ?? '',
|
||||
$this->action_menu ?? '',
|
||||
$this->action_loaded ?? '',
|
||||
$this->action_value ?? '',
|
||||
$this->action_type ?? '',
|
||||
$this->action_error ?? '',
|
||||
],
|
||||
'NULL'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -504,9 +615,9 @@ class Backend
|
||||
string $data,
|
||||
string $key_name,
|
||||
string $key_value,
|
||||
string $associate = null,
|
||||
string $file = null,
|
||||
string $db_schema = null,
|
||||
?string $associate = null,
|
||||
?string $file = null,
|
||||
?string $db_schema = null,
|
||||
): void {
|
||||
/** @var string $DB_SCHEMA check schema */
|
||||
$DB_SCHEMA = 'public';
|
||||
@@ -515,16 +626,30 @@ class Backend
|
||||
} elseif (!empty($this->db->dbGetSchema())) {
|
||||
$DB_SCHEMA = $this->db->dbGetSchema();
|
||||
}
|
||||
$q = "INSERT INTO " . $DB_SCHEMA . ".live_queue ("
|
||||
. "queue_key, key_value, key_name, type, target, data, group_key, action, associate, file"
|
||||
. ") VALUES ("
|
||||
. "'" . $this->db->dbEscapeString($queue_key) . "', '" . $this->db->dbEscapeString($key_value) . "', "
|
||||
. "'" . $this->db->dbEscapeString($key_name) . "', '" . $this->db->dbEscapeString($type) . "', "
|
||||
. "'" . $this->db->dbEscapeString($target) . "', '" . $this->db->dbEscapeString($data) . "', "
|
||||
. "'" . $this->queue_key . "', '" . $this->action . "', "
|
||||
. "'" . $this->db->dbEscapeString((string)$associate) . "', "
|
||||
. "'" . $this->db->dbEscapeString((string)$file) . "')";
|
||||
$this->db->dbExec($q);
|
||||
$q = <<<SQL
|
||||
INSERT INTO {DB_SCHEMA}.live_queue (
|
||||
queue_key, key_value, key_name, type,
|
||||
target, data, group_key, action, associate, file
|
||||
) VALUES (
|
||||
$1, $2, $3, $4,
|
||||
$5, $6, $7, $8, $9, $10
|
||||
)
|
||||
SQL;
|
||||
// $this->db->dbExec($q);
|
||||
$this->db->dbExecParams(
|
||||
str_replace(
|
||||
['{DB_SCHEMA}'],
|
||||
[$DB_SCHEMA],
|
||||
$q
|
||||
),
|
||||
[
|
||||
$queue_key, $key_value,
|
||||
$key_name, $type,
|
||||
$target, $data,
|
||||
$this->queue_key, $this->action,
|
||||
(string)$associate, (string)$file
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,7 +90,7 @@ class Basic
|
||||
* @deprecated DO NOT USE Class\Basic anymore. Use dedicated logger and sub classes
|
||||
*/
|
||||
public function __construct(
|
||||
\CoreLibs\Logging\Logging $log = null,
|
||||
?\CoreLibs\Logging\Logging $log = null,
|
||||
?string $session_name = null
|
||||
) {
|
||||
trigger_error('Class \CoreLibs\Basic is deprected', E_USER_DEPRECATED);
|
||||
|
||||
@@ -52,7 +52,7 @@ class SetVarTypeMain
|
||||
*/
|
||||
protected static function makeStrMain(
|
||||
mixed $val,
|
||||
string $default = null,
|
||||
?string $default = null,
|
||||
bool $to_null = false
|
||||
): ?string {
|
||||
// int/float/string/bool/null, everything else is ignored
|
||||
@@ -113,7 +113,7 @@ class SetVarTypeMain
|
||||
*/
|
||||
protected static function makeIntMain(
|
||||
mixed $val,
|
||||
int $default = null,
|
||||
?int $default = null,
|
||||
bool $to_null = false
|
||||
): ?int {
|
||||
// if we can filter it to a valid int, we can convert it
|
||||
@@ -167,7 +167,7 @@ class SetVarTypeMain
|
||||
*/
|
||||
protected static function makeFloatMain(
|
||||
mixed $val,
|
||||
float $default = null,
|
||||
?float $default = null,
|
||||
bool $to_null = false
|
||||
): ?float {
|
||||
if (
|
||||
|
||||
@@ -16,16 +16,22 @@ class Html
|
||||
/**
|
||||
* full wrapper for html entities
|
||||
*
|
||||
* uses default params as: ENT_QUOTES | ENT_HTML5
|
||||
* switches from ENT_HTML401 to ENT_HTML5 as we assume all our pages have <!DOCTYPE html>
|
||||
* removed: ENT_SUBSTITUTE -> wrong characters will be replaced with space
|
||||
* encodes in UTF-8
|
||||
* does not double encode
|
||||
*
|
||||
* @param mixed $string string to html encode
|
||||
* @param int $flags [default: ENT_QUOTES | ENT_HTML5]
|
||||
* @return mixed if string, encoded, else as is (eg null)
|
||||
*/
|
||||
public static function htmlent(mixed $string): mixed
|
||||
public static function htmlent(mixed $string, int $flags = ENT_QUOTES | ENT_HTML5): mixed
|
||||
{
|
||||
if (is_string($string)) {
|
||||
return htmlentities($string, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
|
||||
} else {
|
||||
return $string;
|
||||
return htmlentities($string, $flags, 'UTF-8', false);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,14 +60,10 @@ class Html
|
||||
*/
|
||||
public static function checked(array|string $haystack, string $needle, int $type = 0): ?string
|
||||
{
|
||||
if (is_array($haystack)) {
|
||||
if (in_array($needle, $haystack)) {
|
||||
return $type ? 'checked' : 'selected';
|
||||
}
|
||||
} else {
|
||||
if ($haystack == $needle) {
|
||||
return $type ? 'checked' : 'selected';
|
||||
}
|
||||
if (is_array($haystack) && in_array($needle, $haystack)) {
|
||||
return $type ? 'checked' : 'selected';
|
||||
} elseif (!is_array($haystack) && $haystack == $needle) {
|
||||
return $type ? 'checked' : 'selected';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class SetVarTypeNull extends Extends\SetVarTypeMain
|
||||
* @param string|null $default Default override value
|
||||
* @return string|null Input value as string or default as string/null
|
||||
*/
|
||||
public static function makeStr(mixed $val, string $default = null): ?string
|
||||
public static function makeStr(mixed $val, ?string $default = null): ?string
|
||||
{
|
||||
return SetVarTypeMain::makeStrMain($val, $default, true);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ class SetVarTypeNull extends Extends\SetVarTypeMain
|
||||
* @param int|null $default Default override value
|
||||
* @return int|null Input value as int or default as int/null
|
||||
*/
|
||||
public static function makeInt(mixed $val, int $default = null): ?int
|
||||
public static function makeInt(mixed $val, ?int $default = null): ?int
|
||||
{
|
||||
return SetVarTypeMain::makeIntMain($val, $default, true);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class SetVarTypeNull extends Extends\SetVarTypeMain
|
||||
* @param float|null $default Default override value
|
||||
* @return float|null Input value as float or default as float/null
|
||||
*/
|
||||
public static function makeFloat(mixed $val, float $default = null): ?float
|
||||
public static function makeFloat(mixed $val, ?float $default = null): ?float
|
||||
{
|
||||
return SetVarTypeMain::makeFloatMain($val, $default, true);
|
||||
}
|
||||
|
||||
@@ -134,6 +134,18 @@ class Strings
|
||||
$path
|
||||
) ?? $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove UTF8 BOM Byte string from line
|
||||
* Note: this is often found in CSV files exported from Excel at the first row, first element
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
public static function stripUTF8BomBytes(string $text): string
|
||||
{
|
||||
return trim($text, pack('H*', 'EFBBBF'));
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -1324,8 +1324,12 @@ class IO
|
||||
// /s for matching new line in . list
|
||||
// [disabled, we don't used ^ or $] /m for multi line match
|
||||
// Matches in 1:, must be array_filtered to remove empty, count with array_unique
|
||||
$query_split = '[(=,?-]|->|->>|#>|#>>|@>|<@|\?\|\?\&|\|\||#-';
|
||||
preg_match_all(
|
||||
'/(?:\'.*?\')?\s*(?:\?\?|<>|[(=,])\s*(?:\d+|(?:\'.*?\')|(\$[1-9]{1}(?:[0-9]{1,})?))/s',
|
||||
'/'
|
||||
. '(?:\'.*?\')?\s*(?:\?\?|<>|' . $query_split . ')\s*'
|
||||
. '(?:\d+|(?:\'.*?\')|(\$[1-9]{1}(?:[0-9]{1,})?))'
|
||||
. '/s',
|
||||
$query,
|
||||
$match
|
||||
);
|
||||
@@ -1892,7 +1896,12 @@ class IO
|
||||
$matches = [];
|
||||
// compare has =, >, < prefix, and gets stripped
|
||||
// if the rest is not X.Y format then error
|
||||
preg_match("/^([<>=]{1,})(\d{1,})\.(\d{1,})/", $compare, $matches);
|
||||
if (!preg_match("/^([<>=]{1,})(\d{1,})\.(\d{1,})/", $compare, $matches)) {
|
||||
$this->log->error('Could not regex match compare version string', [
|
||||
"compare" => $compare
|
||||
]);
|
||||
return false;
|
||||
}
|
||||
$compare = $matches[1];
|
||||
$to_master = $matches[2];
|
||||
$to_minor = $matches[3];
|
||||
@@ -1904,11 +1913,18 @@ class IO
|
||||
}
|
||||
// db_version can return X.Y.Z
|
||||
// we only compare the first two
|
||||
preg_match(
|
||||
"/^(\d{1,})\.(\d{1,})\.?(\d{1,})?/",
|
||||
$this->dbVersion(),
|
||||
$matches
|
||||
);
|
||||
if (
|
||||
!preg_match(
|
||||
"/^(\d{1,})\.(\d{1,})\.?(\d{1,})?/",
|
||||
$this->dbVersion(),
|
||||
$matches
|
||||
)
|
||||
) {
|
||||
$this->log->error('Could not regex match dbVersion string', [
|
||||
"dbVersion" => $this->dbVersion()
|
||||
]);
|
||||
return false;
|
||||
}
|
||||
$master = $matches[1];
|
||||
$minor = $matches[2];
|
||||
$version = $master . ($minor < 10 ? '0' : '') . $minor;
|
||||
@@ -2398,7 +2414,7 @@ class IO
|
||||
// flag if we have cache data stored at the moment
|
||||
'cached' => false,
|
||||
// when fetch array or cache read returns false
|
||||
// in loop read that means dbReturn retuns false without erro
|
||||
// in loop read that means dbReturn retuns false without error
|
||||
'finished' => false,
|
||||
// read from cache/db (pos == rows)
|
||||
'read_finished' => false,
|
||||
|
||||
@@ -39,9 +39,11 @@ class ConvertPlaceholder
|
||||
): array {
|
||||
$convert_to = strtolower($convert_to);
|
||||
$matches = [];
|
||||
$query_split = '[(=,?-]|->|->>|#>|#>>|@>|<@|\?\|\?\&|\|\||#-';
|
||||
$pattern = '/'
|
||||
// prefix string part, must match towards
|
||||
. '(?:\'.*?\')?\s*(?:\?\?|[(=,])\s*'
|
||||
// seperator for ( = , ? - [and json/jsonb in pg doc section 9.15]
|
||||
. '(?:\'.*?\')?\s*(?:\?\?|' . $query_split . ')\s*'
|
||||
// match for replace part
|
||||
. '(?:'
|
||||
// digit -> ignore
|
||||
@@ -96,7 +98,10 @@ class ConvertPlaceholder
|
||||
$type = 'named';
|
||||
$matches_return = $named_matches;
|
||||
// only check for :named
|
||||
$pattern_replace = '/((?:\'.*?\')?\s*(?:\?\?|[(=,])\s*)(\d+|(?:\'.*?\')|(:\w+))/s';
|
||||
$pattern_replace = '/'
|
||||
. '((?:\'.*?\')?\s*(?:\?\?|' . $query_split . ')\s*)'
|
||||
. '(\d+|(?:\'.*?\')|(:\w+))'
|
||||
. '/s';
|
||||
// 0: full
|
||||
// 1: pre part
|
||||
// 2: keep part UNLESS '3' is set
|
||||
@@ -134,7 +139,10 @@ class ConvertPlaceholder
|
||||
// order and data stays the same
|
||||
$params_new = $params;
|
||||
// only check for ?
|
||||
$pattern_replace = '/((?:\'.*?\')?\s*(?:\?\?|[(=,])\s*)(\d+|(?:\'.*?\')|(?:(?:\?\?)?\s*(\?{1})))/s';
|
||||
$pattern_replace = '/'
|
||||
. '((?:\'.*?\')?\s*(?:\?\?|' . $query_split . ')\s*)'
|
||||
. '(\d+|(?:\'.*?\')|(?:(?:\?\?)?\s*(\?{1})))'
|
||||
. '/s';
|
||||
// 0: full
|
||||
// 1: pre part
|
||||
// 2: keep part UNLESS '3' is set
|
||||
@@ -163,7 +171,10 @@ class ConvertPlaceholder
|
||||
$type = 'numbered';
|
||||
$matches_return = $numbered_matches;
|
||||
// only check for $n
|
||||
$pattern_replace = '/((?:\'.*?\')?\s*(?:\?\?|[(=,])\s*)(\d+|(?:\'.*?\')|(\$[1-9]{1}(?:[0-9]{1,})?))/s';
|
||||
$pattern_replace = '/'
|
||||
. '((?:\'.*?\')?\s*(?:\?\?|' . $query_split . ')\s*)'
|
||||
. '(\d+|(?:\'.*?\')|(\$[1-9]{1}(?:[0-9]{1,})?))'
|
||||
. '/s';
|
||||
// 0: full
|
||||
// 1: pre part
|
||||
// 2: keep part UNLESS '3' is set
|
||||
|
||||
@@ -116,6 +116,29 @@ class System
|
||||
3
|
||||
) === 'cli' ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect all IP addresses
|
||||
* REMOTE_ADDR, HTTP_X_FORWARD_FOR, CLIENT_IP
|
||||
* and retuns them in an array with index of io source
|
||||
* if address source has addresses with "," will add "-array" with these as array block
|
||||
*
|
||||
* @return array<string,string|array<string>>
|
||||
*/
|
||||
public static function getIpAddresses(): array
|
||||
{
|
||||
$ip_addr = [];
|
||||
foreach (['REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR', 'CLIENT_IP'] as $_ip_source) {
|
||||
if (!empty($_SERVER[$_ip_source])) {
|
||||
$ip_addr[$_ip_source] = $_SERVER[$_ip_source];
|
||||
// same level as ARRAY IF there is a , inside
|
||||
if (strstr($_SERVER[$_ip_source], ',') !== false) {
|
||||
$ip_addr[$_ip_source . '-array'] = explode(',', $_SERVER[$_ip_source]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ip_addr;
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -46,7 +46,7 @@ class CachedFileReader extends \CoreLibs\Language\Core\StringReader
|
||||
if (!is_resource($fd)) {
|
||||
$this->error = 3; // Cannot read file, probably permissions
|
||||
} else {
|
||||
$this->fd_str = fread($fd, filesize($filename) ?: 0) ?: '';
|
||||
$this->fd_str = fread($fd, filesize($filename) ?: 1) ?: '';
|
||||
fclose($fd);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -128,7 +128,7 @@ class GetLocale
|
||||
$matches
|
||||
)
|
||||
) {
|
||||
$lang = ($matches['lang'] ?? 'en')
|
||||
$lang = $matches['lang']
|
||||
// add country only if set
|
||||
. (!empty($matches['country']) ? '_' . $matches['country'] : '');
|
||||
} else {
|
||||
@@ -235,7 +235,7 @@ class GetLocale
|
||||
$matches
|
||||
)
|
||||
) {
|
||||
$lang = ($matches['lang'] ?? 'en')
|
||||
$lang = $matches['lang']
|
||||
// add country only if set
|
||||
. (!empty($matches['country']) ? '_' . $matches['country'] : '');
|
||||
} else {
|
||||
|
||||
@@ -24,16 +24,20 @@ class ErrorMessage
|
||||
|
||||
/** @var bool $log_error global flag to log error level message */
|
||||
private bool $log_error = false;
|
||||
/** @var bool $log_warning global flat to log warning level messages */
|
||||
private bool $log_warning = false;
|
||||
|
||||
/**
|
||||
* init ErrorMessage
|
||||
*
|
||||
* @param \CoreLibs\Logging\Logging $log
|
||||
* @param null|bool $log_error [=null], defaults to false if log is not level debug
|
||||
* @param null|bool $log_warning [=null], defaults to false if log is not level debug
|
||||
*/
|
||||
public function __construct(
|
||||
\CoreLibs\Logging\Logging $log,
|
||||
?bool $log_error = null
|
||||
?bool $log_error = null,
|
||||
?bool $log_warning = null
|
||||
) {
|
||||
$this->log = $log;
|
||||
// if log default logging is debug then log_error is default set to true
|
||||
@@ -43,6 +47,13 @@ class ErrorMessage
|
||||
$log_error = $log_error ?? false;
|
||||
}
|
||||
$this->log_error = $log_error;
|
||||
// if log default logging is debug then log_warning is default set to true
|
||||
if ($this->log->loggingLevelIsDebug() && $log_warning === null) {
|
||||
$log_warning = true;
|
||||
} else {
|
||||
$log_warning = $log_warning ?? false;
|
||||
}
|
||||
$this->log_warning = $log_warning;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +92,8 @@ class ErrorMessage
|
||||
* @param array<mixed> $context Additionl info for abort/crash messages
|
||||
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
|
||||
* else set for this call only
|
||||
* @param bool|null $log_warning [=null] log level 'warning' to warning, if null use global,
|
||||
* else set for this call only
|
||||
*/
|
||||
public function setErrorMsg(
|
||||
string $error_id,
|
||||
@@ -93,10 +106,14 @@ class ErrorMessage
|
||||
?string $message = null,
|
||||
array $context = [],
|
||||
?bool $log_error = null,
|
||||
?bool $log_warning = null,
|
||||
): void {
|
||||
if ($log_error === null) {
|
||||
$log_error = $this->log_error;
|
||||
}
|
||||
if ($log_warning === null) {
|
||||
$log_warning = $this->log_warning;
|
||||
}
|
||||
$original_level = $level;
|
||||
$level = MessageLevel::fromName($level)->name;
|
||||
// if not string set, write message string if set, else level/error id
|
||||
@@ -121,6 +138,14 @@ class ErrorMessage
|
||||
'level' => $original_level,
|
||||
], $context));
|
||||
break;
|
||||
case 'warn':
|
||||
if ($log_warning) {
|
||||
$this->log->warning($message ?? $str, array_merge([
|
||||
'id' => $error_id,
|
||||
'level' => $original_level,
|
||||
], $context));
|
||||
}
|
||||
break;
|
||||
case 'error':
|
||||
if ($log_error) {
|
||||
$this->log->error($message ?? $str, array_merge([
|
||||
@@ -169,6 +194,8 @@ class ErrorMessage
|
||||
* @param array<mixed> $context Additionl info for abort/crash messages
|
||||
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
|
||||
* else set for this call only
|
||||
* @param bool|null $log_warning [=null] log level 'warning' to warning, if null use global,
|
||||
* else set for this call only
|
||||
*/
|
||||
public function setMessage(
|
||||
string $level,
|
||||
@@ -181,6 +208,7 @@ class ErrorMessage
|
||||
?string $message = null,
|
||||
array $context = [],
|
||||
?bool $log_error = null,
|
||||
?bool $log_warning = null,
|
||||
): void {
|
||||
$this->setErrorMsg(
|
||||
$error_id ?? '',
|
||||
@@ -192,7 +220,8 @@ class ErrorMessage
|
||||
$jump_target,
|
||||
$message,
|
||||
$context,
|
||||
$log_error
|
||||
$log_error,
|
||||
$log_warning
|
||||
);
|
||||
}
|
||||
|
||||
@@ -314,6 +343,27 @@ class ErrorMessage
|
||||
{
|
||||
return $this->log_error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the log warning flag
|
||||
*
|
||||
* @param bool $flag True to log level warning too, False for do not (Default)
|
||||
* @return void
|
||||
*/
|
||||
public function setFlagLogWarning(bool $flag): void
|
||||
{
|
||||
$this->log_warning = $flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current log error flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getFlagLogWarning(): bool
|
||||
{
|
||||
return $this->log_warning;
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace CoreLibs\Logging\Logger;
|
||||
enum MessageLevel: int
|
||||
{
|
||||
case ok = 100;
|
||||
case success = 150; // special for file uploads
|
||||
case info = 200;
|
||||
case notice = 250;
|
||||
case warn = 300;
|
||||
@@ -30,6 +31,7 @@ enum MessageLevel: int
|
||||
{
|
||||
return match (strtolower($name)) {
|
||||
'ok' => self::ok,
|
||||
'success' => self::success,
|
||||
'info' => self::info,
|
||||
'notice' => self::notice,
|
||||
'warn', 'warning' => self::warn,
|
||||
|
||||
@@ -194,13 +194,13 @@ class Elements
|
||||
"/(mailto:)?(\>)?\b([\w\.-]+)@([\w\.\-]+)\.([a-zA-Z]{2,4})\b(\|([^\||^#]+)(#([^\|]+))?\|)?/",
|
||||
function ($matches) {
|
||||
return self::createEmail(
|
||||
$matches[1] ?? '',
|
||||
$matches[2] ?? '',
|
||||
$matches[3] ?? '',
|
||||
$matches[4] ?? '',
|
||||
$matches[5] ?? '',
|
||||
$matches[1],
|
||||
$matches[2],
|
||||
$matches[3],
|
||||
$matches[4],
|
||||
$matches[5],
|
||||
$matches[7] ?? '',
|
||||
$matches[9] ?? ''
|
||||
$matches[9] ?? '',
|
||||
);
|
||||
},
|
||||
$output
|
||||
|
||||
@@ -21,66 +21,82 @@ use SodiumException;
|
||||
|
||||
class SymmetricEncryption
|
||||
{
|
||||
/** @var SymmetricEncryption self instance */
|
||||
private static SymmetricEncryption $instance;
|
||||
|
||||
/** @var string bin hex key */
|
||||
private string $key = '';
|
||||
|
||||
/**
|
||||
* init class
|
||||
* if key not passed, key must be set with createKey
|
||||
*
|
||||
* @param string|null|null $key
|
||||
*/
|
||||
public function __construct(
|
||||
string|null $key = null
|
||||
) {
|
||||
if ($key != null) {
|
||||
$this->setKey($key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the singleton self object.
|
||||
* For function wrapper use
|
||||
*
|
||||
* @return SymmetricEncryption object
|
||||
*/
|
||||
public static function getInstance(string|null $key = null): self
|
||||
{
|
||||
if (empty(self::$instance)) {
|
||||
self::$instance = new self($key);
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/* ************************************************************************
|
||||
* MARK: PRIVATE
|
||||
* *************************************************************************/
|
||||
|
||||
/**
|
||||
* create key and check validity
|
||||
*
|
||||
* @param string $key The key from which the binary key will be created
|
||||
* @return string Binary key string
|
||||
*/
|
||||
public static function createKey(string $key): string
|
||||
private function createKey(string $key): string
|
||||
{
|
||||
try {
|
||||
$key = CreateKey::hex2bin($key);
|
||||
} catch (SodiumException $e) {
|
||||
throw new \UnexpectedValueException('Invalid hex key');
|
||||
throw new \UnexpectedValueException('Invalid hex key: ' . $e->getMessage());
|
||||
}
|
||||
if (mb_strlen($key, '8bit') !== SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
|
||||
throw new \RangeException(
|
||||
'Key is not the correct size (must be '
|
||||
. 'SODIUM_CRYPTO_SECRETBOX_KEYBYTES bytes long).'
|
||||
. SODIUM_CRYPTO_SECRETBOX_KEYBYTES . ' bytes long).'
|
||||
);
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt a message
|
||||
* Decryption call
|
||||
*
|
||||
* @param string $message Message to encrypt
|
||||
* @param string $key Encryption key (as hex string)
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
* @param string $encrypted Text to decrypt
|
||||
* @param ?string $key Mandatory encryption key, will throw exception if empty
|
||||
* @return string Plain text
|
||||
* @throws \RangeException
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \UnexpectedValueException
|
||||
*/
|
||||
public static function encrypt(string $message, string $key): string
|
||||
private function decryptData(string $encrypted, ?string $key): string
|
||||
{
|
||||
$key = self::createKey($key);
|
||||
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
|
||||
|
||||
$cipher = base64_encode(
|
||||
$nonce
|
||||
. sodium_crypto_secretbox(
|
||||
$message,
|
||||
$nonce,
|
||||
$key
|
||||
)
|
||||
);
|
||||
sodium_memzero($message);
|
||||
sodium_memzero($key);
|
||||
return $cipher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt a message
|
||||
*
|
||||
* @param string $encrypted Message encrypted with safeEncrypt()
|
||||
* @param string $key Encryption key (as hex string)
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function decrypt(string $encrypted, string $key): string
|
||||
{
|
||||
$key = self::createKey($key);
|
||||
if (empty($key)) {
|
||||
throw new \UnexpectedValueException('Key not set');
|
||||
}
|
||||
$key = $this->createKey($key);
|
||||
$decoded = base64_decode($encrypted);
|
||||
$nonce = mb_substr($decoded, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
|
||||
$ciphertext = mb_substr($decoded, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');
|
||||
@@ -93,7 +109,7 @@ class SymmetricEncryption
|
||||
$key
|
||||
);
|
||||
} catch (SodiumException $e) {
|
||||
throw new \UnexpectedValueException('Invalid ciphertext (too short)');
|
||||
throw new \UnexpectedValueException('Decipher message failed: ' . $e->getMessage());
|
||||
}
|
||||
if (!is_string($plain)) {
|
||||
throw new \UnexpectedValueException('Invalid Key');
|
||||
@@ -102,6 +118,117 @@ class SymmetricEncryption
|
||||
sodium_memzero($key);
|
||||
return $plain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt a message
|
||||
*
|
||||
* @param string $message Message to encrypt
|
||||
* @param ?string $key Mandatory encryption key, will throw exception if empty
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
* @throws \RangeException
|
||||
*/
|
||||
private function encryptData(string $message, ?string $key): string
|
||||
{
|
||||
if (empty($this->key) || $key === null) {
|
||||
throw new \UnexpectedValueException('Key not set');
|
||||
}
|
||||
$key = $this->createKey($key);
|
||||
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
|
||||
try {
|
||||
$cipher = base64_encode(
|
||||
$nonce
|
||||
. sodium_crypto_secretbox(
|
||||
$message,
|
||||
$nonce,
|
||||
$key,
|
||||
)
|
||||
);
|
||||
} catch (SodiumException $e) {
|
||||
throw new \UnexpectedValueException("Create encrypted message failed: " . $e->getMessage());
|
||||
}
|
||||
sodium_memzero($message);
|
||||
sodium_memzero($key);
|
||||
return $cipher;
|
||||
}
|
||||
|
||||
/* ************************************************************************
|
||||
* MARK: PUBLIC
|
||||
* *************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* set a new key for encryption
|
||||
*
|
||||
* @param string $key
|
||||
* @return void
|
||||
*/
|
||||
public function setKey(string $key)
|
||||
{
|
||||
if (empty($key)) {
|
||||
throw new \UnexpectedValueException('Key cannot be empty');
|
||||
}
|
||||
$this->key = $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt a message
|
||||
* static version
|
||||
*
|
||||
* @param string $encrypted Message encrypted with safeEncrypt()
|
||||
* @param string $key Encryption key (as hex string)
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
* @throws \RangeException
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \UnexpectedValueException
|
||||
*/
|
||||
public static function decryptKey(string $encrypted, string $key): string
|
||||
{
|
||||
return self::getInstance()->decryptData($encrypted, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypt a message
|
||||
*
|
||||
* @param string $encrypted Message encrypted with safeEncrypt()
|
||||
* @return string
|
||||
* @throws \RangeException
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \UnexpectedValueException
|
||||
*/
|
||||
public function decrypt(string $encrypted): string
|
||||
{
|
||||
return $this->decryptData($encrypted, $this->key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt a message
|
||||
* static version
|
||||
*
|
||||
* @param string $message Message to encrypt
|
||||
* @param string $key Encryption key (as hex string)
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
* @throws \RangeException
|
||||
*/
|
||||
public static function encryptKey(string $message, string $key): string
|
||||
{
|
||||
return self::getInstance()->encryptData($message, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt a message
|
||||
*
|
||||
* @param string $message Message to encrypt
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
* @throws \RangeException
|
||||
*/
|
||||
public function encrypt(string $message): string
|
||||
{
|
||||
return $this->encryptData($message, $this->key);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -19,7 +19,7 @@ use CoreLibs\Template\HtmlBuilder\General\HtmlBuilderExcpetion;
|
||||
class Block
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
* Create Element
|
||||
*
|
||||
* @param string $tag
|
||||
* @param string $id
|
||||
@@ -86,7 +86,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Add multiple elements to the base element
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $base
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} ...$attach
|
||||
@@ -101,7 +101,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Add multiple sub elements to the base element
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $sub
|
||||
@@ -117,7 +117,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Remove all sub element entries
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||
* @return array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}
|
||||
@@ -131,7 +131,7 @@ class Block
|
||||
// CSS Elements
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Add css entry to the css entries
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||
* @param string ...$css
|
||||
@@ -144,7 +144,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Remove a css entry entry from the css array
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||
* @param string ...$css
|
||||
@@ -157,7 +157,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Switch CSS entries
|
||||
* scssel (switch) is not supported
|
||||
* use rcssel -> acssel
|
||||
*
|
||||
@@ -175,7 +175,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Build HTML from the content tree
|
||||
* alias phfo
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $tree
|
||||
@@ -231,7 +231,19 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Alias for phfo
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $tree
|
||||
* @param bool $add_nl [default=false]
|
||||
* @return string
|
||||
*/
|
||||
public static function phfo(array $tree, bool $add_nl = false): string
|
||||
{
|
||||
return self::buildHtml($tree, $add_nl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build HTML elements from an array of elements
|
||||
* alias phfa
|
||||
*
|
||||
* @param array<array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}> $list
|
||||
@@ -248,8 +260,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* wrapper for buildHtmlFromList
|
||||
* alias for buildHtmlFromList
|
||||
*
|
||||
* @param array<array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}> $list array of Elements to build string from
|
||||
* @param bool $add_nl [default=false] Optional output string line break
|
||||
|
||||
@@ -401,7 +401,7 @@ class Element
|
||||
* @param bool $add_nl [default=false] Optional output string line breaks
|
||||
* @return string HTML as string
|
||||
*/
|
||||
public function buildHtml(Element $tree = null, bool $add_nl = false): string
|
||||
public function buildHtml(?Element $tree = null, bool $add_nl = false): string
|
||||
{
|
||||
// print "D01: " . microtime(true) . "<br>";
|
||||
if ($tree === null) {
|
||||
@@ -533,7 +533,7 @@ class Element
|
||||
* @return string build html as string
|
||||
* @deprecated Do not use, use Element->buildHtml() instead
|
||||
*/
|
||||
public static function printHtmlFromObject(Element $tree = null, bool $add_nl = false): string
|
||||
public static function printHtmlFromObject(?Element $tree = null, bool $add_nl = false): string
|
||||
{
|
||||
// nothing ->bad
|
||||
if ($tree === null) {
|
||||
|
||||
@@ -185,7 +185,7 @@ class SmartyExtend extends \Smarty
|
||||
// call basic smarty
|
||||
// or Smarty::__construct();
|
||||
parent::__construct();
|
||||
// iinit lang
|
||||
// init lang
|
||||
$this->l10n = $l10n;
|
||||
// parse and read, legacy stuff
|
||||
$locale = $this->l10n->getLocaleAsArray();
|
||||
@@ -203,7 +203,8 @@ class SmartyExtend extends \Smarty
|
||||
_bind_textdomain_codeset($this->domain, $this->encoding);
|
||||
|
||||
// register smarty variable
|
||||
$this->registerPlugin('modifier', 'getvar', [&$this, 'getTemplateVars']);
|
||||
// $this->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'getvar', [&$this, 'getTemplateVars']);
|
||||
$this->registerPlugin(self::PLUGIN_MODIFIER, 'getvar', [&$this, 'getTemplateVars']);
|
||||
|
||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||
|
||||
|
||||
14
www/vendor/composer/installed.json
vendored
14
www/vendor/composer/installed.json
vendored
@@ -35,17 +35,17 @@
|
||||
},
|
||||
{
|
||||
"name": "gullevek/dotenv",
|
||||
"version": "v2.0.8",
|
||||
"version_normalized": "2.0.8.0",
|
||||
"version": "v2.1.0",
|
||||
"version_normalized": "2.1.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/gullevek/dotEnv.git",
|
||||
"reference": "e29f9fcd8853a09bb89b0eb8ee555b754ecee36e"
|
||||
"reference": "b9feacaded4e48effff9da7d1173752aef3dc27f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/gullevek/dotEnv/zipball/e29f9fcd8853a09bb89b0eb8ee555b754ecee36e",
|
||||
"reference": "e29f9fcd8853a09bb89b0eb8ee555b754ecee36e",
|
||||
"url": "https://api.github.com/repos/gullevek/dotEnv/zipball/b9feacaded4e48effff9da7d1173752aef3dc27f",
|
||||
"reference": "b9feacaded4e48effff9da7d1173752aef3dc27f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -56,7 +56,7 @@
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"phpunit/phpunit": "^9"
|
||||
},
|
||||
"time": "2023-03-03T00:32:02+00:00",
|
||||
"time": "2024-08-21T02:41:15+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
@@ -86,7 +86,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/gullevek/dotEnv/issues",
|
||||
"source": "https://github.com/gullevek/dotEnv/tree/v2.0.8"
|
||||
"source": "https://github.com/gullevek/dotEnv/tree/v2.1.0"
|
||||
},
|
||||
"install-path": "../gullevek/dotenv"
|
||||
},
|
||||
|
||||
6
www/vendor/composer/installed.php
vendored
6
www/vendor/composer/installed.php
vendored
@@ -29,9 +29,9 @@
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'gullevek/dotenv' => array(
|
||||
'pretty_version' => 'v2.0.8',
|
||||
'version' => '2.0.8.0',
|
||||
'reference' => 'e29f9fcd8853a09bb89b0eb8ee555b754ecee36e',
|
||||
'pretty_version' => 'v2.1.0',
|
||||
'version' => '2.1.0.0',
|
||||
'reference' => 'b9feacaded4e48effff9da7d1173752aef3dc27f',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../gullevek/dotenv',
|
||||
'aliases' => array(),
|
||||
|
||||
23
www/vendor/gullevek/dotenv/Readme.md
vendored
23
www/vendor/gullevek/dotenv/Readme.md
vendored
@@ -61,6 +61,29 @@ DOUBLE="I will be used"
|
||||
DOUBLE="This will be ignored"
|
||||
```
|
||||
|
||||
A prefix name can be set with `[PrefixName]`. Tne name rules are like for variables, but spaces
|
||||
are allowed, but will be converted to "_".
|
||||
The prefix is valid from the time set until the next prefix block appears or the file ends.
|
||||
|
||||
Example
|
||||
|
||||
```ini
|
||||
FOO="bar"
|
||||
FOOBAR="bar bar"
|
||||
[SecitonA]
|
||||
FOO="other bar"
|
||||
FOOBAR="other bar bar"
|
||||
```
|
||||
|
||||
Will have environmen variables as
|
||||
|
||||
```php
|
||||
$_ENV["FOO"];
|
||||
$_ENV["FOOBAR"];
|
||||
$_ENV["SecitonA.FOO"];
|
||||
$_ENV["SecitonA.FOOBAR"];
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
### Phan
|
||||
|
||||
13
www/vendor/gullevek/dotenv/src/DotEnv.php
vendored
13
www/vendor/gullevek/dotenv/src/DotEnv.php
vendored
@@ -22,6 +22,9 @@ class DotEnv
|
||||
* if there are two variables with the same name only the first is used
|
||||
* variables are case sensitive
|
||||
*
|
||||
* [] Grouping Block Name as prefix until next or end if set,
|
||||
* space replaced by _, all other var rules apply
|
||||
*
|
||||
* @param string $path Folder to file, default is __DIR__
|
||||
* @param string $env_file What file to load, default is .env
|
||||
* @return int -1 other error
|
||||
@@ -56,10 +59,14 @@ class DotEnv
|
||||
$status = 1;
|
||||
$block = false;
|
||||
$var = '';
|
||||
$prefix_name = '';
|
||||
while ($line = fgets($fp)) {
|
||||
// main match for variable = value part
|
||||
if (preg_match("/^\s*([\w_.]+)\s*=\s*((\"?).*)/", $line, $matches)) {
|
||||
$var = $matches[1];
|
||||
// [] block must be a single line, or it will be ignored
|
||||
if (preg_match("/^\s*\[([\w_.\s]+)\]/", $line, $matches)) {
|
||||
$prefix_name = preg_replace("/\s+/", "_", $matches[1]) . ".";
|
||||
} elseif (preg_match("/^\s*([\w_.]+)\s*=\s*((\"?).*)/", $line, $matches)) {
|
||||
// main match for variable = value part
|
||||
$var = $prefix_name . $matches[1];
|
||||
$value = $matches[2];
|
||||
$quotes = $matches[3];
|
||||
// write only if env is not set yet, and write only the first time
|
||||
|
||||
Reference in New Issue
Block a user