Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c68ebe652 | ||
|
|
31d0cdb8ad | ||
|
|
0f823bd283 | ||
|
|
6385a48824 | ||
|
|
a754d897cf | ||
|
|
4600f8f7bf | ||
|
|
04e4fe46f2 | ||
|
|
c35d3c9324 | ||
|
|
e92a682a8c | ||
|
|
ea07e4b95b | ||
|
|
88178cb08d | ||
|
|
5d98be06be | ||
|
|
183cadb0fd | ||
|
|
2067a6fe1d | ||
|
|
f5b6c639fb | ||
|
|
cde29c0362 | ||
|
|
10234000b7 | ||
|
|
a63a50a412 | ||
|
|
59da10b649 | ||
|
|
b714de498f | ||
|
|
aa11937ab2 | ||
|
|
d64d5f081c | ||
|
|
3085b52714 | ||
|
|
9949a5ef7f | ||
|
|
74ba935e96 | ||
|
|
39a62ed59d | ||
|
|
1379cf1519 | ||
|
|
2d15b78d21 | ||
|
|
92ebdb4b9e |
@@ -8,6 +8,9 @@ for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
|
|||||||
echo "Translate language ${file}";
|
echo "Translate language ${file}";
|
||||||
locale=$(echo "${file}" | cut -d "-" -f 1);
|
locale=$(echo "${file}" | cut -d "-" -f 1);
|
||||||
domain=$(echo "${file}" | cut -d "-" -f 2);
|
domain=$(echo "${file}" | cut -d "-" -f 2);
|
||||||
|
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;
|
done;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
# this list only holds edit_* related table data
|
||||||
# functions
|
# functions
|
||||||
function/set_uid.sql
|
|
||||||
function/set_generic.sql
|
|
||||||
function/random_string.sql
|
function/random_string.sql
|
||||||
function/set_edit_generic.sql
|
function/set_edit_generic.sql
|
||||||
function/edit_set_access_uid.sql
|
function/edit_access_set_uid.sql
|
||||||
|
function/edit_group_set_uid.sql
|
||||||
function/edit_log_partition_insert.sql
|
function/edit_log_partition_insert.sql
|
||||||
|
function/edit_user_set_login_user_id_set_date.sql
|
||||||
# generic tables
|
# generic tables
|
||||||
table/edit_temp_files.sql
|
table/edit_temp_files.sql
|
||||||
table/edit_generic.sql
|
table/edit_generic.sql
|
||||||
|
|||||||
@@ -6,20 +6,25 @@
|
|||||||
#exit;
|
#exit;
|
||||||
|
|
||||||
# if flagged 'y' then it will ask after each import to continue
|
# if flagged 'y' then it will ask after each import to continue
|
||||||
development='y';
|
development='n';
|
||||||
|
# do not import anything, just order flow output
|
||||||
test='n';
|
test='n';
|
||||||
input='';
|
# write to file do not write to DB directly
|
||||||
|
write='y';
|
||||||
# database connection info
|
# database connection info
|
||||||
db='<db name>';
|
db='<db name>';
|
||||||
host='<db host>';
|
host='<db host>';
|
||||||
user='<db user>';
|
user='<db user>';
|
||||||
schema="public";
|
schemas='public';
|
||||||
export PGPASSWORD='';
|
export PGPASSWORD='';
|
||||||
|
|
||||||
# log files
|
# log files
|
||||||
error_file="log/error";
|
error_file='log/error';
|
||||||
output_file="log/output";
|
output_file='log/output';
|
||||||
|
data_file='database_create_data.sql';
|
||||||
|
|
||||||
|
if [ "$write" = 'y' ]; then
|
||||||
|
rm -f "${data_file}";
|
||||||
|
fi;
|
||||||
if [ ! -f ORDER ]; then
|
if [ ! -f ORDER ]; then
|
||||||
echo "Could not find ORDER file";
|
echo "Could not find ORDER file";
|
||||||
exit;
|
exit;
|
||||||
@@ -40,26 +45,37 @@ while read file <&3; do
|
|||||||
if [ -f "$file" ]; then
|
if [ -f "$file" ]; then
|
||||||
for path in "$schemas"; do
|
for path in "$schemas"; do
|
||||||
echo "[+] WORK ON '${file}' @ '${path}'";
|
echo "[+] WORK ON '${file}' @ '${path}'";
|
||||||
|
# skip all on test
|
||||||
if [ "$test" = 'n' ]; then
|
if [ "$test" = 'n' ]; then
|
||||||
echo "=== START [$file] ===>" >> ${error_file};
|
# write to file
|
||||||
psql -U ${user} -h ${host} -f "${file}" ${db} 1>> ${output_file} 2>> ${error_file}
|
if [ "$write" = 'y' ]; then
|
||||||
echo "=== END [$file] ===>" >> ${error_file};
|
echo "-- START: ${file}" >> ${data_file};
|
||||||
fi;
|
cat "${file}" >> ${data_file};
|
||||||
if [ "$development" = "y" ]; then
|
echo "-- END: ${file}" >> ${data_file};
|
||||||
echo "Press 'y' to move to next. Press 'r' to reload last file. ^c to abort";
|
else
|
||||||
fi;
|
# write to DB
|
||||||
while [ "$development" = "y" ] && [ "$input" != "y" ]; do
|
echo "=== START [$file] ===>" >> ${error_file};
|
||||||
read -ep "Continue (y|r|^c): " input;
|
psql -U ${user} -h ${host} -f "${file}" ${db} 1>> ${output_file} 2>> ${error_file}
|
||||||
if [ "$input" = "r" ]; then
|
echo "=== END [$file] ===>" >> ${error_file};
|
||||||
echo "Reload File '${file}' ...";
|
# next wait for dev
|
||||||
if [ "$test" = 'n' ]; then
|
if [ "$development" = "y" ]; then
|
||||||
echo "=== START RELOAD [$file] ===>" >> ${error_file};
|
echo "Press 'y' to move to next. Press 'r' to reload last file. ^c to abort";
|
||||||
psql -U ${user} -h ${host} -f "${file}" ${db} 1>> ${output_file} 2>> ${error_file}
|
|
||||||
echo "=== END RELOAD [$file] ===>" >> ${error_file};
|
|
||||||
fi;
|
fi;
|
||||||
|
# loop run for reload on failed
|
||||||
|
while [ "$development" = "y" ] && [ "$input" != "y" ]; do
|
||||||
|
read -ep "Continue (y|r|^c): " input;
|
||||||
|
if [ "$input" = "r" ]; then
|
||||||
|
echo "Reload File '${file}' ...";
|
||||||
|
if [ "$test" = 'n' ]; then
|
||||||
|
echo "=== START RELOAD [$file] ===>" >> ${error_file};
|
||||||
|
psql -U ${user} -h ${host} -f "${file}" ${db} 1>> ${output_file} 2>> ${error_file}
|
||||||
|
echo "=== END RELOAD [$file] ===>" >> ${error_file};
|
||||||
|
fi;
|
||||||
|
fi;
|
||||||
|
done;
|
||||||
|
input='';
|
||||||
fi;
|
fi;
|
||||||
done;
|
fi;
|
||||||
input='';
|
|
||||||
done;
|
done;
|
||||||
elif [[ ${file::1} != "#" ]]; then
|
elif [[ ${file::1} != "#" ]]; then
|
||||||
echo "[!] COULD NOT FIND FILE: '${file}'";
|
echo "[!] COULD NOT FIND FILE: '${file}'";
|
||||||
|
|||||||
@@ -68,10 +68,11 @@ INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Visitor', 'B0C4B3
|
|||||||
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('User', '1E789E', 1);
|
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('User', '1E789E', 1);
|
||||||
|
|
||||||
-- edit language
|
-- edit language
|
||||||
|
-- short_name = locale without encoding
|
||||||
-- iso_name = encoding
|
-- iso_name = encoding
|
||||||
DELETE FROM edit_language;
|
DELETE FROM edit_language;
|
||||||
INSERT INTO edit_language (long_name, short_name, iso_name, order_number, enabled, lang_default) VALUES ('English', 'en_US', 'UTF-8', 1, 1, 1);
|
INSERT INTO edit_language (long_name, short_name, iso_name, order_number, enabled, lang_default) VALUES ('English', 'en_US', 'UTF-8', 1, 1, 1);
|
||||||
INSERT INTO edit_language (long_name, short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('Japanese', 'ja_JP', 'UTF-8', 2, 1, 0);
|
INSERT INTO edit_language (long_name, short_name, iso_name, order_number, enabled, lang_default) VALUES ('Japanese', 'ja_JP', 'UTF-8', 2, 1, 0);
|
||||||
|
|
||||||
-- edit group
|
-- edit group
|
||||||
DELETE FROM edit_group;
|
DELETE FROM edit_group;
|
||||||
@@ -130,7 +131,7 @@ INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_
|
|||||||
-- inserts admin user so basic users can be created
|
-- inserts admin user so basic users can be created
|
||||||
DELETE FROM edit_user;
|
DELETE FROM edit_user;
|
||||||
INSERT INTO edit_user (username, password, enabled, debug, db_debug, email, protected, admin, edit_language_id, edit_group_id, edit_scheme_id, edit_access_right_id) VALUES ('admin', 'admin', 1, 1, 1, '', 1, 1,
|
INSERT INTO edit_user (username, password, enabled, debug, db_debug, email, protected, admin, edit_language_id, edit_group_id, edit_scheme_id, edit_access_right_id) VALUES ('admin', 'admin', 1, 1, 1, '', 1, 1,
|
||||||
(SELECT edit_language_id FROM edit_language WHERE short_name = 'en'),
|
(SELECT edit_language_id FROM edit_language WHERE short_name = 'en_US'),
|
||||||
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
|
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
|
||||||
(SELECT edit_scheme_id FROM edit_scheme WHERE name = 'Admin'),
|
(SELECT edit_scheme_id FROM edit_scheme WHERE name = 'Admin'),
|
||||||
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
||||||
|
|||||||
1031
4dev/database/database_create_data.sql
Normal file
1031
4dev/database/database_create_data.sql
Normal file
File diff suppressed because it is too large
Load Diff
28
4dev/database/function/edit_access_set_uid.sql
Normal file
28
4dev/database/function/edit_access_set_uid.sql
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
-- add uid add for edit_access table
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION set_edit_access_uid() RETURNS TRIGGER AS
|
||||||
|
$$
|
||||||
|
DECLARE
|
||||||
|
myrec RECORD;
|
||||||
|
v_uid VARCHAR;
|
||||||
|
BEGIN
|
||||||
|
-- skip if NEW.name is not set
|
||||||
|
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
|
||||||
|
-- use NEW.name as base, remove all spaces
|
||||||
|
-- name data is already unique, so we do not need to worry about this here
|
||||||
|
v_uid := REPLACE(NEW.name, ' ', '');
|
||||||
|
IF TG_OP = 'INSERT' THEN
|
||||||
|
-- always set
|
||||||
|
NEW.uid := v_uid;
|
||||||
|
ELSIF TG_OP = 'UPDATE' THEN
|
||||||
|
-- check if not set, then set
|
||||||
|
SELECT INTO myrec t.* FROM edit_access t WHERE edit_access_id = NEW.edit_access_id;
|
||||||
|
IF FOUND THEN
|
||||||
|
NEW.uid := v_uid;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE 'plpgsql';
|
||||||
28
4dev/database/function/edit_group_set_uid.sql
Executable file
28
4dev/database/function/edit_group_set_uid.sql
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
-- add uid add for edit_group table
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION set_edit_group_uid() RETURNS TRIGGER AS
|
||||||
|
$$
|
||||||
|
DECLARE
|
||||||
|
myrec RECORD;
|
||||||
|
v_uid VARCHAR;
|
||||||
|
BEGIN
|
||||||
|
-- skip if NEW.name is not set
|
||||||
|
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
|
||||||
|
-- use NEW.name as base, remove all spaces
|
||||||
|
-- name data is already unique, so we do not need to worry about this here
|
||||||
|
v_uid := REPLACE(NEW.name, ' ', '');
|
||||||
|
IF TG_OP = 'INSERT' THEN
|
||||||
|
-- always set
|
||||||
|
NEW.uid := v_uid;
|
||||||
|
ELSIF TG_OP = 'UPDATE' THEN
|
||||||
|
-- check if not set, then set
|
||||||
|
SELECT INTO myrec t.* FROM edit_group t WHERE edit_group_id = NEW.edit_group_id;
|
||||||
|
IF FOUND THEN
|
||||||
|
NEW.uid := v_uid;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE 'plpgsql';
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
-- add uid add for edit_access table
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION set_edit_access_uid() RETURNS TRIGGER AS
|
|
||||||
$$
|
|
||||||
DECLARE
|
|
||||||
myrec RECORD;
|
|
||||||
v_uid VARCHAR;
|
|
||||||
BEGIN
|
|
||||||
-- skip if NEW.name is not set
|
|
||||||
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
|
|
||||||
-- use NEW.name as base, remove all spaces
|
|
||||||
-- name data is already unique, so we do not need to worry about this here
|
|
||||||
v_uid := REPLACE(NEW.name, ' ', '');
|
|
||||||
IF TG_OP = 'INSERT' THEN
|
|
||||||
-- always set
|
|
||||||
NEW.uid := v_uid;
|
|
||||||
ELSIF TG_OP = 'UPDATE' THEN
|
|
||||||
-- check if not set, then set
|
|
||||||
SELECT INTO myrec t.* FROM edit_access t WHERE edit_access_id = NEW.edit_access_id;
|
|
||||||
IF FOUND THEN
|
|
||||||
NEW.uid := v_uid;
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
RETURN NEW;
|
|
||||||
END;
|
|
||||||
$$
|
|
||||||
LANGUAGE 'plpgsql';
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
-- add uid add for edit_group table
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION set_edit_group_uid() RETURNS TRIGGER AS
|
|
||||||
$$
|
|
||||||
DECLARE
|
|
||||||
myrec RECORD;
|
|
||||||
v_uid VARCHAR;
|
|
||||||
BEGIN
|
|
||||||
-- skip if NEW.name is not set
|
|
||||||
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
|
|
||||||
-- use NEW.name as base, remove all spaces
|
|
||||||
-- name data is already unique, so we do not need to worry about this here
|
|
||||||
v_uid := REPLACE(NEW.name, ' ', '');
|
|
||||||
IF TG_OP = 'INSERT' THEN
|
|
||||||
-- always set
|
|
||||||
NEW.uid := v_uid;
|
|
||||||
ELSIF TG_OP = 'UPDATE' THEN
|
|
||||||
-- check if not set, then set
|
|
||||||
SELECT INTO myrec t.* FROM edit_group t WHERE edit_group_id = NEW.edit_group_id;
|
|
||||||
IF FOUND THEN
|
|
||||||
NEW.uid := v_uid;
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
RETURN NEW;
|
|
||||||
END;
|
|
||||||
$$
|
|
||||||
LANGUAGE 'plpgsql';
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
-- set edit user login_user_id_set_date if login_user_id is set
|
||||||
|
-- NOW() if not empty
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION set_login_user_id_set_date()
|
||||||
|
RETURNS TRIGGER AS
|
||||||
|
$$
|
||||||
|
BEGIN
|
||||||
|
-- if new is not null/empty
|
||||||
|
-- and old one is null or old one different new one
|
||||||
|
-- set NOW()
|
||||||
|
-- if new one is NULL
|
||||||
|
-- set NULL
|
||||||
|
IF
|
||||||
|
NEW.login_user_id IS NOT NULL AND NEW.login_user_id <> '' AND
|
||||||
|
(OLD.login_user_id IS NULL OR NEW.login_user_id <> OLD.login_user_id)
|
||||||
|
THEN
|
||||||
|
NEW.login_user_id_set_date = NOW();
|
||||||
|
NEW.login_user_id_last_revalidate = NOW();
|
||||||
|
ELSIF NEW.login_user_id IS NULL OR NEW.login_user_id = '' THEN
|
||||||
|
NEW.login_user_id_set_date = NULL;
|
||||||
|
NEW.login_user_id_last_revalidate = NULL;
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE 'plpgsql';
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
-- create random string with length X
|
-- create random string with length X
|
||||||
|
|
||||||
CREATE FUNCTION random_string(randomLength int)
|
CREATE FUNCTION random_string(randomLength int)
|
||||||
RETURNS text AS $$
|
RETURNS text AS
|
||||||
|
$$
|
||||||
SELECT array_to_string(
|
SELECT array_to_string(
|
||||||
ARRAY(
|
ARRAY(
|
||||||
SELECT substring(
|
SELECT substring(
|
||||||
@@ -13,6 +14,7 @@ SELECT array_to_string(
|
|||||||
),
|
),
|
||||||
''
|
''
|
||||||
)
|
)
|
||||||
$$ LANGUAGE SQL
|
$$
|
||||||
|
LANGUAGE SQL
|
||||||
RETURNS NULL ON NULL INPUT
|
RETURNS NULL ON NULL INPUT
|
||||||
VOLATILE; -- LEAKPROOF;
|
VOLATILE; -- LEAKPROOF;
|
||||||
|
|||||||
15
4dev/database/function/set_date.sql
Normal file
15
4dev/database/function/set_date.sql
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
-- adds the created or updated date tags
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION set_date()
|
||||||
|
RETURNS TRIGGER AS
|
||||||
|
$$
|
||||||
|
BEGIN
|
||||||
|
IF TG_OP = 'INSERT' THEN
|
||||||
|
NEW.date_created := 'now';
|
||||||
|
ELSIF TG_OP = 'UPDATE' THEN
|
||||||
|
NEW.date_updated := 'now';
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE 'plpgsql';
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
-- adds the created or updated date tags
|
-- adds the created or updated date tags
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION set_edit_generic() RETURNS TRIGGER AS '
|
CREATE OR REPLACE FUNCTION set_edit_generic()
|
||||||
DECLARE
|
RETURNS TRIGGER AS
|
||||||
random_length INT = 12; -- that should be long enough
|
$$
|
||||||
BEGIN
|
DECLARE
|
||||||
IF TG_OP = ''INSERT'' THEN
|
random_length INT = 12; -- that should be long enough
|
||||||
NEW.date_created := ''now'';
|
BEGIN
|
||||||
NEW.cuid := random_string(random_length);
|
IF TG_OP = 'INSERT' THEN
|
||||||
ELSIF TG_OP = ''UPDATE'' THEN
|
NEW.date_created := 'now';
|
||||||
NEW.date_updated := ''now'';
|
NEW.cuid := random_string(random_length);
|
||||||
END IF;
|
ELSIF TG_OP = 'UPDATE' THEN
|
||||||
RETURN NEW;
|
NEW.date_updated := 'now';
|
||||||
END;
|
END IF;
|
||||||
' LANGUAGE 'plpgsql';
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE 'plpgsql';
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
-- adds the created or updated date tags
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION set_generic() RETURNS TRIGGER AS '
|
|
||||||
BEGIN
|
|
||||||
IF TG_OP = ''INSERT'' THEN
|
|
||||||
NEW.date_created := ''now'';
|
|
||||||
ELSIF TG_OP = ''UPDATE'' THEN
|
|
||||||
NEW.date_updated := ''now'';
|
|
||||||
END IF;
|
|
||||||
RETURN NEW;
|
|
||||||
END;
|
|
||||||
' LANGUAGE 'plpgsql';
|
|
||||||
21
4dev/database/function/set_generic_uid.sql
Normal file
21
4dev/database/function/set_generic_uid.sql
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
-- set generic with date and uid combined
|
||||||
|
-- don't use with set_generic/set_uid together
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION set_generic()
|
||||||
|
RETURNS TRIGGER AS
|
||||||
|
$$
|
||||||
|
DECLARE
|
||||||
|
random_length INT = 32; -- long for massive data
|
||||||
|
BEGIN
|
||||||
|
IF TG_OP = 'INSERT' THEN
|
||||||
|
NEW.date_created := 'now';
|
||||||
|
IF NEW.uid IS NULL THEN
|
||||||
|
NEW.uid := random_string(random_length);
|
||||||
|
END IF;
|
||||||
|
ELSIF TG_OP = 'UPDATE' THEN
|
||||||
|
NEW.date_updated := 'now';
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE 'plpgsql';
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
-- adds the created or updated date tags
|
-- adds the created or updated date tags
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION set_uid() RETURNS TRIGGER AS '
|
CREATE OR REPLACE FUNCTION set_uid()
|
||||||
DECLARE
|
RETURNS TRIGGER AS
|
||||||
random_length INT = 32; -- that should be long enough
|
$$
|
||||||
BEGIN
|
DECLARE
|
||||||
IF TG_OP = ''INSERT'' THEN
|
random_length INT = 32; -- that should be long enough
|
||||||
NEW.uid := random_string(random_length);
|
BEGIN
|
||||||
END IF;
|
IF TG_OP = 'INSERT' THEN
|
||||||
RETURN NEW;
|
NEW.uid := random_string(random_length);
|
||||||
END;
|
END IF;
|
||||||
' LANGUAGE 'plpgsql';
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE 'plpgsql';
|
||||||
|
|||||||
@@ -2,15 +2,18 @@
|
|||||||
|
|
||||||
-- OLD, DEPRECATED, use set_generic.sql
|
-- OLD, DEPRECATED, use set_generic.sql
|
||||||
|
|
||||||
-- CREATE OR REPLACE FUNCTION set_generic() RETURNS TRIGGER AS '
|
-- CREATE OR REPLACE FUNCTION set_generic()
|
||||||
-- BEGIN
|
-- RETURNS TRIGGER AS
|
||||||
-- IF TG_OP = ''INSERT'' THEN
|
-- $$
|
||||||
-- NEW.date_created := clock_timestamp();
|
-- BEGIN
|
||||||
-- NEW.user_created := current_user;
|
-- IF TG_OP = 'INSERT' THEN
|
||||||
-- ELSIF TG_OP = ''UPDATE'' THEN
|
-- NEW.date_created := clock_timestamp();
|
||||||
-- NEW.date_updated := clock_timestamp();
|
-- NEW.user_created := current_user;
|
||||||
-- NEW.user_updated := current_user;
|
-- ELSIF TG_OP = 'UPDATE' THEN
|
||||||
-- END IF;
|
-- NEW.date_updated := clock_timestamp();
|
||||||
-- RETURN NEW;
|
-- NEW.user_updated := current_user;
|
||||||
-- END;
|
-- END IF;
|
||||||
-- ' LANGUAGE 'plpgsql';
|
-- RETURN NEW;
|
||||||
|
-- END;
|
||||||
|
-- $$
|
||||||
|
-- LANGUAGE 'plpgsql';
|
||||||
|
|||||||
@@ -18,31 +18,82 @@ CREATE TABLE edit_user (
|
|||||||
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
edit_access_right_id INT NOT NULL,
|
edit_access_right_id INT NOT NULL,
|
||||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
-- username/password
|
||||||
deleted SMALLINT NOT NULL DEFAULT 0,
|
|
||||||
username VARCHAR UNIQUE,
|
username VARCHAR UNIQUE,
|
||||||
password VARCHAR,
|
password VARCHAR,
|
||||||
|
-- name block
|
||||||
first_name VARCHAR,
|
first_name VARCHAR,
|
||||||
last_name VARCHAR,
|
last_name VARCHAR,
|
||||||
first_name_furigana VARCHAR,
|
first_name_furigana VARCHAR,
|
||||||
last_name_furigana VARCHAR,
|
last_name_furigana VARCHAR,
|
||||||
|
-- email
|
||||||
|
email VARCHAR,
|
||||||
|
-- eanbled/deleted flag
|
||||||
|
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||||
|
deleted SMALLINT NOT NULL DEFAULT 0,
|
||||||
|
-- general flags
|
||||||
|
strict SMALLINT DEFAULT 0,
|
||||||
|
locked SMALLINT DEFAULT 0,
|
||||||
|
protected SMALLINT NOT NULL DEFAULT 0,
|
||||||
|
-- legacy, debug flags
|
||||||
debug SMALLINT NOT NULL DEFAULT 0,
|
debug SMALLINT NOT NULL DEFAULT 0,
|
||||||
db_debug SMALLINT NOT NULL DEFAULT 0,
|
db_debug SMALLINT NOT NULL DEFAULT 0,
|
||||||
email VARCHAR,
|
-- is admin user
|
||||||
protected SMALLINT NOT NULL DEFAULT 0,
|
|
||||||
admin SMALLINT NOT NULL DEFAULT 0,
|
admin SMALLINT NOT NULL DEFAULT 0,
|
||||||
|
-- last login log
|
||||||
last_login TIMESTAMP WITHOUT TIME ZONE,
|
last_login TIMESTAMP WITHOUT TIME ZONE,
|
||||||
|
-- login error
|
||||||
login_error_count INT DEFAULT 0,
|
login_error_count INT DEFAULT 0,
|
||||||
login_error_date_last TIMESTAMP WITHOUT TIME ZONE,
|
login_error_date_last TIMESTAMP WITHOUT TIME ZONE,
|
||||||
login_error_date_first TIMESTAMP WITHOUT TIME ZONE,
|
login_error_date_first TIMESTAMP WITHOUT TIME ZONE,
|
||||||
strict SMALLINT DEFAULT 0,
|
-- time locked
|
||||||
locked SMALLINT DEFAULT 0,
|
lock_until TIMESTAMP WITHOUT TIME ZONE,
|
||||||
|
lock_after TIMESTAMP WITHOUT TIME ZONE,
|
||||||
|
-- password change
|
||||||
password_change_date TIMESTAMP WITHOUT TIME ZONE, -- only when password is first set or changed
|
password_change_date TIMESTAMP WITHOUT TIME ZONE, -- only when password is first set or changed
|
||||||
password_change_interval INTERVAL, -- null if no change is needed, or d/m/y time interval
|
password_change_interval INTERVAL, -- null if no change is needed, or d/m/y time interval
|
||||||
password_reset_time TIMESTAMP WITHOUT TIME ZONE, -- when the password reset was requested
|
password_reset_time TIMESTAMP WITHOUT TIME ZONE, -- when the password reset was requested
|
||||||
password_reset_uid VARCHAR, -- the uid to access the password reset page
|
password_reset_uid VARCHAR, -- the uid to access the password reset page
|
||||||
|
-- _GET login id for direct login
|
||||||
|
login_user_id VARCHAR UNIQUE, -- the loginUserId, at least 32 chars
|
||||||
|
login_user_id_set_date TIMESTAMP WITHOUT TIME ZONE, -- when above uid was set
|
||||||
|
login_user_id_last_revalidate TIMESTAMP WITHOUT TIME ZONE, -- when the last login was done with user name and password
|
||||||
|
login_user_id_valid_from TIMESTAMP WITHOUT TIME ZONE, -- if set, from when the above uid is valid
|
||||||
|
login_user_id_valid_until TIMESTAMP WITHOUT TIME ZONE, -- if set, until when the above uid is valid
|
||||||
|
login_user_id_revalidate_after INTERVAL, -- user must login to revalidated loginUserId after set days, 0 for forever
|
||||||
|
login_user_id_locked SMALLINT DEFAULT 0, -- lock for loginUserId, but still allow normal login
|
||||||
|
-- additional ACL json block
|
||||||
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
|
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
|
||||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||||
|
|
||||||
|
-- create unique index
|
||||||
|
-- CREATE UNIQUE INDEX edit_user_login_user_id_key ON edit_user (login_user_id) WHERE login_user_id IS NOT NULL;
|
||||||
|
|
||||||
|
COMMENT ON COLUMN edit_user.username IS 'Login username, must set';
|
||||||
|
COMMENT ON COLUMN edit_user.password IS 'Login password, must set';
|
||||||
|
COMMENT ON COLUMN edit_user.enabled IS 'Login is enabled (master switch)';
|
||||||
|
COMMENT ON COLUMN edit_user.deleted IS 'Login is deleted (master switch), overrides all other';
|
||||||
|
COMMENT ON COLUMN edit_user.strict IS 'If too many failed logins user will be locked, default off';
|
||||||
|
COMMENT ON COLUMN edit_user.locked IS 'Locked from too many wrong password logins';
|
||||||
|
COMMENT ON COLUMN edit_user.protected IS 'User can only be chnaged by admin user';
|
||||||
|
COMMENT ON COLUMN edit_user.debug IS 'Turn debug flag on (legacy)';
|
||||||
|
COMMENT ON COLUMN edit_user.db_debug IS 'Turn DB debug flag on (legacy)';
|
||||||
|
COMMENT ON COLUMN edit_user.admin IS 'If set, this user is SUPER admin';
|
||||||
|
COMMENT ON COLUMN edit_user.last_login IS 'Last succesfull login tiemstamp';
|
||||||
|
COMMENT ON COLUMN edit_user.login_error_count IS 'Number of failed logins, reset on successful login';
|
||||||
|
COMMENT ON COLUMN edit_user.login_error_date_last IS 'Last login error date';
|
||||||
|
COMMENT ON COLUMN edit_user.login_error_date_first IS 'First login error date, reset on successfull login';
|
||||||
|
COMMENT ON COLUMN edit_user.lock_until IS 'Account is locked until this date, <';
|
||||||
|
COMMENT ON COLUMN edit_user.lock_after IS 'Account is locked after this date, >';
|
||||||
|
COMMENT ON COLUMN edit_user.password_change_date IS 'Password was changed on';
|
||||||
|
COMMENT ON COLUMN edit_user.password_change_interval IS 'After how many days the password has to be changed';
|
||||||
COMMENT ON COLUMN edit_user.password_reset_time IS 'When the password reset was requested. For reset page uid valid check';
|
COMMENT ON COLUMN edit_user.password_reset_time IS 'When the password reset was requested. For reset page uid valid check';
|
||||||
COMMENT ON COLUMN edit_user.password_reset_uid IS 'Password reset page uid';
|
COMMENT ON COLUMN edit_user.password_reset_uid IS 'Password reset page uid, one time, invalid after reset successful or time out';
|
||||||
|
COMMENT ON COLUMN edit_user.login_user_id IS 'Min 32 character UID to be used to login without password. Via GET/POST parameter';
|
||||||
|
COMMENT ON COLUMN edit_user.login_user_id_set_date IS 'loginUserId was set at what date';
|
||||||
|
COMMENT ON COLUMN edit_user.login_user_id_last_revalidate IS 'set when username/password login is done and loginUserId is set';
|
||||||
|
COMMENT ON COLUMN edit_user.login_user_id_valid_from IS 'loginUserId is valid from this date, >=';
|
||||||
|
COMMENT ON COLUMN edit_user.login_user_id_valid_until IS 'loginUserId is valid until this date, <=';
|
||||||
|
COMMENT ON COLUMN edit_user.login_user_id_revalidate_after IS 'If set to a number greater 0 then user must login after given amount of days to revalidate the loginUserId, set to 0 for valid forver';
|
||||||
|
COMMENT ON COLUMN edit_user.login_user_id_locked IS 'A separte lock flag for loginUserId, user can still login normal';
|
||||||
|
COMMENT ON COLUMN edit_user.additional_acl IS 'Additional Access Control List stored in JSON format';
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
-- AUTHOR: Clemens Schwaighofer
|
-- AUTHOR: Clemens Schwaighofer
|
||||||
-- DATE: 2005/07/05
|
-- DATE: 2005/07/05
|
||||||
-- DESCRIPTION:
|
-- DESCRIPTION:
|
||||||
-- cms tables; generic basic table
|
-- generic basic table with date and uid column
|
||||||
-- TABLE: generic
|
-- TABLE: generic
|
||||||
-- HISTORY:
|
-- HISTORY:
|
||||||
|
|
||||||
-- DROP TABLE edit_generic;
|
-- DROP TABLE generic;
|
||||||
CREATE TABLE generic (
|
CREATE TABLE generic (
|
||||||
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
|
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
|
||||||
date_updated TIMESTAMP WITHOUT TIME ZONE
|
date_updated TIMESTAMP WITHOUT TIME ZONE,
|
||||||
|
uid VARCHAR
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_access ON edit_access;
|
-- DROP TRIGGER IF EXISTS trg_edit_access ON edit_access;
|
||||||
CREATE TRIGGER trg_edit_access
|
CREATE TRIGGER trg_edit_access
|
||||||
BEFORE INSERT OR UPDATE ON edit_access
|
BEFORE INSERT OR UPDATE ON edit_access
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|
||||||
DROP TRIGGER IF EXISTS trg_set_edit_access_uid ON edit_access;
|
-- DROP TRIGGER IF EXISTS trg_set_edit_access_uid ON edit_access;
|
||||||
CREATE TRIGGER trg_set_edit_access_uid
|
CREATE TRIGGER trg_set_edit_access_uid
|
||||||
BEFORE INSERT OR UPDATE ON edit_access
|
BEFORE INSERT OR UPDATE ON edit_access
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_access_uid();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_access_uid();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_access_data ON edit_access_data;
|
-- DROP TRIGGER IF EXISTS trg_edit_access_data ON edit_access_data;
|
||||||
CREATE TRIGGER trg_edit_access_data
|
CREATE TRIGGER trg_edit_access_data
|
||||||
BEFORE INSERT OR UPDATE ON edit_access_data
|
BEFORE INSERT OR UPDATE ON edit_access_data
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_access_right ON edit_access_right;
|
-- DROP TRIGGER IF EXISTS trg_edit_access_right ON edit_access_right;
|
||||||
CREATE TRIGGER trg_edit_access_right
|
CREATE TRIGGER trg_edit_access_right
|
||||||
BEFORE INSERT OR UPDATE ON edit_access_right
|
BEFORE INSERT OR UPDATE ON edit_access_right
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_access_user ON edit_access_user;
|
-- DROP TRIGGER IF EXISTS trg_edit_access_user ON edit_access_user;
|
||||||
CREATE TRIGGER trg_edit_access_user
|
CREATE TRIGGER trg_edit_access_user
|
||||||
BEFORE INSERT OR UPDATE ON edit_access_user
|
BEFORE INSERT OR UPDATE ON edit_access_user
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_group ON edit_group;
|
-- DROP TRIGGER IF EXISTS trg_edit_group ON edit_group;
|
||||||
CREATE TRIGGER trg_edit_group
|
CREATE TRIGGER trg_edit_group
|
||||||
BEFORE INSERT OR UPDATE ON edit_group
|
BEFORE INSERT OR UPDATE ON edit_group
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|
||||||
DROP TRIGGER IF EXISTS trg_set_edit_group_uid ON edit_group;
|
-- DROP TRIGGER IF EXISTS trg_set_edit_group_uid ON edit_group;
|
||||||
CREATE TRIGGER trg_set_edit_group_uid
|
CREATE TRIGGER trg_set_edit_group_uid
|
||||||
BEFORE INSERT OR UPDATE ON edit_group
|
BEFORE INSERT OR UPDATE ON edit_group
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_group_uid();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_group_uid();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_language ON edit_language;
|
-- DROP TRIGGER IF EXISTS trg_edit_language ON edit_language;
|
||||||
CREATE TRIGGER trg_edit_language
|
CREATE TRIGGER trg_edit_language
|
||||||
BEFORE INSERT OR UPDATE ON edit_language
|
BEFORE INSERT OR UPDATE ON edit_language
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_log ON edit_log;
|
-- DROP TRIGGER IF EXISTS trg_edit_log ON edit_log;
|
||||||
CREATE TRIGGER trg_edit_log
|
CREATE TRIGGER trg_edit_log
|
||||||
BEFORE INSERT OR UPDATE ON edit_log
|
BEFORE INSERT OR UPDATE ON edit_log
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|
||||||
DROP TRIGGER IF EXISTS trg_edit_log_insert_partition ON edit_log;
|
-- DROP TRIGGER IF EXISTS trg_edit_log_insert_partition ON edit_log;
|
||||||
CREATE TRIGGER trg_edit_log_insert_partition
|
CREATE TRIGGER trg_edit_log_insert_partition
|
||||||
BEFORE INSERT OR UPDATE ON edit_log
|
BEFORE INSERT OR UPDATE ON edit_log
|
||||||
FOR EACH ROW EXECUTE PROCEDURE edit_log_insert_trigger();
|
FOR EACH ROW EXECUTE PROCEDURE edit_log_insert_trigger();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_log_overflow ON edit_log_overflow;
|
-- DROP TRIGGER IF EXISTS trg_edit_log_overflow ON edit_log_overflow;
|
||||||
CREATE TRIGGER trg_edit_log_overflow
|
CREATE TRIGGER trg_edit_log_overflow
|
||||||
BEFORE INSERT OR UPDATE ON edit_log_overflow
|
BEFORE INSERT OR UPDATE ON edit_log_overflow
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_menu_group ON edit_menu_group;
|
-- DROP TRIGGER IF EXISTS trg_edit_menu_group ON edit_menu_group;
|
||||||
CREATE TRIGGER trg_edit_menu_group
|
CREATE TRIGGER trg_edit_menu_group
|
||||||
BEFORE INSERT OR UPDATE ON edit_menu_group
|
BEFORE INSERT OR UPDATE ON edit_menu_group
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_page ON edit_page;
|
-- DROP TRIGGER IF EXISTS trg_edit_page ON edit_page;
|
||||||
CREATE TRIGGER trg_edit_page
|
CREATE TRIGGER trg_edit_page
|
||||||
BEFORE INSERT OR UPDATE ON edit_page
|
BEFORE INSERT OR UPDATE ON edit_page
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_page_access ON edit_page_access;
|
-- DROP TRIGGER IF EXISTS trg_edit_page_access ON edit_page_access;
|
||||||
CREATE TRIGGER trg_edit_page_access
|
CREATE TRIGGER trg_edit_page_access
|
||||||
BEFORE INSERT OR UPDATE ON edit_page_access
|
BEFORE INSERT OR UPDATE ON edit_page_access
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_page_content ON edit_page_content;
|
-- DROP TRIGGER IF EXISTS trg_edit_page_content ON edit_page_content;
|
||||||
CREATE TRIGGER trg_edit_page_content
|
CREATE TRIGGER trg_edit_page_content
|
||||||
BEFORE INSERT OR UPDATE ON edit_page_content
|
BEFORE INSERT OR UPDATE ON edit_page_content
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_query_string ON edit_query_string;
|
-- DROP TRIGGER IF EXISTS trg_edit_query_string ON edit_query_string;
|
||||||
CREATE TRIGGER trg_edit_query_string
|
CREATE TRIGGER trg_edit_query_string
|
||||||
BEFORE INSERT OR UPDATE ON edit_query_string
|
BEFORE INSERT OR UPDATE ON edit_query_string
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_scheme ON edit_scheme;
|
-- DROP TRIGGER IF EXISTS trg_edit_scheme ON edit_scheme;
|
||||||
CREATE TRIGGER trg_edit_scheme
|
CREATE TRIGGER trg_edit_scheme
|
||||||
BEFORE INSERT OR UPDATE ON edit_scheme
|
BEFORE INSERT OR UPDATE ON edit_scheme
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_user ON edit_user;
|
-- DROP TRIGGER IF EXISTS trg_edit_user ON edit_user;
|
||||||
CREATE TRIGGER trg_edit_user
|
CREATE TRIGGER trg_edit_user
|
||||||
BEFORE INSERT OR UPDATE ON edit_user
|
BEFORE INSERT OR UPDATE ON edit_user
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|
||||||
|
-- DROP TRIGGER IF EXISTS trg_edit_user_set_login_user_id_set_date ON edit_user;
|
||||||
|
CREATE TRIGGER trg_edit_user_set_login_user_id_set_date
|
||||||
|
BEFORE INSERT OR UPDATE ON edit_user
|
||||||
|
FOR EACH ROW EXECUTE PROCEDURE set_login_user_id_set_date();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DROP TRIGGER IF EXISTS trg_edit_visible_group ON edit_visible_group;
|
-- DROP TRIGGER IF EXISTS trg_edit_visible_group ON edit_visible_group;
|
||||||
CREATE TRIGGER trg_edit_visible_group
|
CREATE TRIGGER trg_edit_visible_group
|
||||||
BEFORE INSERT OR UPDATE ON edit_visible_group
|
BEFORE INSERT OR UPDATE ON edit_visible_group
|
||||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
-- update missing edit_* table data
|
-- 2019/12/11 update missing edit_* table data
|
||||||
|
|
||||||
ALTER TABLE edit_generic ADD cuid VARCHAR;
|
ALTER TABLE edit_generic ADD cuid VARCHAR;
|
||||||
|
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
-- 2022/6/17 update edit_user with login uid
|
||||||
|
|
||||||
|
-- the login uid, at least 32 chars
|
||||||
|
ALTER TABLE edit_user ADD login_user_id VARCHAR UNIQUE;
|
||||||
|
-- CREATE UNIQUE INDEX edit_user_login_user_id_key ON edit_user (login_user_id) WHERE login_user_id IS NOT NULL;
|
||||||
|
-- ALTER TABLE edit_user ADD CONSTRAINT edit_user_login_user_id_key UNIQUE (login_user_id);
|
||||||
|
-- when above uid was set
|
||||||
|
ALTER TABLE edit_user ADD login_user_id_set_date TIMESTAMP WITHOUT TIME ZONE;
|
||||||
|
ALTER TABLE edit_user ADD login_user_id_last_revalidate TIMESTAMP WITHOUT TIME ZONE;
|
||||||
|
-- if set, from/until when the above uid is valid
|
||||||
|
ALTER TABLE edit_user ADD login_user_id_valid_from TIMESTAMP WITHOUT TIME ZONE;
|
||||||
|
ALTER TABLE edit_user ADD login_user_id_valid_until TIMESTAMP WITHOUT TIME ZONE;
|
||||||
|
-- user must login to revalidated login id after set days, 0 for forever
|
||||||
|
ALTER TABLE edit_user ADD login_user_id_revalidate_after INTERVAL;
|
||||||
|
-- lock for login user id, but still allow normal login
|
||||||
|
ALTER TABLE edit_user ADD login_user_id_locked SMALLINT NOT NULL DEFAULT 0;
|
||||||
|
|
||||||
|
-- disable login before date
|
||||||
|
ALTER TABLE edit_user ADD lock_until TIMESTAMP WITHOUT TIME ZONE;
|
||||||
|
-- disable login after date
|
||||||
|
ALTER TABLE edit_user ADD lock_after TIMESTAMP WITHOUT TIME ZONE;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION set_login_user_id_set_date()
|
||||||
|
RETURNS TRIGGER AS
|
||||||
|
$$
|
||||||
|
BEGIN
|
||||||
|
-- if new is not null/empty
|
||||||
|
-- and old one is null or old one different new one
|
||||||
|
-- set NOW()
|
||||||
|
-- if new one is NULL
|
||||||
|
-- set NULL
|
||||||
|
IF
|
||||||
|
NEW.login_user_id IS NOT NULL AND NEW.login_user_id <> '' AND
|
||||||
|
(OLD.login_user_id IS NULL OR NEW.login_user_id <> OLD.login_user_id)
|
||||||
|
THEN
|
||||||
|
NEW.login_user_id_set_date = NOW();
|
||||||
|
NEW.login_user_id_last_revalidate = NOW();
|
||||||
|
ELSIF NEW.login_user_id IS NULL OR NEW.login_user_id = '' THEN
|
||||||
|
NEW.login_user_id_set_date = NULL;
|
||||||
|
NEW.login_user_id_last_revalidate = NULL;
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
CREATE TRIGGER trg_edit_user_set_login_user_id_set_date
|
||||||
|
BEFORE INSERT OR UPDATE ON edit_user
|
||||||
|
FOR EACH ROW EXECUTE PROCEDURE set_login_user_id_set_date();
|
||||||
|
|
||||||
|
-- __END__
|
||||||
File diff suppressed because it is too large
Load Diff
52
4dev/tests/CoreLibsACLLogin_database_prepare.sh
Executable file
52
4dev/tests/CoreLibsACLLogin_database_prepare.sh
Executable file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# note: there is currently no port selection, standard 5432 port is assumed
|
||||||
|
# note: we use the default in path postgresql commands and connect to whatever default DB is set
|
||||||
|
|
||||||
|
# PARAMETER 1: database data file to load
|
||||||
|
# PARAMETER 2: db user WHO MUST BE ABLE TO CREATE A DATABASE
|
||||||
|
# PARAMETER 3: db name
|
||||||
|
# PARAMETER 4: db host
|
||||||
|
# PARAMETER 5: print out for testing
|
||||||
|
|
||||||
|
load_sql="${1}";
|
||||||
|
# abort with 1 if we cannot find the file
|
||||||
|
if [ ! -f "${load_sql}" ]; then
|
||||||
|
echo 1;
|
||||||
|
exit 1;
|
||||||
|
fi;
|
||||||
|
db_user="${2}";
|
||||||
|
db_name="${3}";
|
||||||
|
db_host="${4}";
|
||||||
|
# empty db name or db user -> exit with 2
|
||||||
|
if [ -z "${db_user}" ] || [ -z "${db_name}" ] || [ -z "${db_host}" ]; then
|
||||||
|
echo 2;
|
||||||
|
exit 2;
|
||||||
|
fi;
|
||||||
|
# drop database, on error exit with 3
|
||||||
|
dropdb -U ${db_user} -h ${db_host} ${db_name} 2>&1;
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo 3;
|
||||||
|
exit 3;
|
||||||
|
fi;
|
||||||
|
# create database, on error exit with 4
|
||||||
|
createdb -U ${db_user} -O ${db_user} -h ${db_host} -E utf8 ${db_name} 2>&1;
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo 4;
|
||||||
|
exit 4;
|
||||||
|
fi;
|
||||||
|
# if error 5 thrown, test with enabled below
|
||||||
|
if [ ! -z "${5}" ]; then
|
||||||
|
psql -U ${db_user} -h ${db_host} -f ${load_sql} ${db_name};
|
||||||
|
else
|
||||||
|
# load data (redirect ALL error to null), on error exit with 5
|
||||||
|
psql -U ${db_user} -h ${db_host} -f ${load_sql} ${db_name} 2>&1 1>/dev/null 2>/dev/null;
|
||||||
|
fi;
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo 5;
|
||||||
|
exit 5;
|
||||||
|
fi;
|
||||||
|
echo 0;
|
||||||
|
exit 0;
|
||||||
|
|
||||||
|
# __END__
|
||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace tests;
|
namespace tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for Create\Session
|
* Test class for Create\Session
|
||||||
@@ -20,85 +21,246 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function sessionProvider(): array
|
public function sessionProvider(): array
|
||||||
{
|
{
|
||||||
// 0: session name as parameter
|
// 0: session name as parameter or for GLOBAL value
|
||||||
// 1: type p (param), g: global, c: constant
|
// 1: type p: parameter, g: global, d: php.ini default
|
||||||
// 2: exepcted name (session)
|
// 2: mock data as array
|
||||||
// 3: regex check
|
// checkCliStatus: true/false,
|
||||||
|
// getSessionStatus: PHP_SESSION_DISABLED for abort,
|
||||||
|
// PHP_SESSION_NONE/ACTIVE for ok
|
||||||
|
// setSessionName: true/false,
|
||||||
|
// checkActiveSession: true/false, [1st call, 2nd call]
|
||||||
|
// getSessionId: string or false
|
||||||
|
// 3: exepcted name (session)
|
||||||
|
// 4: expected error string
|
||||||
return [
|
return [
|
||||||
'session parameter' => [
|
'session parameter' => [
|
||||||
'sessionNameParameter',
|
'sessionNameParameter',
|
||||||
'p',
|
'p',
|
||||||
|
[
|
||||||
|
'checkCliStatus' => false,
|
||||||
|
'getSessionStatus' => PHP_SESSION_NONE,
|
||||||
|
'setSessionName' => true,
|
||||||
|
'checkActiveSession' => [false, true],
|
||||||
|
'getSessionId' => '1234abcd4567'
|
||||||
|
],
|
||||||
'sessionNameParameter',
|
'sessionNameParameter',
|
||||||
'/^\w+$/'
|
''
|
||||||
],
|
],
|
||||||
'session globals' => [
|
'session globals' => [
|
||||||
'sessionNameGlobals',
|
'sessionNameGlobals',
|
||||||
'g',
|
'g',
|
||||||
|
[
|
||||||
|
'checkCliStatus' => false,
|
||||||
|
'getSessionStatus' => PHP_SESSION_NONE,
|
||||||
|
'setSessionName' => true,
|
||||||
|
'checkActiveSession' => [false, true],
|
||||||
|
'getSessionId' => '1234abcd4567'
|
||||||
|
],
|
||||||
'sessionNameGlobals',
|
'sessionNameGlobals',
|
||||||
'/^\w+$/'
|
''
|
||||||
],
|
],
|
||||||
'session name default' => [
|
'session name default' => [
|
||||||
'',
|
'',
|
||||||
'd',
|
'd',
|
||||||
|
[
|
||||||
|
'checkCliStatus' => false,
|
||||||
|
'getSessionStatus' => PHP_SESSION_NONE,
|
||||||
|
'setSessionName' => true,
|
||||||
|
'checkActiveSession' => [false, true],
|
||||||
|
'getSessionId' => '1234abcd4567'
|
||||||
|
],
|
||||||
'',
|
'',
|
||||||
'/^\w+$/'
|
''
|
||||||
|
],
|
||||||
|
// error checks
|
||||||
|
// 1: we are in cli
|
||||||
|
'on cli error' => [
|
||||||
|
'',
|
||||||
|
'd',
|
||||||
|
[
|
||||||
|
'checkCliStatus' => true,
|
||||||
|
'getSessionStatus' => PHP_SESSION_NONE,
|
||||||
|
'setSessionName' => true,
|
||||||
|
'checkActiveSession' => [false, true],
|
||||||
|
'getSessionId' => '1234abcd4567'
|
||||||
|
],
|
||||||
|
'',
|
||||||
|
'[SESSION] No sessions in php cli'
|
||||||
|
],
|
||||||
|
// 2: session disabled
|
||||||
|
'session disabled error' => [
|
||||||
|
'',
|
||||||
|
'd',
|
||||||
|
[
|
||||||
|
'checkCliStatus' => false,
|
||||||
|
'getSessionStatus' => PHP_SESSION_DISABLED,
|
||||||
|
'setSessionName' => true,
|
||||||
|
'checkActiveSession' => [false, true],
|
||||||
|
'getSessionId' => '1234abcd4567'
|
||||||
|
],
|
||||||
|
'',
|
||||||
|
'[SESSION] Sessions are disabled'
|
||||||
|
],
|
||||||
|
// 3: invalid session name: string
|
||||||
|
'invalid name chars error' => [
|
||||||
|
'1invalid$session#;',
|
||||||
|
'p',
|
||||||
|
[
|
||||||
|
'checkCliStatus' => false,
|
||||||
|
'getSessionStatus' => PHP_SESSION_NONE,
|
||||||
|
'setSessionName' => false,
|
||||||
|
'checkActiveSession' => [false, true],
|
||||||
|
'getSessionId' => '1234abcd4567'
|
||||||
|
],
|
||||||
|
'',
|
||||||
|
'[SESSION] Invalid session name: 1invalid$session#;'
|
||||||
|
],
|
||||||
|
// 3: invalid session name: only numbers
|
||||||
|
'invalid name numbers only error' => [
|
||||||
|
'123',
|
||||||
|
'p',
|
||||||
|
[
|
||||||
|
'checkCliStatus' => false,
|
||||||
|
'getSessionStatus' => PHP_SESSION_NONE,
|
||||||
|
'setSessionName' => false,
|
||||||
|
'checkActiveSession' => [false, true],
|
||||||
|
'getSessionId' => '1234abcd4567'
|
||||||
|
],
|
||||||
|
'',
|
||||||
|
'[SESSION] Invalid session name: 123'
|
||||||
|
],
|
||||||
|
// 3: invalid session name: invalid name short
|
||||||
|
// 3: invalid session name: too long (128)
|
||||||
|
// 4: failed to start session (2nd false on check active session)
|
||||||
|
'invalid name numbers only error' => [
|
||||||
|
'',
|
||||||
|
'd',
|
||||||
|
[
|
||||||
|
'checkCliStatus' => false,
|
||||||
|
'getSessionStatus' => PHP_SESSION_NONE,
|
||||||
|
'setSessionName' => true,
|
||||||
|
'checkActiveSession' => [false, false],
|
||||||
|
'getSessionId' => '1234abcd4567'
|
||||||
|
],
|
||||||
|
'',
|
||||||
|
'[SESSION] Failed to activate session'
|
||||||
|
],
|
||||||
|
// 5: get session id return false
|
||||||
|
'invalid name numbers only error' => [
|
||||||
|
'',
|
||||||
|
'd',
|
||||||
|
[
|
||||||
|
'checkCliStatus' => false,
|
||||||
|
'getSessionStatus' => PHP_SESSION_NONE,
|
||||||
|
'setSessionName' => true,
|
||||||
|
'checkActiveSession' => [false, true],
|
||||||
|
'getSessionId' => false
|
||||||
|
],
|
||||||
|
'',
|
||||||
|
'[SESSION] getSessionId did not return a session id'
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Test session start
|
||||||
*
|
*
|
||||||
|
* @covers ::startSession
|
||||||
* @dataProvider sessionProvider
|
* @dataProvider sessionProvider
|
||||||
* @testdox startSession $input name for $type will be $expected_n with $expected_i [$_dataName]
|
* @testdox startSession $input name for $type will be $expected (error: $expected_error) [$_dataName]
|
||||||
*
|
*
|
||||||
* @param string $input
|
* @param string $input
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string|bool $expected_n
|
* @param array<mixed> $mock_data
|
||||||
* @param string|bool $expected_i
|
* @param string $expected
|
||||||
|
* @param string $expected_error
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testStartSession(
|
public function testStartSession(
|
||||||
string $input,
|
string $input,
|
||||||
string $type,
|
string $type,
|
||||||
$expected_n,
|
array $mock_data,
|
||||||
$expected_i
|
string $expected,
|
||||||
|
string $expected_error,
|
||||||
): void {
|
): void {
|
||||||
/*
|
// override expected
|
||||||
// MOCK class for dummy call
|
if ($type == 'd') {
|
||||||
$session = new \CoreLibs\Create\Session();
|
$expected = ini_get('session.name');
|
||||||
$session_id = '';
|
}
|
||||||
|
/** @var \CoreLibs\Create\Session&MockObject $session_mock */
|
||||||
|
$session_mock = $this->createPartialMock(
|
||||||
|
\CoreLibs\Create\Session::class,
|
||||||
|
[
|
||||||
|
'checkCliStatus', 'getSessionStatus', 'checkActiveSession',
|
||||||
|
'setSessionName', 'startSessionCall', 'getSessionId',
|
||||||
|
'getSessionName'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
// set return values based requested input values
|
||||||
|
// OK: true
|
||||||
|
// error: false
|
||||||
|
$session_mock->method('checkCliStatus')->willReturn($mock_data['checkCliStatus']);
|
||||||
|
// OK: PHP_SESSION_ACTIVE, PHP_SESSION_NONE
|
||||||
|
// error: PHP_SESSION_DISABLED
|
||||||
|
$session_mock->method('getSessionStatus')->willReturn($mock_data['getSessionStatus']);
|
||||||
|
// false: try start
|
||||||
|
// true: skip start
|
||||||
|
// note that on second call if false -> error
|
||||||
|
$session_mock->method('checkActiveSession')
|
||||||
|
->willReturnOnConsecutiveCalls(
|
||||||
|
$mock_data['checkActiveSession'][0],
|
||||||
|
$mock_data['checkActiveSession'][1],
|
||||||
|
);
|
||||||
|
// dummy set for session name
|
||||||
|
$session_mock->method('setSessionName')->with($input)->willReturn($mock_data['setSessionName']);
|
||||||
|
// set session name & return bsed on request data
|
||||||
|
$session_mock->method('getSessionName')->willReturn($expected);
|
||||||
|
// will not return anything
|
||||||
|
$session_mock->method('startSessionCall');
|
||||||
|
// in test case only return string
|
||||||
|
// false: will return false
|
||||||
|
$session_mock->method('getSessionId')->willReturn($mock_data['getSessionId']);
|
||||||
|
|
||||||
|
// regex for session id
|
||||||
|
$ression_id_regex = "/^\w+$/";
|
||||||
|
|
||||||
unset($GLOBALS['SET_SESSION_NAME']);
|
unset($GLOBALS['SET_SESSION_NAME']);
|
||||||
|
$session_id = '';
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'p':
|
case 'p':
|
||||||
$session_id = $session->startSession($input);
|
$session_id = $session_mock->startSession($input);
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
$GLOBALS['SET_SESSION_NAME'] = $input;
|
$GLOBALS['SET_SESSION_NAME'] = $input;
|
||||||
$session_id = $session->startSession();
|
$session_id = $session_mock->startSession();
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
$expected_n = ini_get('session.name');
|
$session_id = $session_mock->startSession();
|
||||||
$session_id = \$session->startSession();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->assertMatchesRegularExpression(
|
// asert checks
|
||||||
$expected_i,
|
if (!empty($session_id)) {
|
||||||
(string)$session_id
|
$this->assertMatchesRegularExpression(
|
||||||
);
|
$ression_id_regex,
|
||||||
$this->assertMatchesRegularExpression(
|
(string)$session_id,
|
||||||
$expected_i,
|
'session id regex from retrun'
|
||||||
(string)$session->getSessionId()
|
);
|
||||||
);
|
$this->assertMatchesRegularExpression(
|
||||||
$this->assertEquals(
|
$ression_id_regex,
|
||||||
$expected_n,
|
(string)$session_mock->getSessionId()
|
||||||
$session->getSessionName()
|
);
|
||||||
);
|
$this->assertEquals(
|
||||||
if ($type == 'g') {
|
$expected,
|
||||||
unset($GLOBALS['SET_SESSION_NAME']);
|
$session_mock->getSessionName()
|
||||||
} */
|
);
|
||||||
$this->markTestSkipped('[CoreLibsCreateSessionTest] No implementation '
|
} else {
|
||||||
. 'for Create\Session. Cannot run session_start in CLI');
|
// false checks
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_error,
|
||||||
|
$session_mock->getErrorStr(),
|
||||||
|
'error assert'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,7 +271,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
public function sessionNameProvider(): array
|
public function sessionNameProvider(): array
|
||||||
{
|
{
|
||||||
// 0: string for session
|
// 0: string for session
|
||||||
// 1: expected return
|
// 1: expected return as bool
|
||||||
return [
|
return [
|
||||||
'valid name' => [
|
'valid name' => [
|
||||||
'abc',
|
'abc',
|
||||||
@@ -141,7 +303,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* test valid session name
|
||||||
*
|
*
|
||||||
* @covers ::checkValidSessionName
|
* @covers ::checkValidSessionName
|
||||||
* @dataProvider sessionNameProvider
|
* @dataProvider sessionNameProvider
|
||||||
@@ -158,6 +320,153 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
\CoreLibs\Create\Session::checkValidSessionName($input)
|
\CoreLibs\Create\Session::checkValidSessionName($input)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provider for set/get tests
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function sessionDataProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'test' => [
|
||||||
|
'foo',
|
||||||
|
'bar',
|
||||||
|
'bar',
|
||||||
|
],
|
||||||
|
'int key test' => [
|
||||||
|
123,
|
||||||
|
'bar',
|
||||||
|
'bar',
|
||||||
|
],
|
||||||
|
// more complex value tests
|
||||||
|
'array values' => [
|
||||||
|
'array',
|
||||||
|
[1, 2, 3],
|
||||||
|
[1, 2, 3],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* method call test
|
||||||
|
*
|
||||||
|
* @covers ::setS
|
||||||
|
* @covers ::getS
|
||||||
|
* @covers ::issetS
|
||||||
|
* @covers ::unsetS
|
||||||
|
* @dataProvider sessionDataProvider
|
||||||
|
* @testdox setS/getS/issetS/unsetS $name with $input is $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string|int $name
|
||||||
|
* @param mixed $input
|
||||||
|
* @param mixed $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testMethodSetGet($name, $input, $expected): void
|
||||||
|
{
|
||||||
|
$session = new \CoreLibs\Create\Session();
|
||||||
|
$session->setS($name, $input);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$session->getS($name),
|
||||||
|
'method set assert'
|
||||||
|
);
|
||||||
|
// isset true
|
||||||
|
$this->assertTrue(
|
||||||
|
$session->issetS($name),
|
||||||
|
'method isset assert ok'
|
||||||
|
);
|
||||||
|
$session->unsetS($name);
|
||||||
|
$this->assertEquals(
|
||||||
|
'',
|
||||||
|
$session->getS($name),
|
||||||
|
'method unset assert'
|
||||||
|
);
|
||||||
|
// iset false
|
||||||
|
$this->assertFalse(
|
||||||
|
$session->issetS($name),
|
||||||
|
'method isset assert false'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* magic call test
|
||||||
|
*
|
||||||
|
* @covers ::__set
|
||||||
|
* @covers ::__get
|
||||||
|
* @covers ::__isset
|
||||||
|
* @covers ::__unset
|
||||||
|
* @dataProvider sessionDataProvider
|
||||||
|
* @testdox __set/__get/__iseet/__unset $name with $input is $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string|int $name
|
||||||
|
* @param mixed $input
|
||||||
|
* @param mixed $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testMagicSetGet($name, $input, $expected): void
|
||||||
|
{
|
||||||
|
$session = new \CoreLibs\Create\Session();
|
||||||
|
$session->$name = $input;
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$session->$name,
|
||||||
|
'magic set assert'
|
||||||
|
);
|
||||||
|
// isset true
|
||||||
|
$this->assertTrue(
|
||||||
|
isset($session->$name),
|
||||||
|
'magic isset assert ok'
|
||||||
|
);
|
||||||
|
unset($session->$name);
|
||||||
|
$this->assertEquals(
|
||||||
|
'',
|
||||||
|
$session->$name,
|
||||||
|
'magic unset assert'
|
||||||
|
);
|
||||||
|
// isset true
|
||||||
|
$this->assertFalse(
|
||||||
|
isset($session->$name),
|
||||||
|
'magic isset assert false'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unset all test
|
||||||
|
*
|
||||||
|
* @covers ::unsetAllS
|
||||||
|
* @testdox unsetAllS test
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testUnsetAll(): void
|
||||||
|
{
|
||||||
|
$test_values = [
|
||||||
|
'foo' => 'abc',
|
||||||
|
'bar' => '123'
|
||||||
|
];
|
||||||
|
$session = new \CoreLibs\Create\Session();
|
||||||
|
foreach ($test_values as $name => $value) {
|
||||||
|
$session->setS($name, $value);
|
||||||
|
// confirm set
|
||||||
|
$this->assertEquals(
|
||||||
|
$value,
|
||||||
|
$session->getS($name),
|
||||||
|
'set assert: ' . $name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// unset all
|
||||||
|
$session->unsetAllS();
|
||||||
|
// check unset
|
||||||
|
foreach (array_keys($test_values) as $name) {
|
||||||
|
$this->assertEquals(
|
||||||
|
'',
|
||||||
|
$session->getS($name),
|
||||||
|
'unsert assert: ' . $name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -709,6 +709,64 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function prBlProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'true bool default' => [
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
'true'
|
||||||
|
],
|
||||||
|
'false bool default' => [
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
'false'
|
||||||
|
],
|
||||||
|
'true bool override' => [
|
||||||
|
true,
|
||||||
|
'ok',
|
||||||
|
'not ok',
|
||||||
|
'ok'
|
||||||
|
],
|
||||||
|
'false bool override' => [
|
||||||
|
false,
|
||||||
|
'ok',
|
||||||
|
'not ok',
|
||||||
|
'not ok'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check bool to string converter
|
||||||
|
*
|
||||||
|
* @covers ::prBl
|
||||||
|
* @dataProvider prBlProvider
|
||||||
|
* @textdox check prBl $input ($true/$false) is expected $false [$_dataName]
|
||||||
|
*
|
||||||
|
* @param bool $input
|
||||||
|
* @param string|null $true
|
||||||
|
* @param string|null $false
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testPrBl(bool $input, ?string $true, ?string $false, string $expected): void
|
||||||
|
{
|
||||||
|
$this->log = new \CoreLibs\Debug\Logging();
|
||||||
|
$return = '';
|
||||||
|
if ($true === null && $false === null) {
|
||||||
|
$return = $this->log->prBl($input);
|
||||||
|
} elseif ($true !== null || $false !== null) {
|
||||||
|
$return = $this->log->prBl($input, $true ?? '', $false ?? '');
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$return
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// from here are complex debug tests
|
// from here are complex debug tests
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
119
4dev/tests/CoreLibsDebugMemoryUsageTest.php
Normal file
119
4dev/tests/CoreLibsDebugMemoryUsageTest.php
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use CoreLibs\Debug\MemoryUsage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Debug\MemoryUsage
|
||||||
|
* @coversDefaultClass \CoreLibs\Debug\MemoryUsage
|
||||||
|
* @testdox \CoreLibs\Debug\MemoryUsage method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsDebugMemoryUsageTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function memoryUsageProvider(): array
|
||||||
|
{
|
||||||
|
$regex_raw_off = '/^\[[\w\s_-]+\] Peak\/Curr\/Change: \d+(\.\d+)? ?\w{1,2}\/'
|
||||||
|
. '\d+(\.\d+)? ?\w{1,2}\/'
|
||||||
|
. 'Since Start: \d+(\.\d+)? ?\w{1,2} \| '
|
||||||
|
. 'Since Last: \d+(\.\d+)? ?\w{1,2} \| '
|
||||||
|
. 'Since Set: \d+(\.\d+)? ?\w{1,2}$/';
|
||||||
|
$regex_raw_on = '/^\[[\w\s_-]+\] Peak\/Curr\/'
|
||||||
|
// . 'Change: \d+(\.\d+)? ?\w{1,2}\/\d+(\.\d+)? ?\w{1,2} \[\d+\]\/'
|
||||||
|
. 'Change: \d+(\.\d+)? ?\w{1,2}\/\d+(\.\d+)? ?\w{1,2}/'
|
||||||
|
. 'Since Start: \d+(\.\d+)? ?\w{1,2} \[\d+\] \| '
|
||||||
|
. 'Since Last: \d+(\.\d+)? ?\w{1,2} \[\d+\] \| '
|
||||||
|
. 'Since Set: \d+(\.\d+)? ?\w{1,2} \[\d+\]$/';
|
||||||
|
$regex_array = [
|
||||||
|
'prefix' => '/^[\w\s_-]+$/',
|
||||||
|
'peak' => '/^\d+$/',
|
||||||
|
'usage' => '/^\d+$/',
|
||||||
|
'start' => '/^\d+$/',
|
||||||
|
'last' => '/^\d+$/',
|
||||||
|
'set' => '/^\d+$/',
|
||||||
|
];
|
||||||
|
// 0: prefix
|
||||||
|
// 1: raw flag
|
||||||
|
// 2: set flags array
|
||||||
|
// 3: array output expected (as regex)
|
||||||
|
// 4: string output expected (as regex)
|
||||||
|
return [
|
||||||
|
'test normal' => [
|
||||||
|
'test',
|
||||||
|
null,
|
||||||
|
[],
|
||||||
|
$regex_array,
|
||||||
|
$regex_raw_off,
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @cover ::resetMemory
|
||||||
|
* @cover ::debugMemoryFlag
|
||||||
|
* @cover ::setStartMemory
|
||||||
|
* @cover ::setMemory
|
||||||
|
* @cover ::memoryUsage
|
||||||
|
* @cover ::printMemoryUsage
|
||||||
|
* @dataProvider memoryUsageProvider
|
||||||
|
* @testdox memoryUsage with $prefix, raw memory $raw [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $prefix
|
||||||
|
* @param bool|null $raw
|
||||||
|
* @param array $set_flags
|
||||||
|
* @param array $expected_array
|
||||||
|
* @param string $expected_string
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testMemoryUsage(
|
||||||
|
string $prefix,
|
||||||
|
?bool $raw,
|
||||||
|
array $settings,
|
||||||
|
array $expected_array,
|
||||||
|
string $expected_string
|
||||||
|
): void {
|
||||||
|
// always reeset to null
|
||||||
|
MemoryUsage::resetMemory();
|
||||||
|
MemoryUsage::debugMemoryFlag(true);
|
||||||
|
MemoryUsage::setStartMemory();
|
||||||
|
MemoryUsage::setMemory();
|
||||||
|
// run collector
|
||||||
|
$memory = MemoryUsage::memoryUsage($prefix);
|
||||||
|
if ($raw === null) {
|
||||||
|
$string = MemoryUsage::printMemoryUsage($memory);
|
||||||
|
} else {
|
||||||
|
$string = MemoryUsage::printMemoryUsage($memory, $raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
// expected_array for each
|
||||||
|
foreach ($expected_array as $name => $regex) {
|
||||||
|
$this->assertMatchesRegularExpression(
|
||||||
|
$regex,
|
||||||
|
(string)$memory[$name],
|
||||||
|
'assert memory usage array ' . $name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// regex match string
|
||||||
|
$this->assertMatchesRegularExpression(
|
||||||
|
$expected_string,
|
||||||
|
$string,
|
||||||
|
'assert memory usage string as regex'
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO additional tests with use more memory and check diff matching
|
||||||
|
// TODO reset memory usage test
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -15,6 +15,8 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
|
|||||||
{
|
{
|
||||||
public function hrRunningTimeProvider(): array
|
public function hrRunningTimeProvider(): array
|
||||||
{
|
{
|
||||||
|
// 0: return time difference
|
||||||
|
// 1: return time on first run in regex
|
||||||
return [
|
return [
|
||||||
'default time' => [
|
'default time' => [
|
||||||
0 => null,
|
0 => null,
|
||||||
@@ -69,21 +71,73 @@ final class CoreLibsDebugRunningTimeTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testHrRunningTime(?string $out_time, string $expected): void
|
public function testHrRunningTime(?string $out_time, string $expected): void
|
||||||
{
|
{
|
||||||
|
// reset for each run
|
||||||
|
\CoreLibs\Debug\RunningTime::hrRunningTimeReset();
|
||||||
$start = \CoreLibs\Debug\RunningTime::hrRunningTime();
|
$start = \CoreLibs\Debug\RunningTime::hrRunningTime();
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
0,
|
0,
|
||||||
$start
|
$start,
|
||||||
|
'assert first run 0'
|
||||||
);
|
);
|
||||||
time_nanosleep(1, 500);
|
time_nanosleep(1, 500);
|
||||||
if ($out_time === null) {
|
if ($out_time === null) {
|
||||||
$end = \CoreLibs\Debug\RunningTime::hrRunningTime();
|
$second = \CoreLibs\Debug\RunningTime::hrRunningTime();
|
||||||
} else {
|
} else {
|
||||||
$end = \CoreLibs\Debug\RunningTime::hrRunningTime($out_time);
|
$second = \CoreLibs\Debug\RunningTime::hrRunningTime($out_time);
|
||||||
}
|
}
|
||||||
// print "E: " . $end . "\n";
|
// print "E: " . $end . "\n";
|
||||||
$this->assertMatchesRegularExpression(
|
$this->assertMatchesRegularExpression(
|
||||||
$expected,
|
$expected,
|
||||||
(string)$end
|
(string)$second,
|
||||||
|
'assert second run regex'
|
||||||
|
);
|
||||||
|
if ($out_time === null) {
|
||||||
|
$end_second = \CoreLibs\Debug\RunningTime::hrRunningTimeFromStart();
|
||||||
|
} else {
|
||||||
|
$end_second = \CoreLibs\Debug\RunningTime::hrRunningTimeFromStart($out_time);
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$end_second,
|
||||||
|
$second,
|
||||||
|
'assert end is equal second'
|
||||||
|
);
|
||||||
|
// sleep again, second messurement
|
||||||
|
time_nanosleep(1, 500);
|
||||||
|
if ($out_time === null) {
|
||||||
|
$third = \CoreLibs\Debug\RunningTime::hrRunningTime();
|
||||||
|
} else {
|
||||||
|
$third = \CoreLibs\Debug\RunningTime::hrRunningTime($out_time);
|
||||||
|
}
|
||||||
|
// third call is not null
|
||||||
|
$this->assertNotEquals(
|
||||||
|
0,
|
||||||
|
$third,
|
||||||
|
'assert third call not null'
|
||||||
|
);
|
||||||
|
// third call is bigger than end
|
||||||
|
$this->assertNotEquals(
|
||||||
|
$second,
|
||||||
|
$third,
|
||||||
|
'assert third different second'
|
||||||
|
);
|
||||||
|
// last messurement, must match start - end + last
|
||||||
|
if ($out_time === null) {
|
||||||
|
$end = \CoreLibs\Debug\RunningTime::hrRunningTimeFromStart();
|
||||||
|
} else {
|
||||||
|
$end = \CoreLibs\Debug\RunningTime::hrRunningTimeFromStart($out_time);
|
||||||
|
}
|
||||||
|
$this->assertGreaterThan(
|
||||||
|
$third,
|
||||||
|
$end,
|
||||||
|
'assert end greater third'
|
||||||
|
);
|
||||||
|
// new start
|
||||||
|
\CoreLibs\Debug\RunningTime::hrRunningTimeReset();
|
||||||
|
$new_start = \CoreLibs\Debug\RunningTime::hrRunningTime();
|
||||||
|
$this->assertEquals(
|
||||||
|
0,
|
||||||
|
$new_start,
|
||||||
|
'assert new run 0'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ final class CoreLibsDebugSupportTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function printArProvider(): array
|
public function printArrayProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'empty array' => [
|
'empty array' => [
|
||||||
@@ -62,6 +62,51 @@ final class CoreLibsDebugSupportTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function printBoolProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'true input default' => [
|
||||||
|
0 => true,
|
||||||
|
1 => [],
|
||||||
|
2 => 'true'
|
||||||
|
],
|
||||||
|
'false input default' => [
|
||||||
|
0 => false,
|
||||||
|
1 => [],
|
||||||
|
2 => 'false'
|
||||||
|
],
|
||||||
|
'false input param name' => [
|
||||||
|
0 => false,
|
||||||
|
1 => [
|
||||||
|
'name' => 'param test'
|
||||||
|
],
|
||||||
|
2 => '<b>param test</b>: false'
|
||||||
|
],
|
||||||
|
'true input param name, true override' => [
|
||||||
|
0 => true,
|
||||||
|
1 => [
|
||||||
|
'name' => 'param test',
|
||||||
|
'true' => 'ok'
|
||||||
|
],
|
||||||
|
2 => '<b>param test</b>: ok'
|
||||||
|
],
|
||||||
|
'false input param name, true override, false override' => [
|
||||||
|
0 => false,
|
||||||
|
1 => [
|
||||||
|
'name' => 'param test',
|
||||||
|
'true' => 'ok',
|
||||||
|
'false' => 'not',
|
||||||
|
],
|
||||||
|
2 => '<b>param test</b>: not'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -184,8 +229,9 @@ final class CoreLibsDebugSupportTest extends TestCase
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @cover ::printAr
|
* @cover ::printAr
|
||||||
* @dataProvider printArProvider
|
* @cover ::printArray
|
||||||
* @testdox printAr $input will be $expected [$_dataName]
|
* @dataProvider printArrayProvider
|
||||||
|
* @testdox printAr/printArray $input will be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
* @param array $input
|
* @param array $input
|
||||||
* @param string $expected
|
* @param string $expected
|
||||||
@@ -195,7 +241,59 @@ final class CoreLibsDebugSupportTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Debug\Support::printAr($input)
|
\CoreLibs\Debug\Support::printAr($input),
|
||||||
|
'assert printAr'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Debug\Support::printArray($input),
|
||||||
|
'assert printArray'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @cover ::printBool
|
||||||
|
* @dataProvider printBoolProvider
|
||||||
|
* @testdox printBool $input will be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param bool $input
|
||||||
|
* @param array $params
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testPrintBool(bool $input, array $params, string $expected): void
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
isset($params['name']) &&
|
||||||
|
isset($params['true']) &&
|
||||||
|
isset($params['false'])
|
||||||
|
) {
|
||||||
|
$string = \CoreLibs\Debug\Support::printBool(
|
||||||
|
$input,
|
||||||
|
$params['name'],
|
||||||
|
$params['true'],
|
||||||
|
$params['false']
|
||||||
|
);
|
||||||
|
} elseif (isset($params['name']) && isset($params['true'])) {
|
||||||
|
$string = \CoreLibs\Debug\Support::printBool(
|
||||||
|
$input,
|
||||||
|
$params['name'],
|
||||||
|
$params['true']
|
||||||
|
);
|
||||||
|
} elseif (isset($params['name'])) {
|
||||||
|
$string = \CoreLibs\Debug\Support::printBool(
|
||||||
|
$input,
|
||||||
|
$params['name']
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$string = \CoreLibs\Debug\Support::printBool($input);
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$string,
|
||||||
|
'assert printBool'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
162
4dev/tests/CoreLibsGetDotEnvTest.php
Normal file
162
4dev/tests/CoreLibsGetDotEnvTest.php
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use CoreLibs\Get\DotEnv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for ACL\Login
|
||||||
|
* @coversDefaultClass \CoreLibs\Get\DotEnv
|
||||||
|
* @testdox \CoreLibs\Get\DotEnv method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsGetDotEnvTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function envFileProvider(): array
|
||||||
|
{
|
||||||
|
$dot_env_content = [
|
||||||
|
'SOMETHING' => 'A',
|
||||||
|
'OTHER' => 'B IS B',
|
||||||
|
'Complex' => 'A B \"D is F',
|
||||||
|
'HAS_SPACE' => 'ABC',
|
||||||
|
'HAS_COMMENT_QUOTES_SPACE' => 'Comment at end with quotes and space',
|
||||||
|
'HAS_COMMENT_QUOTES_NO_SPACE' => 'Comment at end with quotes no space',
|
||||||
|
'HAS_COMMENT_NO_QUOTES_SPACE' => 'Comment at end no quotes and space',
|
||||||
|
'HAS_COMMENT_NO_QUOTES_NO_SPACE' => 'Comment at end no quotes no space',
|
||||||
|
'COMMENT_IN_TEXT_QUOTES' => 'Foo bar # comment in here',
|
||||||
|
'FAILURE' => 'ABC',
|
||||||
|
'SIMPLEBOX' => 'A B C',
|
||||||
|
'TITLE' => '1',
|
||||||
|
'FOO' => '1.2',
|
||||||
|
'SOME.TEST' => 'Test Var',
|
||||||
|
'SOME.LIVE' => 'Live Var',
|
||||||
|
'A_TEST1' => 'foo',
|
||||||
|
'A_TEST2' => '${TEST1:-bar}',
|
||||||
|
'A_TEST3' => '${TEST4:-bar}',
|
||||||
|
'A_TEST5' => 'null',
|
||||||
|
'A_TEST6' => '${TEST5-bar}',
|
||||||
|
'A_TEST7' => '${TEST6:-bar}',
|
||||||
|
'B_TEST1' => 'foo',
|
||||||
|
'B_TEST2' => '${TEST1:=bar}',
|
||||||
|
'B_TEST3' => '${TEST4:=bar}',
|
||||||
|
'B_TEST5' => 'null',
|
||||||
|
'B_TEST6' => '${TEST5=bar}',
|
||||||
|
'B_TEST7' => '${TEST6=bar}',
|
||||||
|
'Test' => 'A',
|
||||||
|
'TEST' => 'B',
|
||||||
|
'LINE' => "ABC\nDEF",
|
||||||
|
'OTHERLINE' => "ABC\nAF\"ASFASDF\nMORESHIT",
|
||||||
|
'SUPERLINE' => '',
|
||||||
|
'__FOO_BAR_1' => 'b',
|
||||||
|
'__FOOFOO' => 'f ',
|
||||||
|
123123 => 'number',
|
||||||
|
'EMPTY' => '',
|
||||||
|
];
|
||||||
|
// 0: folder relative to test folder, if unset __DIR__
|
||||||
|
// 1: file, if unset .env
|
||||||
|
// 2: status to be returned
|
||||||
|
// 3: _ENV file content to be set
|
||||||
|
// 4: override chmod as octect in string
|
||||||
|
return [
|
||||||
|
'default' => [
|
||||||
|
'folder' => null,
|
||||||
|
'file' => null,
|
||||||
|
'status' => 3,
|
||||||
|
'content' => [],
|
||||||
|
'chmod' => null,
|
||||||
|
],
|
||||||
|
'cannot open file' => [
|
||||||
|
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||||
|
'file' => 'cannot_read.env',
|
||||||
|
'status' => 2,
|
||||||
|
'content' => [],
|
||||||
|
'chmod' => '000',
|
||||||
|
],
|
||||||
|
'empty file' => [
|
||||||
|
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||||
|
'file' => 'empty.env',
|
||||||
|
'status' => 1,
|
||||||
|
'content' => [],
|
||||||
|
'chmod' => null,
|
||||||
|
],
|
||||||
|
'override all' => [
|
||||||
|
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||||
|
'file' => 'test.env',
|
||||||
|
'status' => 0,
|
||||||
|
'content' => $dot_env_content,
|
||||||
|
'chmod' => null,
|
||||||
|
],
|
||||||
|
'override directory' => [
|
||||||
|
'folder' => __DIR__ . DIRECTORY_SEPARATOR . 'dotenv',
|
||||||
|
'file' => null,
|
||||||
|
'status' => 0,
|
||||||
|
'content' => $dot_env_content,
|
||||||
|
'chmod' => null,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test read .env file
|
||||||
|
*
|
||||||
|
* @covers ::readEnvFile
|
||||||
|
* @dataProvider envFileProvider
|
||||||
|
* @testdox Read _ENV file from $folder / $file with expected status: $expected_status and chmod $chmod [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string|null $folder
|
||||||
|
* @param string|null $file
|
||||||
|
* @param int $expected_status
|
||||||
|
* @param array $expected_env
|
||||||
|
* @param string|null $chmod
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testReadEnvFile(
|
||||||
|
?string $folder,
|
||||||
|
?string $file,
|
||||||
|
int $expected_status,
|
||||||
|
array $expected_env,
|
||||||
|
?string $chmod
|
||||||
|
): void {
|
||||||
|
// if we have file + chmod set
|
||||||
|
$old_chmod = null;
|
||||||
|
if (
|
||||||
|
is_file($folder . DIRECTORY_SEPARATOR . $file) &&
|
||||||
|
!empty($chmod)
|
||||||
|
) {
|
||||||
|
// get the old permissions
|
||||||
|
$old_chmod = fileperms($folder . DIRECTORY_SEPARATOR . $file);
|
||||||
|
chmod($folder . DIRECTORY_SEPARATOR . $file, octdec($chmod));
|
||||||
|
}
|
||||||
|
if ($folder !== null && $file !== null) {
|
||||||
|
$status = DotEnv::readEnvFile($folder, $file);
|
||||||
|
} elseif ($folder !== null) {
|
||||||
|
$status = DotEnv::readEnvFile($folder);
|
||||||
|
} else {
|
||||||
|
$status = DotEnv::readEnvFile();
|
||||||
|
}
|
||||||
|
$this->assertEquals(
|
||||||
|
$status,
|
||||||
|
$expected_status,
|
||||||
|
'Assert returned status equal'
|
||||||
|
);
|
||||||
|
// now assert read data
|
||||||
|
$this->assertEquals(
|
||||||
|
$_ENV,
|
||||||
|
$expected_env,
|
||||||
|
'Assert _ENV correct'
|
||||||
|
);
|
||||||
|
// if we have file and chmod unset
|
||||||
|
if ($old_chmod !== null) {
|
||||||
|
chmod($folder . DIRECTORY_SEPARATOR . $file, $old_chmod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
1031
4dev/tests/database/CoreLibsACLLogin_database_create_data.sql
Normal file
1031
4dev/tests/database/CoreLibsACLLogin_database_create_data.sql
Normal file
File diff suppressed because it is too large
Load Diff
1
4dev/tests/dotenv/.env
Symbolic link
1
4dev/tests/dotenv/.env
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
test.env
|
||||||
0
4dev/tests/dotenv/cannot_read.env
Normal file
0
4dev/tests/dotenv/cannot_read.env
Normal file
0
4dev/tests/dotenv/empty.env
Normal file
0
4dev/tests/dotenv/empty.env
Normal file
49
4dev/tests/dotenv/test.env
Normal file
49
4dev/tests/dotenv/test.env
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
# enviroment file
|
||||||
|
SOMETHING=A
|
||||||
|
OTHER="B IS B"
|
||||||
|
Complex="A B \"D is F"
|
||||||
|
# COMMENT
|
||||||
|
HAS_SPACE= "ABC";
|
||||||
|
# COMMENT AT END
|
||||||
|
HAS_COMMENT_QUOTES_SPACE="Comment at end with quotes and space" # Comment QE
|
||||||
|
HAS_COMMENT_QUOTES_NO_SPACE="Comment at end with quotes no space"# Comment QES
|
||||||
|
HAS_COMMENT_NO_QUOTES_SPACE=Comment at end no quotes and space # Comment NQE
|
||||||
|
HAS_COMMENT_NO_QUOTES_NO_SPACE=Comment at end no quotes no space# Comment NQES
|
||||||
|
COMMENT_IN_TEXT_QUOTES="Foo bar # comment in here"
|
||||||
|
FAILURE = ABC
|
||||||
|
SIMPLEBOX= A B C
|
||||||
|
TITLE=1
|
||||||
|
FOO=1.2
|
||||||
|
SOME.TEST=Test Var
|
||||||
|
SOME.LIVE=Live Var
|
||||||
|
# VAR TESTS -
|
||||||
|
A_TEST1 = foo
|
||||||
|
A_TEST2 = ${TEST1:-bar} # TEST1 is set so the value of TEST2 = foo
|
||||||
|
A_TEST3 = ${TEST4:-bar} # TEST4 is not set so the value of TEST3 = bar
|
||||||
|
A_TEST5 = null
|
||||||
|
A_TEST6 = ${TEST5-bar} # TEST5 is set but empty so the value of TEST6 = null
|
||||||
|
A_TEST7 = ${TEST6:-bar} # TEST5 is set and empty so the value of TEST7 = bar
|
||||||
|
# VAR TESTS =
|
||||||
|
B_TEST1 = foo
|
||||||
|
B_TEST2 = ${TEST1:=bar} # TEST1 is set so the value of TEST2 = foo
|
||||||
|
B_TEST3 = ${TEST4:=bar} # TEST4 is not set so the value of TEST3 = bar and TEST4 = bar
|
||||||
|
B_TEST5 = null
|
||||||
|
B_TEST6 = ${TEST5=bar} # TEST5 is set but emtpy so the value of TEST6 = null
|
||||||
|
B_TEST7 = ${TEST6=bar} # TEST5 is set and empty so the value of TEST7 = bar and TEST5 = bar
|
||||||
|
# VAR TEST END
|
||||||
|
Test="A"
|
||||||
|
TEST="B"
|
||||||
|
TEST="D"
|
||||||
|
LINE="ABC
|
||||||
|
DEF"
|
||||||
|
OTHERLINE="ABC
|
||||||
|
AF\"ASFASDF
|
||||||
|
MORESHIT"
|
||||||
|
SUPERLINE=
|
||||||
|
"asfasfasf"
|
||||||
|
__FOO_BAR_1 = b
|
||||||
|
__FOOFOO = f
|
||||||
|
123123=number
|
||||||
|
EMPTY=
|
||||||
|
= flase
|
||||||
|
asfasdf
|
||||||
140
www/admin/class_test.db.dbReturn.php
Normal file
140
www/admin/class_test.db.dbReturn.php
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
<?php // phpcs:ignore warning
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
// turn on all error reporting
|
||||||
|
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
// basic class test file
|
||||||
|
define('USE_DATABASE', true);
|
||||||
|
// sample config
|
||||||
|
require 'config.php';
|
||||||
|
// override ECHO ALL FALSE
|
||||||
|
$ECHO_ALL = true;
|
||||||
|
// define log file id
|
||||||
|
$LOG_FILE_ID = 'classTest-db';
|
||||||
|
ob_end_flush();
|
||||||
|
|
||||||
|
use CoreLibs\Debug\Support;
|
||||||
|
use CoreLibs\Debug\RunningTime;
|
||||||
|
|
||||||
|
$log = new CoreLibs\Debug\Logging([
|
||||||
|
'log_folder' => BASE . LOG,
|
||||||
|
'file_id' => $LOG_FILE_ID,
|
||||||
|
// add file date
|
||||||
|
'print_file_date' => true,
|
||||||
|
// set debug and print flags
|
||||||
|
'debug_all' => $DEBUG_ALL ?? false,
|
||||||
|
'echo_all' => $ECHO_ALL ?? false,
|
||||||
|
'print_all' => $PRINT_ALL ?? false,
|
||||||
|
]);
|
||||||
|
// db connection and attach logger
|
||||||
|
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||||
|
$db->log->debug('START', '=============================>');
|
||||||
|
|
||||||
|
$PAGE_NAME = 'TEST CLASS: DB dbReturn';
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
|
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||||
|
print "<body>";
|
||||||
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
print '<div><a href="class_test.db.php">Class Test DB</a></div>';
|
||||||
|
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||||
|
|
||||||
|
print "LOGFILE NAME: " . $db->log->getSetting('log_file_name') . "<br>";
|
||||||
|
print "LOGFILE ID: " . $db->log->getSetting('log_file_id') . "<br>";
|
||||||
|
print "DBINFO: " . $db->dbInfo() . "<br>";
|
||||||
|
|
||||||
|
// DB client encoding
|
||||||
|
print "DB client encoding: " . $db->dbGetEncoding() . "<br>";
|
||||||
|
print "DB search path: " . $db->dbGetSchema() . "<br>";
|
||||||
|
|
||||||
|
// SELECT read tests with dbReturn and cache values
|
||||||
|
print "<br>";
|
||||||
|
print "<b>dbReturn CACHE tests</b><br>";
|
||||||
|
// DATA has two rows for reading
|
||||||
|
// delete and repare base data
|
||||||
|
$db->dbExec("DELETE FROM test_db_return");
|
||||||
|
$db->dbExec("INSERT INTO test_db_return (uid, data) VALUES ('A1', 'Test A'), ('B1', 'Test B')");
|
||||||
|
// read query to use
|
||||||
|
$q_db_ret = "SELECT * FROM test_db_return ORDER BY uid";
|
||||||
|
|
||||||
|
RunningTime::hrRunningTime();
|
||||||
|
|
||||||
|
$cache_flag = 'USE_CACHE (0)';
|
||||||
|
print "dbReturn '" . $cache_flag . "'/Default: " . $q_db_ret . "<br>";
|
||||||
|
// SINGLE read on multi row return
|
||||||
|
// Do twice
|
||||||
|
for ($i = 1; $i <= 6; $i++) {
|
||||||
|
$res = $db->dbReturn($q_db_ret);
|
||||||
|
print $i . ") " . $cache_flag . ": "
|
||||||
|
. "res: " . (is_bool($res) ?
|
||||||
|
"<b>Bool:</b> " . $db->log->prBl($res) :
|
||||||
|
(is_array($res) ?
|
||||||
|
"Array: " . $db->log->prBl(is_array($res)) : '{-}')
|
||||||
|
) . ", "
|
||||||
|
. "cursor_ext: <pre>" . Support::printAr($db->dbGetCursorExt($q_db_ret)) . "</pre>";
|
||||||
|
print "Run time: " . RunningTime::hrRunningTime() . "<br>";
|
||||||
|
}
|
||||||
|
// reset all read data
|
||||||
|
$db->dbCacheReset($q_db_ret);
|
||||||
|
echo "<hr>";
|
||||||
|
$cache_flag = 'READ_NEW (1)';
|
||||||
|
print "dbReturn '" . $cache_flag . "': " . $q_db_ret . "<br>";
|
||||||
|
// NO CACHE
|
||||||
|
for ($i = 1; $i <= 6; $i++) {
|
||||||
|
$res = $db->dbReturn($q_db_ret, $db::READ_NEW);
|
||||||
|
print $i . ") " . $cache_flag . ": "
|
||||||
|
. "res: " . (is_bool($res) ?
|
||||||
|
"<b>Bool:</b> " . $db->log->prBl($res) :
|
||||||
|
(is_array($res) ?
|
||||||
|
"Array: " . $db->log->prBl(is_array($res)) : '{-}')
|
||||||
|
) . ", "
|
||||||
|
. "cursor_ext: <pre>" . Support::printAr($db->dbGetCursorExt($q_db_ret)) . "</pre>";
|
||||||
|
print "Run time: " . RunningTime::hrRunningTime() . "<br>";
|
||||||
|
}
|
||||||
|
// reset all read data
|
||||||
|
$db->dbCacheReset($q_db_ret);
|
||||||
|
echo "<hr>";
|
||||||
|
$cache_flag = 'CLEAR_CACHE (2)';
|
||||||
|
print "dbReturn '" . $cache_flag . "': " . $q_db_ret . "<br>";
|
||||||
|
// NO CACHE
|
||||||
|
for ($i = 1; $i <= 6; $i++) {
|
||||||
|
$res = $db->dbReturn($q_db_ret, $db::CLEAR_CACHE);
|
||||||
|
print $i . ") " . $cache_flag . ": "
|
||||||
|
. "res: " . (is_bool($res) ?
|
||||||
|
"<b>Bool:</b> " . $db->log->prBl($res) :
|
||||||
|
(is_array($res) ?
|
||||||
|
"Array: " . $db->log->prBl(is_array($res)) : '{-}')
|
||||||
|
) . ", "
|
||||||
|
. "cursor_ext: <pre>" . Support::printAr($db->dbGetCursorExt($q_db_ret)) . "</pre>";
|
||||||
|
print "Run time: " . RunningTime::hrRunningTime() . "<br>";
|
||||||
|
}
|
||||||
|
// reset all read data
|
||||||
|
$db->dbCacheReset($q_db_ret);
|
||||||
|
echo "<hr>";
|
||||||
|
$cache_flag = 'NO_CACHE (3)';
|
||||||
|
print "dbReturn '" . $cache_flag . "': " . $q_db_ret . "<br>";
|
||||||
|
// NO CACHE
|
||||||
|
for ($i = 1; $i <= 6; $i++) {
|
||||||
|
$res = $db->dbReturn($q_db_ret, $db::NO_CACHE);
|
||||||
|
print $i . ") " . $cache_flag . ": "
|
||||||
|
. "res: " . (is_bool($res) ?
|
||||||
|
"<b>Bool:</b> " . $db->log->prBl($res) :
|
||||||
|
(is_array($res) ?
|
||||||
|
"Array: " . $db->log->prBl(is_array($res)) : '{-}')
|
||||||
|
) . ", "
|
||||||
|
. "cursor_ext: <pre>" . Support::printAr($db->dbGetCursorExt($q_db_ret)) . "</pre>";
|
||||||
|
print "Run time: " . RunningTime::hrRunningTime() . "<br>";
|
||||||
|
}
|
||||||
|
// reset all data
|
||||||
|
$db->dbCacheReset($q_db_ret);
|
||||||
|
print "<br>";
|
||||||
|
print "Overall Run time: " . RunningTime::hrRunningTimeFromStart() . "<br>";
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -44,6 +44,7 @@ print "<!DOCTYPE html>";
|
|||||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
print '<div><a href="class_test.db.dbReturn.php">Class Test DB dbReturn</a></div>';
|
||||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||||
|
|
||||||
print "LOGFILE NAME: " . $db->log->getSetting('log_file_name') . "<br>";
|
print "LOGFILE NAME: " . $db->log->getSetting('log_file_name') . "<br>";
|
||||||
@@ -72,6 +73,8 @@ $db->dbSetEncoding('SJIS');
|
|||||||
print "ENCODING TEST: " . $db->dbVersionInfo('client_encoding') . "/" . $db->dbGetEncoding() . "<br>";
|
print "ENCODING TEST: " . $db->dbVersionInfo('client_encoding') . "/" . $db->dbGetEncoding() . "<br>";
|
||||||
$db->dbResetEncoding();
|
$db->dbResetEncoding();
|
||||||
|
|
||||||
|
// TEST CACHE READS
|
||||||
|
|
||||||
$res = $db->dbReturn("SELECT * FROM max_test");
|
$res = $db->dbReturn("SELECT * FROM max_test");
|
||||||
print "DB RETURN ROWS: " . $db->dbGetNumRows() . "<br>";
|
print "DB RETURN ROWS: " . $db->dbGetNumRows() . "<br>";
|
||||||
|
|
||||||
@@ -97,6 +100,12 @@ print "NO CACHED DATA: <pre>" . print_r($db->dbGetCursorExt(), true) . "</pre><b
|
|||||||
// print "UUD/TIME: " . $res['uid'] . "/" . $res['time'] . "<br>";
|
// print "UUD/TIME: " . $res['uid'] . "/" . $res['time'] . "<br>";
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// dbReturn tests on separate page
|
||||||
|
print "<br>";
|
||||||
|
print "<b>dbReturn CACHE tests</b><br>";
|
||||||
|
print '<a href="class_test.db.dbReturn.php">Class Test DB dbReturn</a><br>';
|
||||||
|
print "<br>";
|
||||||
|
|
||||||
print "<pre>";
|
print "<pre>";
|
||||||
|
|
||||||
print "SOCKET: " . pg_socket($db->dbGetDbh()) . "<br>";
|
print "SOCKET: " . pg_socket($db->dbGetDbh()) . "<br>";
|
||||||
@@ -182,7 +191,6 @@ print "UPDATE WITH PK " . $last_insert_pk
|
|||||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||||
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||||
|
|
||||||
|
|
||||||
// INSERT WITH NO RETURNING
|
// INSERT WITH NO RETURNING
|
||||||
$status = $db->dbExec("INSERT INTO test_foobar (type, integer) VALUES ('WITHOUT DATA', 456)");
|
$status = $db->dbExec("INSERT INTO test_foobar (type, integer) VALUES ('WITHOUT DATA', 456)");
|
||||||
print "INSERT WITH NO PRIMARY KEY NO RETURNING STATUS: " . Support::printToString($status) . " |<br>"
|
print "INSERT WITH NO PRIMARY KEY NO RETURNING STATUS: " . Support::printToString($status) . " |<br>"
|
||||||
@@ -222,7 +230,6 @@ if (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# db write class test
|
# db write class test
|
||||||
$table = 'test_foo';
|
$table = 'test_foo';
|
||||||
print "TABLE META DATA: " . DgS::printAr($db->dbShowTableMetaData($table)) . "<br>";
|
print "TABLE META DATA: " . DgS::printAr($db->dbShowTableMetaData($table)) . "<br>";
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ print "S::GETCALLERMETHOD: " . test() . "<br>";
|
|||||||
print "S::GETCALLERMETHODLIST: <pre>" . print_r(test2(), true) . "</pre><br>";
|
print "S::GETCALLERMETHODLIST: <pre>" . print_r(test2(), true) . "</pre><br>";
|
||||||
print "S::PRINTAR: " . DebugSupport::printAr(['Foo', 'Bar']) . "<br>";
|
print "S::PRINTAR: " . DebugSupport::printAr(['Foo', 'Bar']) . "<br>";
|
||||||
print "V-S::PRINTAR: " . $debug_support_class::printAr(['Foo', 'Bar']) . "<br>";
|
print "V-S::PRINTAR: " . $debug_support_class::printAr(['Foo', 'Bar']) . "<br>";
|
||||||
|
print "S::PRINTBOOL(default): " . DebugSupport::printBool(true) . "<br>";
|
||||||
|
print "S::PRINTBOOL(name): " . DebugSupport::printBool(true, 'Name') . "<br>";
|
||||||
|
print "S::PRINTBOOL(name, ok): " . DebugSupport::printBool(true, 'Name', 'ok') . "<br>";
|
||||||
|
print "S::PRINTBOOL(name, ok, not): " . DebugSupport::printBool(false, 'Name', 'ok', 'not') . "<br>";
|
||||||
print "S::DEBUSTRING(s): " . DebugSupport::debugString('SET') . "<br>";
|
print "S::DEBUSTRING(s): " . DebugSupport::debugString('SET') . "<br>";
|
||||||
print "S::DEBUSTRING(''): " . DebugSupport::debugString('') . "<br>";
|
print "S::DEBUSTRING(''): " . DebugSupport::debugString('') . "<br>";
|
||||||
print "S::DEBUSTRING(,s): " . DebugSupport::debugString(null, '{-}') . "<br>";
|
print "S::DEBUSTRING(,s): " . DebugSupport::debugString(null, '{-}') . "<br>";
|
||||||
@@ -181,6 +185,10 @@ $debug->debug('TEST PER LEVEL', 'Per level test');
|
|||||||
$debug->debug('()', 'Per level test: invalid chars');
|
$debug->debug('()', 'Per level test: invalid chars');
|
||||||
$debug->setLogPer('level', false);
|
$debug->setLogPer('level', false);
|
||||||
|
|
||||||
|
$ar = ['A', 1, ['B' => 'D']];
|
||||||
|
$debug->debug('ARRAY', 'Array: ' . $debug->prAr($ar));
|
||||||
|
$debug->debug('BOOL', 'True: ' . $debug->prBl(true) . ', False: ' . $debug->prBl(false));
|
||||||
|
|
||||||
// error message
|
// error message
|
||||||
// future DEPRECATED
|
// future DEPRECATED
|
||||||
// $debug->debug('BASIC CLASS', 'Debug test');
|
// $debug->debug('BASIC CLASS', 'Debug test');
|
||||||
|
|||||||
91
www/admin/class_test.memoryusage.php
Normal file
91
www/admin/class_test.memoryusage.php
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<?php // phpcs:ignore warning
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
|
||||||
|
$DEBUG_ALL = 1;
|
||||||
|
$PRINT_ALL = 1;
|
||||||
|
$DB_DEBUG = 1;
|
||||||
|
|
||||||
|
if ($DEBUG_ALL) {
|
||||||
|
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
// basic class test file
|
||||||
|
define('USE_DATABASE', false);
|
||||||
|
// sample config
|
||||||
|
require 'config.php';
|
||||||
|
// define log file id
|
||||||
|
$LOG_FILE_ID = 'classTest-memoryusage';
|
||||||
|
ob_end_flush();
|
||||||
|
|
||||||
|
use CoreLibs\Debug\MemoryUsage;
|
||||||
|
use CoreLibs\Debug\Support;
|
||||||
|
|
||||||
|
$log = new CoreLibs\Debug\Logging([
|
||||||
|
'log_folder' => BASE . LOG,
|
||||||
|
'file_id' => $LOG_FILE_ID,
|
||||||
|
// add file date
|
||||||
|
'print_file_date' => true,
|
||||||
|
// set debug and print flags
|
||||||
|
'debug_all' => $DEBUG_ALL ?? false,
|
||||||
|
'echo_all' => $ECHO_ALL ?? false,
|
||||||
|
'print_all' => $PRINT_ALL ?? false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$PAGE_NAME = 'TEST CLASS: MEMORY USAGE';
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
|
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||||
|
print "<body>";
|
||||||
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||||
|
|
||||||
|
MemoryUsage::debugMemoryFlag(true);
|
||||||
|
print "Debug Flag: " . Support::printBool(MemoryUsage::debugMemoryFlag()) . "<br>";
|
||||||
|
MemoryUsage::setStartMemory();
|
||||||
|
MemoryUsage::setMemory();
|
||||||
|
$data = MemoryUsage::memoryUsage('first run');
|
||||||
|
print "Memory usage 1 array: " . Support::printAr($data) . "<br>";
|
||||||
|
print "Memory usage 1 string: " . MemoryUsage::printMemoryUsage($data) . "<br>";
|
||||||
|
print "Memory usage 1 string raw: " . MemoryUsage::printMemoryUsage($data, true) . "<br>";
|
||||||
|
$var = 'foo';
|
||||||
|
$out = '';
|
||||||
|
for ($i = 1; $i <= 100; $i++) {
|
||||||
|
$out .= $var;
|
||||||
|
}
|
||||||
|
$data = MemoryUsage::memoryUsage('second run');
|
||||||
|
print "Memory usage 2 array: " . Support::printAr($data) . "<br>";
|
||||||
|
print "Memory usage 2 string: " . MemoryUsage::printMemoryUsage($data) . "<br>";
|
||||||
|
print "Memory usage 2 string raw: " . MemoryUsage::printMemoryUsage($data, true) . "<br>";
|
||||||
|
MemoryUsage::setMemory();
|
||||||
|
$var = 'foasdfasdfasdfasdfasdfo';
|
||||||
|
$out = '';
|
||||||
|
for ($i = 1; $i <= 10000; $i++) {
|
||||||
|
$out .= $var;
|
||||||
|
}
|
||||||
|
$data = MemoryUsage::memoryUsage('third run');
|
||||||
|
print "Memory usage 3 array: " . Support::printAr($data) . "<br>";
|
||||||
|
print "Memory usage 3 string: " . MemoryUsage::printMemoryUsage($data) . "<br>";
|
||||||
|
print "Memory usage 3 string raw: " . MemoryUsage::printMemoryUsage($data, true) . "<br>";
|
||||||
|
$var = 'foasdfasdfasdasdfasdfasdfadfadfasdfasdfo';
|
||||||
|
$out = '';
|
||||||
|
for ($i = 1; $i <= 100000; $i++) {
|
||||||
|
$out .= $var;
|
||||||
|
}
|
||||||
|
$data = MemoryUsage::memoryUsage('forth run');
|
||||||
|
print "Memory usage 4 array: " . Support::printAr($data) . "<br>";
|
||||||
|
print "Memory usage 4 string: " . MemoryUsage::printMemoryUsage($data) . "<br>";
|
||||||
|
print "Memory usage 4 string raw: " . MemoryUsage::printMemoryUsage($data, true) . "<br>";
|
||||||
|
|
||||||
|
// error message
|
||||||
|
print $log->printErrorMsg();
|
||||||
|
|
||||||
|
print "</body></html>";
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -54,6 +54,7 @@ print "<html><head><title>TEST CLASS</title><head>";
|
|||||||
print "<body>";
|
print "<body>";
|
||||||
|
|
||||||
print '<div><a href="class_test.db.php">Class Test: DB</a></div>';
|
print '<div><a href="class_test.db.php">Class Test: DB</a></div>';
|
||||||
|
print '<div><a href="class_test.db.DbReturn.php">Class Test: DB dbReturn</a></div>';
|
||||||
print '<div><a href="class_test.colors.php">Class Test: COLORS</a></div>';
|
print '<div><a href="class_test.colors.php">Class Test: COLORS</a></div>';
|
||||||
print '<div><a href="class_test.mime.php">Class Test: MIME</a></div>';
|
print '<div><a href="class_test.mime.php">Class Test: MIME</a></div>';
|
||||||
print '<div><a href="class_test.json.php">Class Test: JSON</a></div>';
|
print '<div><a href="class_test.json.php">Class Test: JSON</a></div>';
|
||||||
@@ -75,6 +76,7 @@ print '<div><a href="class_test.randomkey.php">Class Test: RANDOM KEY</a></div>'
|
|||||||
print '<div><a href="class_test.system.php">Class Test: SYSTEM</a></div>';
|
print '<div><a href="class_test.system.php">Class Test: SYSTEM</a></div>';
|
||||||
print '<div><a href="class_test.readenvfile.php">Class Test: READ ENV FILE</a></div>';
|
print '<div><a href="class_test.readenvfile.php">Class Test: READ ENV FILE</a></div>';
|
||||||
print '<div><a href="class_test.runningtime.php">Class Test: RUNNING TIME</a></div>';
|
print '<div><a href="class_test.runningtime.php">Class Test: RUNNING TIME</a></div>';
|
||||||
|
print '<div><a href="class_test.memoryusage.php">Class Test: MEMORY USAGE</a></div>';
|
||||||
print '<div><a href="class_test.debug.php">Class Test: DEBUG</a></div>';
|
print '<div><a href="class_test.debug.php">Class Test: DEBUG</a></div>';
|
||||||
print '<div><a href="class_test.output.form.php">Class Test: OUTPUT FORM</a></div>';
|
print '<div><a href="class_test.output.form.php">Class Test: OUTPUT FORM</a></div>';
|
||||||
print '<div><a href="class_test.admin.backend.php">Class Test: BACKEND ADMIN CLASS</a></div>';
|
print '<div><a href="class_test.admin.backend.php">Class Test: BACKEND ADMIN CLASS</a></div>';
|
||||||
@@ -94,13 +96,13 @@ print "<div>READ _ENV ARRAY:</div>";
|
|||||||
print CoreLibs\Debug\Support::printAr(array_map('htmlentities', $_ENV));
|
print CoreLibs\Debug\Support::printAr(array_map('htmlentities', $_ENV));
|
||||||
// set + check edit access id
|
// set + check edit access id
|
||||||
$edit_access_id = 3;
|
$edit_access_id = 3;
|
||||||
if (is_object($login) && isset($login->acl['unit'])) {
|
if (is_object($login) && isset($login->loginGetAcl()['unit'])) {
|
||||||
print "ACL UNIT: " . print_r(array_keys($login->acl['unit']), true) . "<br>";
|
print "ACL UNIT: " . print_r(array_keys($login->loginGetAcl()['unit']), true) . "<br>";
|
||||||
print "ACCESS CHECK: " . (string)$login->loginCheckEditAccess($edit_access_id) . "<br>";
|
print "ACCESS CHECK: " . (string)$login->loginCheckEditAccess($edit_access_id) . "<br>";
|
||||||
if ($login->loginCheckEditAccess($edit_access_id)) {
|
if ($login->loginCheckEditAccess($edit_access_id)) {
|
||||||
$backend->edit_access_id = $edit_access_id;
|
$backend->edit_access_id = $edit_access_id;
|
||||||
} else {
|
} else {
|
||||||
$backend->edit_access_id = $login->acl['unit_id'];
|
$backend->edit_access_id = $login->loginGetAcl()['unit_id'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print "Something went wrong with the login<br>";
|
print "Something went wrong with the login<br>";
|
||||||
@@ -131,8 +133,8 @@ $log->debug('SOME MARK', 'Some error output');
|
|||||||
// INTERNAL SET
|
// INTERNAL SET
|
||||||
print "EDIT ACCESS ID: " . $backend->edit_access_id . "<br>";
|
print "EDIT ACCESS ID: " . $backend->edit_access_id . "<br>";
|
||||||
if (is_object($login)) {
|
if (is_object($login)) {
|
||||||
// print "ACL: <br>".$backend->print_ar($login->acl)."<br>";
|
// print "ACL: <br>".$backend->print_ar($login->loginGetAcl())."<br>";
|
||||||
$log->debug('ACL', "ACL: " . \CoreLibs\Debug\Support::printAr($login->acl));
|
$log->debug('ACL', "ACL: " . \CoreLibs\Debug\Support::printAr($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>";
|
||||||
// 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(
|
// $result = array_flip(
|
||||||
@@ -147,7 +149,7 @@ if (is_object($login)) {
|
|||||||
// );
|
// );
|
||||||
// print "DEFAULT ACL: <br>".$backend->print_ar($result)."<br>";
|
// print "DEFAULT ACL: <br>".$backend->print_ar($result)."<br>";
|
||||||
// DEPRICATED CALL
|
// DEPRICATED CALL
|
||||||
// $backend->adbSetACL($login->acl);
|
// $backend->adbSetACL($login->loginGetAcl());
|
||||||
}
|
}
|
||||||
|
|
||||||
print "THIS HOST: " . HOST_NAME . ", with PROTOCOL: " . HOST_PROTOCOL . " is running SSL: " . HOST_SSL . "<br>";
|
print "THIS HOST: " . HOST_NAME . ", with PROTOCOL: " . HOST_PROTOCOL . " is running SSL: " . HOST_SSL . "<br>";
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
|||||||
print "ALREADY from config.php: " . \CoreLibs\Debug\Support::printAr($_ENV) . "<br>";
|
print "ALREADY from config.php: " . \CoreLibs\Debug\Support::printAr($_ENV) . "<br>";
|
||||||
|
|
||||||
// test .env in local
|
// test .env in local
|
||||||
|
$status = \CoreLibs\Get\DotEnv::readEnvFile('.', 'test.env');
|
||||||
|
print "test.env: STATUS: " . $status . "<br>";
|
||||||
|
print "AFTER reading test.env file: " . \CoreLibs\Debug\Support::printAr($_ENV) . "<br>";
|
||||||
|
|
||||||
// error message
|
// error message
|
||||||
print $log->printErrorMsg();
|
print $log->printErrorMsg();
|
||||||
|
|||||||
@@ -52,8 +52,17 @@ echo "TIMED [hr]: " . RunningTime::hrRunningTime() . "<br>";
|
|||||||
echo "TIMED [def]: " . RunningTime::runningTime() . "<br>";
|
echo "TIMED [def]: " . RunningTime::runningTime() . "<br>";
|
||||||
echo "TIMED [string]: " . RunningTime::runningTimeString() . "<br>";
|
echo "TIMED [string]: " . RunningTime::runningTimeString() . "<br>";
|
||||||
RunningTime::hrRunningTime();
|
RunningTime::hrRunningTime();
|
||||||
|
echo "TIMED [hr-end] " . RunningTime::hrRunningTimeFromStart() . "<br>";
|
||||||
|
echo "<br>";
|
||||||
echo "RANDOM KEY [default]: " . \CoreLibs\Create\RandomKey::randomKeyGen() . "<br>";
|
echo "RANDOM KEY [default]: " . \CoreLibs\Create\RandomKey::randomKeyGen() . "<br>";
|
||||||
echo "TIMED [hr]: " . RunningTime::hrRunningTime() . "<br>";
|
echo "TIMED 1 [hr]: " . RunningTime::hrRunningTime() . "<br>";
|
||||||
|
echo "TIMED 1 [hr-n]: " . RunningTime::hrRunningTime() . "<br>";
|
||||||
|
echo "TIMED 1 [hr-b]: " . RunningTime::hrRunningTime() . "<br>";
|
||||||
|
echo "TIMED 1 [hr-end]: " . RunningTime::hrRunningTimeFromStart() . "<br>";
|
||||||
|
RunningTime::hrRunningTimeReset();
|
||||||
|
RunningTime::hrRunningTime();
|
||||||
|
echo "TIMED 2 [hr]: " . RunningTime::hrRunningTime() . "<br>";
|
||||||
|
echo "TIMED 2 [hr-end]: " . RunningTime::hrRunningTimeFromStart() . "<br>";
|
||||||
|
|
||||||
// error message
|
// error message
|
||||||
print $log->printErrorMsg();
|
print $log->printErrorMsg();
|
||||||
|
|||||||
@@ -120,6 +120,21 @@ print "[READ] B " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
|||||||
print "[READ] Confirm " . $var . " is " . $value . ": "
|
print "[READ] Confirm " . $var . " is " . $value . ": "
|
||||||
. (($_SESSION[$var] ?? '') == $value ? 'Matching' : 'Not matching') . "<br>";
|
. (($_SESSION[$var] ?? '') == $value ? 'Matching' : 'Not matching') . "<br>";
|
||||||
|
|
||||||
|
// test set wrappers methods
|
||||||
|
$session->setS('setwrap', 'YES, method set _SESSION var');
|
||||||
|
print "[READ WRAP] A setwrap: " . $session->getS('setwrap') . "<br>";
|
||||||
|
print "[READ WRAP] Isset: " . ($session->issetS('setwrap') ? 'Yes' : 'No') . "<br>";
|
||||||
|
$session->unsetS('setwrap');
|
||||||
|
print "[READ WRAP] unset setwrap: " . $session->getS('setwrap') . "<br>";
|
||||||
|
print "[READ WRAP] unset Isset: " . ($session->issetS('setwrap') ? 'Yes' : 'No') . "<br>";
|
||||||
|
// test __get/__set
|
||||||
|
$session->setwrap = 'YES, magic set _SESSION var';
|
||||||
|
print "[READ MAGIC] A setwrap: " . $session->setwrap . "<br>";
|
||||||
|
print "[READ MAGIC] Isset: " . (isset($session->setwrap) ? 'Yes' : 'No') . "<br>";
|
||||||
|
unset($session->setwrap);
|
||||||
|
print "[READ MAGIC] unset setwrap: " . $session->setwrap . "<br>";
|
||||||
|
print "[READ MAGIC] unset Isset: " . (isset($session->setwrap) ? 'Yes' : 'No') . "<br>";
|
||||||
|
|
||||||
// differnt session name
|
// differnt session name
|
||||||
$session_name = 'class-test-session-ALT';
|
$session_name = 'class-test-session-ALT';
|
||||||
if (false === ($session_id = $session->startSession($session_name))) {
|
if (false === ($session_id = $session->startSession($session_name))) {
|
||||||
|
|||||||
61
www/admin/edit_groups_test.php
Normal file
61
www/admin/edit_groups_test.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||||
|
|
||||||
|
// this is an empty test page for login tests only
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
$DEBUG_ALL_OVERRIDE = false; // set to 1 to debug on live/remote server locations
|
||||||
|
$DEBUG_ALL = true;
|
||||||
|
$PRINT_ALL = true;
|
||||||
|
$DB_DEBUG = true;
|
||||||
|
|
||||||
|
if ($DEBUG_ALL) {
|
||||||
|
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
// basic class test file
|
||||||
|
define('USE_DATABASE', true);
|
||||||
|
// sample config
|
||||||
|
require 'config.php';
|
||||||
|
// define log file id
|
||||||
|
$LOG_FILE_ID = 'classTest';
|
||||||
|
$SET_SESSION_NAME = EDIT_SESSION_NAME;
|
||||||
|
|
||||||
|
// init login & backend class
|
||||||
|
$session = new CoreLibs\Create\Session($SET_SESSION_NAME);
|
||||||
|
$log = new CoreLibs\Debug\Logging([
|
||||||
|
'log_folder' => BASE . LOG,
|
||||||
|
'file_id' => $LOG_FILE_ID,
|
||||||
|
// add file date
|
||||||
|
'print_file_date' => true,
|
||||||
|
// set debug and print flags
|
||||||
|
'debug_all' => $DEBUG_ALL ?? false,
|
||||||
|
'echo_all' => $ECHO_ALL ?? false,
|
||||||
|
'print_all' => $PRINT_ALL ?? false,
|
||||||
|
]);
|
||||||
|
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||||
|
$login = new CoreLibs\ACL\Login($db, $log, $session);
|
||||||
|
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||||
|
$l10n = new \CoreLibs\Language\L10n(
|
||||||
|
$locale['locale'],
|
||||||
|
$locale['domain'],
|
||||||
|
$locale['path'],
|
||||||
|
);
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
|
print "<html><head><title>GROUP TESTER</title><head>";
|
||||||
|
print "<body>";
|
||||||
|
|
||||||
|
print '<form method="post" name="loginlogout">';
|
||||||
|
print '<a href="javascript:document.loginlogout.login_logout.value=\'Logou\';'
|
||||||
|
. 'document.loginlogout.submit();">Logout</a>';
|
||||||
|
print '<input type="hidden" name="login_logout" value="">';
|
||||||
|
print '</form>';
|
||||||
|
|
||||||
|
print "<h1>TEST Login</h1>";
|
||||||
|
|
||||||
|
print "</body></html>";
|
||||||
|
|
||||||
|
// __END__
|
||||||
1
www/admin/test.env
Symbolic link
1
www/admin/test.env
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../4dev/tests/dotenv/test.env
|
||||||
38
www/composer.lock
generated
38
www/composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "fb2235a66a37d89e7941a863843d2e15",
|
"content-hash": "a71e6f4fbc06f0efb6ad34538b515c53",
|
||||||
"packages": [],
|
"packages": [],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
{
|
{
|
||||||
@@ -415,16 +415,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpdocumentor/type-resolver",
|
"name": "phpdocumentor/type-resolver",
|
||||||
"version": "1.6.0",
|
"version": "1.6.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/phpDocumentor/TypeResolver.git",
|
"url": "https://github.com/phpDocumentor/TypeResolver.git",
|
||||||
"reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706"
|
"reference": "77a32518733312af16a44300404e945338981de3"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706",
|
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/77a32518733312af16a44300404e945338981de3",
|
||||||
"reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706",
|
"reference": "77a32518733312af16a44300404e945338981de3",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -459,9 +459,9 @@
|
|||||||
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
|
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
|
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
|
||||||
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0"
|
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.1"
|
||||||
},
|
},
|
||||||
"time": "2022-01-04T19:58:01+00:00"
|
"time": "2022-03-15T21:29:03+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpspec/prophecy",
|
"name": "phpspec/prophecy",
|
||||||
@@ -850,16 +850,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/phpunit",
|
"name": "phpunit/phpunit",
|
||||||
"version": "9.5.19",
|
"version": "9.5.20",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||||
"reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807"
|
"reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/35ea4b7f3acabb26f4bb640f8c30866c401da807",
|
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/12bc8879fb65aef2138b26fc633cb1e3620cffba",
|
||||||
"reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807",
|
"reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -937,7 +937,7 @@
|
|||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
||||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.19"
|
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.20"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@@ -949,7 +949,7 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2022-03-15T09:57:31+00:00"
|
"time": "2022-04-01T12:37:26+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/cli-parser",
|
"name": "sebastian/cli-parser",
|
||||||
@@ -1317,16 +1317,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/environment",
|
"name": "sebastian/environment",
|
||||||
"version": "5.1.3",
|
"version": "5.1.4",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/environment.git",
|
"url": "https://github.com/sebastianbergmann/environment.git",
|
||||||
"reference": "388b6ced16caa751030f6a69e588299fa09200ac"
|
"reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/388b6ced16caa751030f6a69e588299fa09200ac",
|
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/1b5dff7bb151a4db11d49d90e5408e4e938270f7",
|
||||||
"reference": "388b6ced16caa751030f6a69e588299fa09200ac",
|
"reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -1368,7 +1368,7 @@
|
|||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/environment/issues",
|
"issues": "https://github.com/sebastianbergmann/environment/issues",
|
||||||
"source": "https://github.com/sebastianbergmann/environment/tree/5.1.3"
|
"source": "https://github.com/sebastianbergmann/environment/tree/5.1.4"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@@ -1376,7 +1376,7 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2020-09-28T05:52:38+00:00"
|
"time": "2022-04-03T09:37:03+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/exporter",
|
"name": "sebastian/exporter",
|
||||||
|
|||||||
@@ -232,10 +232,16 @@ if (
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
// set SSL on
|
// set SSL on
|
||||||
if (
|
$is_secure = false;
|
||||||
(array_key_exists('HTTPS', $_SERVER) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ||
|
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
|
||||||
$_SERVER['SERVER_PORT'] == 443
|
$is_secure = true;
|
||||||
|
} elseif (
|
||||||
|
!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ||
|
||||||
|
!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on'
|
||||||
) {
|
) {
|
||||||
|
$is_secure = true;
|
||||||
|
}
|
||||||
|
if ($is_secure) {
|
||||||
define('HOST_SSL', true);
|
define('HOST_SSL', true);
|
||||||
define('HOST_PROTOCOL', 'https://');
|
define('HOST_PROTOCOL', 'https://');
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ for (
|
|||||||
is_file($__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php')
|
is_file($__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php')
|
||||||
) {
|
) {
|
||||||
// load enviorment file if it exists
|
// load enviorment file if it exists
|
||||||
\CoreLibs\Get\ReadEnvFile::readEnvFile(
|
\CoreLibs\Get\DotEnv::readEnvFile(
|
||||||
$__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH
|
$__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH
|
||||||
);
|
);
|
||||||
// load master config file that loads all other config files
|
// load master config file that loads all other config files
|
||||||
|
|||||||
@@ -19,15 +19,17 @@ if (!empty($DEBUG_ALL) && !empty($ENABLE_ERROR_HANDLING)) {
|
|||||||
//------------------------------ library include start
|
//------------------------------ library include start
|
||||||
// set output to quiet for load of classes & session settings
|
// set output to quiet for load of classes & session settings
|
||||||
ob_start();
|
ob_start();
|
||||||
// set the session name
|
|
||||||
$SET_SESSION_NAME = EDIT_SESSION_NAME;
|
|
||||||
$LOG_FILE_ID = BASE_NAME . 'Admin';
|
|
||||||
//------------------------------ library include end
|
//------------------------------ library include end
|
||||||
|
|
||||||
//------------------------------ basic variable settings start
|
//------------------------------ basic variable settings start
|
||||||
|
// set the session name
|
||||||
|
$SET_SESSION_NAME = EDIT_SESSION_NAME;
|
||||||
|
$LOG_FILE_ID = BASE_NAME . 'Admin';
|
||||||
|
// ajax page flag
|
||||||
if (!isset($AJAX_PAGE)) {
|
if (!isset($AJAX_PAGE)) {
|
||||||
$AJAX_PAGE = false;
|
$AJAX_PAGE = false;
|
||||||
}
|
}
|
||||||
|
// zip download flag
|
||||||
if (!isset($ZIP_STREAM)) {
|
if (!isset($ZIP_STREAM)) {
|
||||||
$ZIP_STREAM = false;
|
$ZIP_STREAM = false;
|
||||||
}
|
}
|
||||||
@@ -48,9 +50,9 @@ if ($AJAX_PAGE && !$ZIP_STREAM) {
|
|||||||
// start session
|
// start session
|
||||||
$session = new \CoreLibs\Create\Session($SET_SESSION_NAME);
|
$session = new \CoreLibs\Create\Session($SET_SESSION_NAME);
|
||||||
// create logger
|
// create logger
|
||||||
$log = new CoreLibs\Debug\Logging([
|
$log = new \CoreLibs\Debug\Logging([
|
||||||
'log_folder' => BASE . LOG,
|
'log_folder' => BASE . LOG,
|
||||||
'file_id' => LOG_FILE_ID,
|
'file_id' => $LOG_FILE_ID,
|
||||||
'print_file_date' => true,
|
'print_file_date' => true,
|
||||||
'debug_all' => $DEBUG_ALL ?? false,
|
'debug_all' => $DEBUG_ALL ?? false,
|
||||||
'echo_all' => $ECHO_ALL ?? false,
|
'echo_all' => $ECHO_ALL ?? false,
|
||||||
@@ -69,9 +71,9 @@ if (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// db config with logger
|
// db config with logger
|
||||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
$db = new \CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||||
// login & page access check
|
// login & page access check
|
||||||
$login = new CoreLibs\ACL\Login($db, $log, $session);
|
$login = new \CoreLibs\ACL\Login($db, $log, $session);
|
||||||
// lang, path, domain
|
// lang, path, domain
|
||||||
// pre auto detect language after login
|
// pre auto detect language after login
|
||||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||||
@@ -82,15 +84,15 @@ $l10n = new \CoreLibs\Language\L10n(
|
|||||||
$locale['path'],
|
$locale['path'],
|
||||||
);
|
);
|
||||||
// create smarty object
|
// create smarty object
|
||||||
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
|
$smarty = new \CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||||
// create new Backend class with db and loger attached
|
// create new Backend class with db and loger attached
|
||||||
$cms = new CoreLibs\Admin\Backend($db, $log, $session, $l10n, $locale);
|
$cms = new \CoreLibs\Admin\Backend($db, $log, $session, $l10n, $locale);
|
||||||
// the menu show flag (what menu to show)
|
// the menu show flag (what menu to show)
|
||||||
$cms->menu_show_flag = 'main';
|
$cms->menu_show_flag = 'main';
|
||||||
// db info
|
// db info
|
||||||
$cms->db->dbInfo();
|
$cms->db->dbInfo();
|
||||||
// set acl
|
// set acl
|
||||||
$cms->setACL($login->acl);
|
$cms->setACL($login->loginGetAcl());
|
||||||
// flush (can we move that to header block above)
|
// flush (can we move that to header block above)
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
//------------------------------ class init end
|
//------------------------------ class init end
|
||||||
|
|||||||
@@ -397,10 +397,18 @@ if ($form->my_page_name == 'edit_order') {
|
|||||||
$elements[] = $form->formCreateElement('login_error_date_last');
|
$elements[] = $form->formCreateElement('login_error_date_last');
|
||||||
$elements[] = $form->formCreateElement('login_error_date_first');
|
$elements[] = $form->formCreateElement('login_error_date_first');
|
||||||
$elements[] = $form->formCreateElement('enabled');
|
$elements[] = $form->formCreateElement('enabled');
|
||||||
|
$elements[] = $form->formCreateElement('deleted');
|
||||||
$elements[] = $form->formCreateElement('protected');
|
$elements[] = $form->formCreateElement('protected');
|
||||||
$elements[] = $form->formCreateElement('username');
|
$elements[] = $form->formCreateElement('username');
|
||||||
$elements[] = $form->formCreateElement('password');
|
$elements[] = $form->formCreateElement('password');
|
||||||
$elements[] = $form->formCreateElement('password_change_interval');
|
$elements[] = $form->formCreateElement('password_change_interval');
|
||||||
|
$elements[] = $form->formCreateElement('login_user_id');
|
||||||
|
$elements[] = $form->formCreateElement('login_user_id_set_date');
|
||||||
|
$elements[] = $form->formCreateElement('login_user_id_last_revalidate');
|
||||||
|
$elements[] = $form->formCreateElement('login_user_id_locked');
|
||||||
|
$elements[] = $form->formCreateElement('login_user_id_revalidate_after');
|
||||||
|
$elements[] = $form->formCreateElement('login_user_id_valid_from');
|
||||||
|
$elements[] = $form->formCreateElement('login_user_id_valid_until');
|
||||||
$elements[] = $form->formCreateElement('email');
|
$elements[] = $form->formCreateElement('email');
|
||||||
$elements[] = $form->formCreateElement('last_name');
|
$elements[] = $form->formCreateElement('last_name');
|
||||||
$elements[] = $form->formCreateElement('first_name');
|
$elements[] = $form->formCreateElement('first_name');
|
||||||
@@ -408,6 +416,8 @@ if ($form->my_page_name == 'edit_order') {
|
|||||||
$elements[] = $form->formCreateElement('edit_access_right_id');
|
$elements[] = $form->formCreateElement('edit_access_right_id');
|
||||||
$elements[] = $form->formCreateElement('strict');
|
$elements[] = $form->formCreateElement('strict');
|
||||||
$elements[] = $form->formCreateElement('locked');
|
$elements[] = $form->formCreateElement('locked');
|
||||||
|
$elements[] = $form->formCreateElement('lock_until');
|
||||||
|
$elements[] = $form->formCreateElement('lock_after');
|
||||||
$elements[] = $form->formCreateElement('admin');
|
$elements[] = $form->formCreateElement('admin');
|
||||||
$elements[] = $form->formCreateElement('debug');
|
$elements[] = $form->formCreateElement('debug');
|
||||||
$elements[] = $form->formCreateElement('db_debug');
|
$elements[] = $form->formCreateElement('db_debug');
|
||||||
|
|||||||
@@ -53,6 +53,16 @@ $edit_users = [
|
|||||||
'0' => 'No'
|
'0' => 'No'
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
'deleted' => [
|
||||||
|
'value' => $GLOBALS['deleted'] ?? '',
|
||||||
|
'output_name' => 'Deleted',
|
||||||
|
'type' => 'binary',
|
||||||
|
'int' => 1,
|
||||||
|
'element_list' => [
|
||||||
|
'1' => 'Yes',
|
||||||
|
'0' => 'No'
|
||||||
|
],
|
||||||
|
],
|
||||||
'strict' => [
|
'strict' => [
|
||||||
'value' => $GLOBALS['strict'] ?? '',
|
'value' => $GLOBALS['strict'] ?? '',
|
||||||
'output_name' => 'Strict (Lock after errors)',
|
'output_name' => 'Strict (Lock after errors)',
|
||||||
@@ -119,6 +129,77 @@ $edit_users = [
|
|||||||
'output_name' => 'First Name',
|
'output_name' => 'First Name',
|
||||||
'type' => 'text'
|
'type' => 'text'
|
||||||
],
|
],
|
||||||
|
'lock_until' => [
|
||||||
|
'value' => $GLOBALS['lock_until'] ?? '',
|
||||||
|
'output_name' => 'Lock account until',
|
||||||
|
'type' => 'datetime',
|
||||||
|
'error_check' => 'datetime',
|
||||||
|
'sql_read' => 'YYYY-MM-DD HH24:MI',
|
||||||
|
'datetime' => 1,
|
||||||
|
],
|
||||||
|
'lock_after' => [
|
||||||
|
'value' => $GLOBALS['lock_after'] ?? '',
|
||||||
|
'output_name' => 'Lock account after',
|
||||||
|
'type' => 'datetime',
|
||||||
|
'error_check' => 'datetime',
|
||||||
|
'sql_read' => 'YYYY-MM-DD HH24:MI',
|
||||||
|
'datetime' => 1,
|
||||||
|
],
|
||||||
|
'login_user_id' => [
|
||||||
|
'value' => $GLOBALS['login_user_id'] ?? '',
|
||||||
|
'output_name' => '_GET/_POST loginUserId direct login ID',
|
||||||
|
'type' => 'text',
|
||||||
|
'error_check' => 'unique|custom',
|
||||||
|
'error_regex' => "/^[A-Za-z0-9]+$/",
|
||||||
|
'emptynull' => 1,
|
||||||
|
],
|
||||||
|
'login_user_id_set_date' => [
|
||||||
|
'output_name' => 'loginUserId set date',
|
||||||
|
'value' => $GLOBALS['login_user_id_set_date'] ?? '',
|
||||||
|
'type' => 'view',
|
||||||
|
'empty' => '-'
|
||||||
|
],
|
||||||
|
'login_user_id_last_revalidate' => [
|
||||||
|
'output_name' => 'loginUserId last revalidate date',
|
||||||
|
'value' => $GLOBALS['login_user_id_last_revalidate'] ?? '',
|
||||||
|
'type' => 'view',
|
||||||
|
'empty' => '-'
|
||||||
|
],
|
||||||
|
'login_user_id_locked' => [
|
||||||
|
'value' => $GLOBALS['login_user_id_locked'] ?? '',
|
||||||
|
'output_name' => 'loginUserId usage locked',
|
||||||
|
'type' => 'binary',
|
||||||
|
'int' => 1,
|
||||||
|
'element_list' => [
|
||||||
|
'1' => 'Yes',
|
||||||
|
'0' => 'No'
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'login_user_id_revalidate_after' => [
|
||||||
|
'value' => $GLOBALS['login_user_id_revalidate_after'] ?? '',
|
||||||
|
'output_name' => 'loginUserId, User must login after n days',
|
||||||
|
'type' => 'text',
|
||||||
|
'error_check' => 'intervalshort',
|
||||||
|
'interval' => 1, // interval needs NULL write for empty
|
||||||
|
'size' => 5, // make it 5 chars long
|
||||||
|
'length' => 5
|
||||||
|
],
|
||||||
|
'login_user_id_valid_from' => [
|
||||||
|
'value' => $GLOBALS['login_user_id_valid_from'] ?? '',
|
||||||
|
'output_name' => 'loginUserId valid from',
|
||||||
|
'type' => 'datetime',
|
||||||
|
'error_check' => 'datetime',
|
||||||
|
'sql_read' => 'YYYY-MM-DD HH24:MI',
|
||||||
|
'datetime' => 1,
|
||||||
|
],
|
||||||
|
'login_user_id_valid_until' => [
|
||||||
|
'value' => $GLOBALS['login_user_id_valid_until'] ?? '',
|
||||||
|
'output_name' => 'loginUserId valid until',
|
||||||
|
'type' => 'datetime',
|
||||||
|
'error_check' => 'datetime',
|
||||||
|
'sql_read' => 'YYYY-MM-DD HH24:MI',
|
||||||
|
'datetime' => 1,
|
||||||
|
],
|
||||||
'edit_language_id' => [
|
'edit_language_id' => [
|
||||||
'value' => $GLOBALS['edit_language_id'] ?? '',
|
'value' => $GLOBALS['edit_language_id'] ?? '',
|
||||||
'output_name' => 'Language',
|
'output_name' => 'Language',
|
||||||
@@ -187,7 +268,8 @@ $edit_users = [
|
|||||||
'cols' => 60
|
'cols' => 60
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'load_query' => "SELECT edit_user_id, username, enabled, debug, db_debug, strict, locked, login_error_count "
|
'load_query' => "SELECT edit_user_id, username, enabled, deleted, "
|
||||||
|
. "strict, locked, login_error_count "
|
||||||
. "FROM edit_user ORDER BY username",
|
. "FROM edit_user ORDER BY username",
|
||||||
'table_name' => 'edit_user',
|
'table_name' => 'edit_user',
|
||||||
'show_fields' => [
|
'show_fields' => [
|
||||||
@@ -197,31 +279,26 @@ $edit_users = [
|
|||||||
[
|
[
|
||||||
'name' => 'enabled',
|
'name' => 'enabled',
|
||||||
'binary' => ['Yes', 'No'],
|
'binary' => ['Yes', 'No'],
|
||||||
'before_value' => 'Enabled: '
|
'before_value' => 'ENBL: '
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'debug',
|
'name' => 'deleted',
|
||||||
'binary' => ['Yes', 'No'],
|
'binary' => ['Yes', 'No'],
|
||||||
'before_value' => 'Debug: '
|
'before_value' => 'DEL: '
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'db_debug',
|
|
||||||
'binary' => ['Yes', 'No'],
|
|
||||||
'before_value' => 'DB Debug: '
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'strict',
|
'name' => 'strict',
|
||||||
'binary' => ['Yes', 'No'],
|
'binary' => ['Yes', 'No'],
|
||||||
'before_value' => 'Strict: '
|
'before_value' => 'STRC: '
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'locked',
|
'name' => 'locked',
|
||||||
'binary' => ['Yes', 'No'],
|
'binary' => ['Yes', 'No'],
|
||||||
'before_value' => 'Locked: '
|
'before_value' => 'LCK: '
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'login_error_count',
|
'name' => 'login_error_count',
|
||||||
'before_value' => 'Errors: '
|
'before_value' => 'ERR: '
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'element_list' => [
|
'element_list' => [
|
||||||
|
|||||||
@@ -32,7 +32,10 @@
|
|||||||
<input type="hidden" name="HIDDEN_{$element.data.name}" value="{$element.data.HIDDEN_value}">
|
<input type="hidden" name="HIDDEN_{$element.data.name}" value="{$element.data.HIDDEN_value}">
|
||||||
{/if}
|
{/if}
|
||||||
{if $element.type == 'date'}
|
{if $element.type == 'date'}
|
||||||
<input type="text" name="{$element.data.name}" value="{$element.data.value}" size="10" maxlength="10">
|
<input type="text" name="{$element.data.name}" value="{$element.data.value}" size="10" maxlength="10" placeholder="YYYY-MM-DD">
|
||||||
|
{/if}
|
||||||
|
{if $element.type == 'datetime'}
|
||||||
|
<input type="text" name="{$element.data.name}" value="{$element.data.value}" size="16" maxlength="16" placeholder="YYYY-MM-DD HH:mm">
|
||||||
{/if}
|
{/if}
|
||||||
{if $element.type == 'textarea'}
|
{if $element.type == 'textarea'}
|
||||||
<textarea name="{$element.data.name}"{if $element.data.rows} rows="{$element.data.rows}"{/if}{if $element.data.cols} cols="{$element.data.cols}"{/if}>{$element.data.value}</textarea>
|
<textarea name="{$element.data.name}"{if $element.data.rows} rows="{$element.data.rows}"{/if}{if $element.data.cols} cols="{$element.data.cols}"{/if}>{$element.data.value}</textarea>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -116,6 +116,7 @@ class Backend
|
|||||||
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
||||||
/**
|
/**
|
||||||
* main class constructor
|
* main class constructor
|
||||||
|
*
|
||||||
* @param \CoreLibs\DB\IO $db Database connection class
|
* @param \CoreLibs\DB\IO $db Database connection class
|
||||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||||
* @param \CoreLibs\Create\Session $session Session interface class
|
* @param \CoreLibs\Create\Session $session Session interface class
|
||||||
@@ -175,6 +176,7 @@ class Backend
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* set internal ACL from login ACL
|
* set internal ACL from login ACL
|
||||||
|
*
|
||||||
* @param array<mixed> $acl login acl array
|
* @param array<mixed> $acl login acl array
|
||||||
*/
|
*/
|
||||||
public function setACL(array $acl): void
|
public function setACL(array $acl): void
|
||||||
@@ -183,7 +185,8 @@ class Backend
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* writes all action vars plus other info into edit_log tabl
|
* writes all action vars plus other info into edit_log table
|
||||||
|
*
|
||||||
* @param string $event any kind of event description,
|
* @param string $event any kind of event description,
|
||||||
* @param string|array<mixed> $data any kind of data related to that event
|
* @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 $write_type write type can bei STRING or BINARY
|
||||||
@@ -255,6 +258,7 @@ class Backend
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the menu show flag
|
* Set the menu show flag
|
||||||
|
*
|
||||||
* @param string|int $menu_show_flag
|
* @param string|int $menu_show_flag
|
||||||
* @return string|int
|
* @return string|int
|
||||||
*/
|
*/
|
||||||
@@ -267,6 +271,7 @@ class Backend
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the menu show flag
|
* Return the menu show flag
|
||||||
|
*
|
||||||
* @return string|int
|
* @return string|int
|
||||||
*/
|
*/
|
||||||
public function adbGetMenuShowFlag()
|
public function adbGetMenuShowFlag()
|
||||||
@@ -276,6 +281,7 @@ class Backend
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* menu creater (from login menu session pages)
|
* menu creater (from login menu session pages)
|
||||||
|
*
|
||||||
* @param int $flag visible flag trigger
|
* @param int $flag visible flag trigger
|
||||||
* @return array<mixed> menu array for output on page (smarty)
|
* @return array<mixed> menu array for output on page (smarty)
|
||||||
*/
|
*/
|
||||||
@@ -403,6 +409,7 @@ class Backend
|
|||||||
/**
|
/**
|
||||||
* ONLY USED IN adbTopMenu
|
* ONLY USED IN adbTopMenu
|
||||||
* checks if this filename is in the current situation (user id, etc) available
|
* checks if this filename is in the current situation (user id, etc) available
|
||||||
|
*
|
||||||
* @param string|null $filename filename
|
* @param string|null $filename filename
|
||||||
* @return bool true for visible/accessable menu point, false for not
|
* @return bool true for visible/accessable menu point, false for not
|
||||||
*/
|
*/
|
||||||
@@ -422,8 +429,8 @@ class Backend
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
|
||||||
* creates out of a normal db_return array an assoc array
|
* creates out of a normal db_return array an assoc array
|
||||||
|
*
|
||||||
* @param array<mixed> $db_array input array
|
* @param array<mixed> $db_array input array
|
||||||
* @param string|int|bool $key key
|
* @param string|int|bool $key key
|
||||||
* @param string|int|bool $value value
|
* @param string|int|bool $value value
|
||||||
@@ -440,8 +447,8 @@ class Backend
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
|
||||||
* converts bytes into formated string with KB, MB, etc
|
* converts bytes into formated string with KB, MB, etc
|
||||||
|
*
|
||||||
* @param string|int|float $number string or int or number
|
* @param string|int|float $number string or int or number
|
||||||
* @return string formatted string
|
* @return string formatted string
|
||||||
* @deprecated \CoreLibs\Convert\Byte::humanReadableByteFormat()
|
* @deprecated \CoreLibs\Convert\Byte::humanReadableByteFormat()
|
||||||
@@ -456,8 +463,8 @@ class Backend
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
|
||||||
* converts picture to a thumbnail with max x and max y size
|
* converts picture to a thumbnail with max x and max y size
|
||||||
|
*
|
||||||
* @param string $pic source image file with or without path
|
* @param string $pic source image file with or without path
|
||||||
* @param int $size_x maximum size width
|
* @param int $size_x maximum size width
|
||||||
* @param int $size_y maximum size height
|
* @param int $size_y maximum size height
|
||||||
@@ -485,6 +492,7 @@ class Backend
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper function to fill up the mssages array
|
* wrapper function to fill up the mssages array
|
||||||
|
*
|
||||||
* @param string $level info/warning/error
|
* @param string $level info/warning/error
|
||||||
* @param string $msg string, can be printf formated
|
* @param string $msg string, can be printf formated
|
||||||
* @param array<mixed> $vars optional data for a possible printf formated msg
|
* @param array<mixed> $vars optional data for a possible printf formated msg
|
||||||
@@ -514,6 +522,7 @@ class Backend
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* writes live queue
|
* writes live queue
|
||||||
|
*
|
||||||
* @param string $queue_key string to identfy the queue
|
* @param string $queue_key string to identfy the queue
|
||||||
* @param string $type [description]
|
* @param string $type [description]
|
||||||
* @param string $target [description]
|
* @param string $target [description]
|
||||||
@@ -559,17 +568,22 @@ class Backend
|
|||||||
/**
|
/**
|
||||||
* Basic class holds exact the same, except the Year/Month/Day/etc strings
|
* Basic class holds exact the same, except the Year/Month/Day/etc strings
|
||||||
* are translated in this call
|
* are translated in this call
|
||||||
|
*
|
||||||
* @param int $year year YYYY
|
* @param int $year year YYYY
|
||||||
* @param int $month month m
|
* @param int $month month m
|
||||||
* @param int $day day d
|
* @param int $day day d
|
||||||
* @param int $hour hour H
|
* @param int $hour hour H
|
||||||
* @param int $min min i
|
* @param int $min min i
|
||||||
* @param string $suffix additional info printed after the date time variable in the drop down
|
* @param string $suffix additional info printed after the date time
|
||||||
|
* variable in the drop down
|
||||||
* also used for ID in the on change JS call
|
* also used for ID in the on change JS call
|
||||||
* @param int $min_steps default is 1 (minute), can set to anything, is used as sum up from 0
|
* @param int $min_steps default is 1 (minute), can set to anything,
|
||||||
* @param bool $name_pos_back default false, if set to true, the name will be printend
|
* is used as sum up from 0
|
||||||
|
* @param bool $name_pos_back default false, if set to true,
|
||||||
|
* the name will be printend
|
||||||
* after the drop down and not before the drop down
|
* after the drop down and not before the drop down
|
||||||
* @return string HTML formated strings for drop down lists of date and time
|
* @return string HTML formated strings for drop down lists
|
||||||
|
* of date and time
|
||||||
*/
|
*/
|
||||||
public function adbPrintDateTime(
|
public function adbPrintDateTime(
|
||||||
$year,
|
$year,
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ class Email
|
|||||||
/**
|
/**
|
||||||
* guesses the email type (mostly for mobile) from the domain
|
* guesses the email type (mostly for mobile) from the domain
|
||||||
* if second is set to true, it will return short naming scheme (only provider)
|
* if second is set to true, it will return short naming scheme (only provider)
|
||||||
|
*
|
||||||
* @param string $email email string
|
* @param string $email email string
|
||||||
* @param bool $short default false, if true,
|
* @param bool $short default false, if true,
|
||||||
* returns only short type (pc instead of pc_html)
|
* returns only short type (pc instead of pc_html)
|
||||||
@@ -197,6 +198,7 @@ class Email
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the short email type from a long email type
|
* gets the short email type from a long email type
|
||||||
|
*
|
||||||
* @param string $email_type email string
|
* @param string $email_type email string
|
||||||
* @return string|bool short string or false for invalid
|
* @return string|bool short string or false for invalid
|
||||||
*/
|
*/
|
||||||
@@ -227,7 +229,7 @@ class Email
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* check email with all regex checks possible and return errors as array
|
||||||
*
|
*
|
||||||
* @param string $email Email address, will be checkd as lower
|
* @param string $email Email address, will be checkd as lower
|
||||||
* @param bool $error_code_only If this is set to true it will only return
|
* @param bool $error_code_only If this is set to true it will only return
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class File
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* quick return the extension of the given file name
|
* quick return the extension of the given file name
|
||||||
|
*
|
||||||
* @param string $filename file name
|
* @param string $filename file name
|
||||||
* @return string extension of the file name
|
* @return string extension of the file name
|
||||||
*/
|
*/
|
||||||
@@ -23,6 +24,7 @@ class File
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get lines in a file
|
* get lines in a file
|
||||||
|
*
|
||||||
* @param string $file file for line count read
|
* @param string $file file for line count read
|
||||||
* @return int number of lines or -1 for non readable file
|
* @return int number of lines or -1 for non readable file
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use CoreLibs\Convert\Json;
|
|||||||
|
|
||||||
class Jason
|
class Jason
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|null $json a json string, or null data
|
* @param string|null $json a json string, or null data
|
||||||
* @param bool $override if set to true, then on json error
|
* @param bool $override if set to true, then on json error
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class Password
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* creates the password hash
|
* creates the password hash
|
||||||
|
*
|
||||||
* @param string $password password
|
* @param string $password password
|
||||||
* @return string hashed password
|
* @return string hashed password
|
||||||
*/
|
*/
|
||||||
@@ -25,6 +26,7 @@ class Password
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* checks if the entered password matches the hash
|
* checks if the entered password matches the hash
|
||||||
|
*
|
||||||
* @param string $password password
|
* @param string $password password
|
||||||
* @param string $hash password hash
|
* @param string $hash password hash
|
||||||
* @return bool true or false
|
* @return bool true or false
|
||||||
@@ -40,6 +42,7 @@ class Password
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* checks if the password needs to be rehashed
|
* checks if the password needs to be rehashed
|
||||||
|
*
|
||||||
* @param string $hash password hash
|
* @param string $hash password hash
|
||||||
* @return bool true or false
|
* @return bool true or false
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class PhpVersion
|
|||||||
* checks if running PHP version matches given PHP version (min or max)
|
* checks if running PHP version matches given PHP version (min or max)
|
||||||
* if either is empty or null it will be ignored
|
* if either is empty or null it will be ignored
|
||||||
* if no min version (null or empty)
|
* if no min version (null or empty)
|
||||||
|
*
|
||||||
* @param string|null $min_version minimum version as string (x, x.y, x.y.x)
|
* @param string|null $min_version minimum version as string (x, x.y, x.y.x)
|
||||||
* @param string|null $max_version optional maximum version as string (x, x.y, x.y.x)
|
* @param string|null $max_version optional maximum version as string (x, x.y, x.y.x)
|
||||||
* @return bool true if ok, false if not matching version
|
* @return bool true if ok, false if not matching version
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class ArrayHandler
|
|||||||
/**
|
/**
|
||||||
* searches key = value in an array / array
|
* searches key = value in an array / array
|
||||||
* only returns the first one found
|
* only returns the first one found
|
||||||
|
*
|
||||||
* @param string|int $needle needle (search for)
|
* @param string|int $needle needle (search for)
|
||||||
* @param array<mixed> $haystack haystack (search in)
|
* @param array<mixed> $haystack haystack (search in)
|
||||||
* @param string|null $key_search_for the key to look out for, default empty
|
* @param string|null $key_search_for the key to look out for, default empty
|
||||||
@@ -68,10 +69,12 @@ class ArrayHandler
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* recursive array search function, which returns all found not only the first one
|
* recursive array search function, which returns all found not only the first one
|
||||||
|
*
|
||||||
* @param string|int $needle needle (search for)
|
* @param string|int $needle needle (search for)
|
||||||
* @param array<mixed> $haystack haystack (search in)
|
* @param array<mixed> $haystack haystack (search in)
|
||||||
* @param string|int $key_search_for the key to look for in
|
* @param string|int $key_search_for the key to look for in
|
||||||
* @param bool $old [true], if set to false will return new flat layout
|
* @param bool $old [true], if set to false will
|
||||||
|
* return new flat layout
|
||||||
* @param array<mixed>|null $path recursive call for previous path
|
* @param array<mixed>|null $path recursive call for previous path
|
||||||
* @return array<mixed>|null all array elements paths where
|
* @return array<mixed>|null all array elements paths where
|
||||||
* the element was found
|
* the element was found
|
||||||
@@ -148,6 +151,7 @@ class ArrayHandler
|
|||||||
/**
|
/**
|
||||||
* array search simple. looks for key, value combination, if found, returns true
|
* array search simple. looks for key, value combination, if found, returns true
|
||||||
* on default does not strict check, so string '4' will match int 4 and vica versa
|
* on default does not strict check, so string '4' will match int 4 and vica versa
|
||||||
|
*
|
||||||
* @param array<mixed> $array search in as array
|
* @param array<mixed> $array search in as array
|
||||||
* @param string|int $key key (key to search in)
|
* @param string|int $key key (key to search in)
|
||||||
* @param string|int $value value (what to find)
|
* @param string|int $value value (what to find)
|
||||||
@@ -184,6 +188,7 @@ class ArrayHandler
|
|||||||
* ... etc
|
* ... etc
|
||||||
* bool key flag: true: handle keys as string or int
|
* bool key flag: true: handle keys as string or int
|
||||||
* default false: all keys are string
|
* default false: all keys are string
|
||||||
|
*
|
||||||
* @return array<mixed>|bool merged array
|
* @return array<mixed>|bool merged array
|
||||||
*/
|
*/
|
||||||
public static function arrayMergeRecursive()
|
public static function arrayMergeRecursive()
|
||||||
@@ -240,6 +245,7 @@ class ArrayHandler
|
|||||||
* array_diff only checks elements from A that are not in B, but not the
|
* array_diff only checks elements from A that are not in B, but not the
|
||||||
* other way around.
|
* other way around.
|
||||||
* Note that like array_diff this only checks first level values not keys
|
* Note that like array_diff this only checks first level values not keys
|
||||||
|
*
|
||||||
* @param array<mixed> $a array to compare a
|
* @param array<mixed> $a array to compare a
|
||||||
* @param array<mixed> $b array to compare b
|
* @param array<mixed> $b array to compare b
|
||||||
* @return array<mixed> array with missing elements from a & b
|
* @return array<mixed> array with missing elements from a & b
|
||||||
@@ -254,9 +260,12 @@ class ArrayHandler
|
|||||||
* search for the needle array elements in haystack and
|
* search for the needle array elements in haystack and
|
||||||
* return the ones found as an array,
|
* return the ones found as an array,
|
||||||
* is there nothing found, it returns FALSE (boolean)
|
* is there nothing found, it returns FALSE (boolean)
|
||||||
|
*
|
||||||
* @param array<mixed> $needle elements to search for
|
* @param array<mixed> $needle elements to search for
|
||||||
* @param array<mixed> $haystack array where the $needle elements should be searched int
|
* @param array<mixed> $haystack array where the $needle elements should
|
||||||
* @return array<mixed>|bool either the found elements or false for nothing found or error
|
* be searched int
|
||||||
|
* @return array<mixed>|bool either the found elements or
|
||||||
|
* false for nothing found or error
|
||||||
*/
|
*/
|
||||||
public static function inArrayAny(array $needle, array $haystack)
|
public static function inArrayAny(array $needle, array $haystack)
|
||||||
{
|
{
|
||||||
@@ -275,6 +284,7 @@ class ArrayHandler
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* creates out of a normal db_return array an assoc array
|
* creates out of a normal db_return array an assoc array
|
||||||
|
*
|
||||||
* @param array<mixed> $db_array return array from the database
|
* @param array<mixed> $db_array return array from the database
|
||||||
* @param string|int|bool $key key set, false for not set
|
* @param string|int|bool $key key set, false for not set
|
||||||
* @param string|int|bool $value value set, false for not set
|
* @param string|int|bool $value value set, false for not set
|
||||||
@@ -313,6 +323,7 @@ class ArrayHandler
|
|||||||
/**
|
/**
|
||||||
* converts multi dimensional array to a flat array
|
* converts multi dimensional array to a flat array
|
||||||
* does NOT preserve keys
|
* does NOT preserve keys
|
||||||
|
*
|
||||||
* @param array<mixed> $array multi dimensionial array
|
* @param array<mixed> $array multi dimensionial array
|
||||||
* @return array<mixed> flattened array
|
* @return array<mixed> flattened array
|
||||||
*/
|
*/
|
||||||
@@ -330,6 +341,7 @@ class ArrayHandler
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* will loop through an array recursivly and write the array keys back
|
* will loop through an array recursivly and write the array keys back
|
||||||
|
*
|
||||||
* @param array<mixed> $array multidemnsional array to flatten
|
* @param array<mixed> $array multidemnsional array to flatten
|
||||||
* @param array<mixed> $return recoursive pass on array of keys
|
* @param array<mixed> $return recoursive pass on array of keys
|
||||||
* @return array<mixed> flattened keys array
|
* @return array<mixed> flattened keys array
|
||||||
@@ -348,6 +360,7 @@ class ArrayHandler
|
|||||||
/**
|
/**
|
||||||
* as above will flatten an array, but in this case only the outmost
|
* as above will flatten an array, but in this case only the outmost
|
||||||
* leave nodes, all other keyswill be skipped
|
* leave nodes, all other keyswill be skipped
|
||||||
|
*
|
||||||
* @param array<mixed> $array multidemnsional array to flatten
|
* @param array<mixed> $array multidemnsional array to flatten
|
||||||
* @return array<mixed> flattened keys array
|
* @return array<mixed> flattened keys array
|
||||||
*/
|
*/
|
||||||
@@ -366,6 +379,7 @@ class ArrayHandler
|
|||||||
/**
|
/**
|
||||||
* searches for key -> value in an array tree and writes the value one level up
|
* searches for key -> value in an array tree and writes the value one level up
|
||||||
* this will remove this leaf will all other values
|
* this will remove this leaf will all other values
|
||||||
|
*
|
||||||
* @param array<mixed> $array nested array
|
* @param array<mixed> $array nested array
|
||||||
* @param string|int $search key to find that has no sub leaf
|
* @param string|int $search key to find that has no sub leaf
|
||||||
* and will be pushed up
|
* and will be pushed up
|
||||||
|
|||||||
@@ -66,9 +66,11 @@ class DateTime
|
|||||||
/**
|
/**
|
||||||
* a simple wrapper for the date format
|
* a simple wrapper for the date format
|
||||||
* if an invalid timestamp is give zero timestamp unix time is used
|
* if an invalid timestamp is give zero timestamp unix time is used
|
||||||
|
*
|
||||||
* @param int|float $timestamp unix timestamp
|
* @param int|float $timestamp unix timestamp
|
||||||
* @param bool $show_micro show the micro time (default false)
|
* @param bool $show_micro show the micro time (default false)
|
||||||
* @param bool $micro_as_float Add the micro time with . instead of ms (default false)
|
* @param bool $micro_as_float Add the micro time with . instead
|
||||||
|
* of ms (default false)
|
||||||
* @return string formated date+time in Y-M-D h:m:s ms
|
* @return string formated date+time in Y-M-D h:m:s ms
|
||||||
*/
|
*/
|
||||||
public static function dateStringFormat(
|
public static function dateStringFormat(
|
||||||
@@ -92,7 +94,9 @@ class DateTime
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* formats a timestamp into interval, not into a date
|
* formats a timestamp into interval, not into a date
|
||||||
* @param string|int|float $timestamp interval in seconds and optional float micro seconds
|
*
|
||||||
|
* @param string|int|float $timestamp interval in seconds and optional
|
||||||
|
* float micro seconds
|
||||||
* @param bool $show_micro show micro seconds, default true
|
* @param bool $show_micro show micro seconds, default true
|
||||||
* @return string interval formatted string or string as is
|
* @return string interval formatted string or string as is
|
||||||
*/
|
*/
|
||||||
@@ -149,6 +153,7 @@ class DateTime
|
|||||||
/**
|
/**
|
||||||
* does a reverse of the timeStringFormat and converts the string from
|
* does a reverse of the timeStringFormat and converts the string from
|
||||||
* xd xh xm xs xms to a timestamp.microtime format
|
* xd xh xm xs xms to a timestamp.microtime format
|
||||||
|
*
|
||||||
* @param string|int|float $timestring formatted interval
|
* @param string|int|float $timestring formatted interval
|
||||||
* @return string|int|float converted float interval, or string as is
|
* @return string|int|float converted float interval, or string as is
|
||||||
*/
|
*/
|
||||||
@@ -190,6 +195,7 @@ class DateTime
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* splits & checks date, wrap around for check_date function
|
* splits & checks date, wrap around for check_date function
|
||||||
|
*
|
||||||
* @param string $date a date string in the format YYYY-MM-DD
|
* @param string $date a date string in the format YYYY-MM-DD
|
||||||
* @return bool true if valid date, false if date not valid
|
* @return bool true if valid date, false if date not valid
|
||||||
*/
|
*/
|
||||||
@@ -214,6 +220,7 @@ class DateTime
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* splits & checks date, wrap around for check_date function
|
* splits & checks date, wrap around for check_date function
|
||||||
|
*
|
||||||
* @param string $datetime date (YYYY-MM-DD) + time (HH:MM:SS), SS can be dropped
|
* @param string $datetime date (YYYY-MM-DD) + time (HH:MM:SS), SS can be dropped
|
||||||
* @return bool true if valid date, false if date not valid
|
* @return bool true if valid date, false if date not valid
|
||||||
*/
|
*/
|
||||||
@@ -263,6 +270,7 @@ class DateTime
|
|||||||
* 0 if both are equal
|
* 0 if both are equal
|
||||||
* 1 if the first date is bigger than the last
|
* 1 if the first date is bigger than the last
|
||||||
* false (bool): error
|
* false (bool): error
|
||||||
|
*
|
||||||
* @param string $start_date start date string in YYYY-MM-DD
|
* @param string $start_date start date string in YYYY-MM-DD
|
||||||
* @param string $end_date end date string in YYYY-MM-DD
|
* @param string $end_date end date string in YYYY-MM-DD
|
||||||
* @return int|bool false on error, or int -1/0/1 as difference
|
* @return int|bool false on error, or int -1/0/1 as difference
|
||||||
@@ -297,12 +305,14 @@ class DateTime
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* compares the two dates + times. if seconds missing in one set, add :00, converts / to -
|
* compares the two dates + times. if seconds missing in one set,
|
||||||
|
* add :00, converts / to -
|
||||||
* returns int/bool in:
|
* returns int/bool in:
|
||||||
* -1 if the first date is smaller the last
|
* -1 if the first date is smaller the last
|
||||||
* 0 if both are equal
|
* 0 if both are equal
|
||||||
* 1 if the first date is bigger than the last
|
* 1 if the first date is bigger than the last
|
||||||
* false if no valid date/times chould be found
|
* false if no valid date/times chould be found
|
||||||
|
*
|
||||||
* @param string $start_datetime start date/time in YYYY-MM-DD HH:mm:ss
|
* @param string $start_datetime start date/time in YYYY-MM-DD HH:mm:ss
|
||||||
* @param string $end_datetime end date/time in YYYY-MM-DD HH:mm:ss
|
* @param string $end_datetime end date/time in YYYY-MM-DD HH:mm:ss
|
||||||
* @return int|bool false for error or -1/0/1 as difference
|
* @return int|bool false for error or -1/0/1 as difference
|
||||||
@@ -336,6 +346,7 @@ class DateTime
|
|||||||
* calculates the days between two dates
|
* calculates the days between two dates
|
||||||
* return: overall days, week days, weekend days as array 0...2 or named
|
* return: overall days, week days, weekend days as array 0...2 or named
|
||||||
* as overall, weekday and weekend
|
* as overall, weekday and weekend
|
||||||
|
*
|
||||||
* @param string $start_date valid start date (y/m/d)
|
* @param string $start_date valid start date (y/m/d)
|
||||||
* @param string $end_date valid end date (y/m/d)
|
* @param string $end_date valid end date (y/m/d)
|
||||||
* @param bool $return_named return array type, false (default), true for named
|
* @param bool $return_named return array type, false (default), true for named
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class Byte
|
|||||||
* BYTE_FORMAT_ADJUST [2] use sprintf to always print two decimals
|
* BYTE_FORMAT_ADJUST [2] use sprintf to always print two decimals
|
||||||
* BYTE_FORMAT_SI [3] use si standard 1000 instead of bytes 1024
|
* BYTE_FORMAT_SI [3] use si standard 1000 instead of bytes 1024
|
||||||
* To use the constant from outside use class::CONSTANT
|
* To use the constant from outside use class::CONSTANT
|
||||||
|
*
|
||||||
* @param string|int|float $bytes bytes as string int or pure int
|
* @param string|int|float $bytes bytes as string int or pure int
|
||||||
* @param int $flags bitwise flag with use space turned on
|
* @param int $flags bitwise flag with use space turned on
|
||||||
* @return string converted byte number (float) with suffix
|
* @return string converted byte number (float) with suffix
|
||||||
@@ -106,6 +107,7 @@ class Byte
|
|||||||
* NOTE: large exabyte numbers will overflow
|
* NOTE: large exabyte numbers will overflow
|
||||||
* flag allowed:
|
* flag allowed:
|
||||||
* BYTE_FORMAT_SI [3] use si standard 1000 instead of bytes 1024
|
* BYTE_FORMAT_SI [3] use si standard 1000 instead of bytes 1024
|
||||||
|
*
|
||||||
* @param string|int|float $number any string or number to convert
|
* @param string|int|float $number any string or number to convert
|
||||||
* @param int $flags bitwise flag with use space turned on
|
* @param int $flags bitwise flag with use space turned on
|
||||||
* @return string|int|float converted value or original value
|
* @return string|int|float converted value or original value
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class Colors
|
|||||||
* converts the rgb values from int data to the valid rgb html hex string
|
* converts the rgb values from int data to the valid rgb html hex string
|
||||||
* optional can turn of leading #
|
* optional can turn of leading #
|
||||||
* if one value is invalid, will return false
|
* if one value is invalid, will return false
|
||||||
|
*
|
||||||
* @param int $red red 0-255
|
* @param int $red red 0-255
|
||||||
* @param int $green green 0-255
|
* @param int $green green 0-255
|
||||||
* @param int $blue blue 0-255
|
* @param int $blue blue 0-255
|
||||||
@@ -49,6 +50,7 @@ class Colors
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* converts a hex RGB color to the int numbers
|
* converts a hex RGB color to the int numbers
|
||||||
|
*
|
||||||
* @param string $hexStr RGB hexstring
|
* @param string $hexStr RGB hexstring
|
||||||
* @param bool $return_as_string flag to return as string
|
* @param bool $return_as_string flag to return as string
|
||||||
* @param string $seperator string seperator: default: ","
|
* @param string $seperator string seperator: default: ","
|
||||||
@@ -90,6 +92,7 @@ class Colors
|
|||||||
* converts RGB to HSB/V values
|
* converts RGB to HSB/V values
|
||||||
* returns:
|
* returns:
|
||||||
* array with hue (0-360), sat (0-100%), brightness/value (0-100%)
|
* array with hue (0-360), sat (0-100%), brightness/value (0-100%)
|
||||||
|
*
|
||||||
* @param int $red red 0-255
|
* @param int $red red 0-255
|
||||||
* @param int $green green 0-255
|
* @param int $green green 0-255
|
||||||
* @param int $blue blue 0-255
|
* @param int $blue blue 0-255
|
||||||
@@ -136,6 +139,7 @@ class Colors
|
|||||||
* hsb2rgb does not clean convert back to hsb in a round trip
|
* hsb2rgb does not clean convert back to hsb in a round trip
|
||||||
* converts HSB/V to RGB values RGB is full INT
|
* converts HSB/V to RGB values RGB is full INT
|
||||||
* if HSB/V value is invalid, sets this value to 0
|
* if HSB/V value is invalid, sets this value to 0
|
||||||
|
*
|
||||||
* @param float $H hue 0-360 (int)
|
* @param float $H hue 0-360 (int)
|
||||||
* @param float $S saturation 0-100 (int)
|
* @param float $S saturation 0-100 (int)
|
||||||
* @param float $V brightness/value 0-100 (int)
|
* @param float $V brightness/value 0-100 (int)
|
||||||
@@ -218,6 +222,7 @@ class Colors
|
|||||||
* converts a RGB (0-255) to HSL
|
* converts a RGB (0-255) to HSL
|
||||||
* return:
|
* return:
|
||||||
* array with hue (0-360), saturation (0-100%) and luminance (0-100%)
|
* array with hue (0-360), saturation (0-100%) and luminance (0-100%)
|
||||||
|
*
|
||||||
* @param int $red red 0-255
|
* @param int $red red 0-255
|
||||||
* @param int $green green 0-255
|
* @param int $green green 0-255
|
||||||
* @param int $blue blue 0-255
|
* @param int $blue blue 0-255
|
||||||
@@ -271,6 +276,7 @@ class Colors
|
|||||||
/**
|
/**
|
||||||
* converts an HSL to RGB
|
* converts an HSL to RGB
|
||||||
* if HSL value is invalid, set this value to 0
|
* if HSL value is invalid, set this value to 0
|
||||||
|
*
|
||||||
* @param float $hue hue: 0-360 (degrees)
|
* @param float $hue hue: 0-360 (degrees)
|
||||||
* @param float $sat saturation: 0-100
|
* @param float $sat saturation: 0-100
|
||||||
* @param float $lum luminance: 0-100
|
* @param float $lum luminance: 0-100
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class Html
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* full wrapper for html entities
|
* full wrapper for html entities
|
||||||
|
*
|
||||||
* @param mixed $string string to html encode
|
* @param mixed $string string to html encode
|
||||||
* @return mixed if string, encoded, else as is (eg null)
|
* @return mixed if string, encoded, else as is (eg null)
|
||||||
*/
|
*/
|
||||||
@@ -42,10 +43,14 @@ class Html
|
|||||||
* returns 'checked' or 'selected' if okay
|
* returns 'checked' or 'selected' if okay
|
||||||
* $needle is a var, $haystack an array or a string
|
* $needle is a var, $haystack an array or a string
|
||||||
* **** THE RETURN: VALUE WILL CHANGE TO A DEFAULT NULL IF NOT FOUND ****
|
* **** THE RETURN: VALUE WILL CHANGE TO A DEFAULT NULL IF NOT FOUND ****
|
||||||
* @param array<mixed>|string $haystack (search in) haystack can be an array or a string
|
*
|
||||||
|
* @param array<mixed>|string $haystack (search in) haystack can be
|
||||||
|
* an array or a string
|
||||||
* @param string $needle needle (search for)
|
* @param string $needle needle (search for)
|
||||||
* @param int $type type: 0: returns selected, 1, returns checked
|
* @param int $type type: 0: returns selected, 1,
|
||||||
* @return ?string returns checked or selected, else returns null
|
* returns checked
|
||||||
|
* @return ?string returns checked or selected,
|
||||||
|
* else returns null
|
||||||
*/
|
*/
|
||||||
public static function checked($haystack, string $needle, int $type = 0): ?string
|
public static function checked($haystack, string $needle, int $type = 0): ?string
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class Json
|
|||||||
* or failed convert to array
|
* or failed convert to array
|
||||||
* In ANY case it will ALWAYS return array.
|
* In ANY case it will ALWAYS return array.
|
||||||
* Does not throw errors
|
* Does not throw errors
|
||||||
|
*
|
||||||
* @param string|null $json a json string, or null data
|
* @param string|null $json a json string, or null data
|
||||||
* @param bool $override if set to true, then on json error
|
* @param bool $override if set to true, then on json error
|
||||||
* set original value as array
|
* set original value as array
|
||||||
@@ -49,6 +50,7 @@ class Json
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* returns human readable string for json errors thrown in jsonConvertToArray
|
* returns human readable string for json errors thrown in jsonConvertToArray
|
||||||
|
*
|
||||||
* @param bool|boolean $return_string [default=false] if set to true
|
* @param bool|boolean $return_string [default=false] if set to true
|
||||||
* it will return the message string and not
|
* it will return the message string and not
|
||||||
* the error number
|
* the error number
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class Math
|
|||||||
/**
|
/**
|
||||||
* some float numbers will be rounded up even if they have no decimal entries
|
* some float numbers will be rounded up even if they have no decimal entries
|
||||||
* this function fixes this by pre-rounding before calling ceil
|
* this function fixes this by pre-rounding before calling ceil
|
||||||
|
*
|
||||||
* @param float $number number to round
|
* @param float $number number to round
|
||||||
* @param int|integer $precision intermediat round up decimals (default 10)
|
* @param int|integer $precision intermediat round up decimals (default 10)
|
||||||
* @return float correct ceil number
|
* @return float correct ceil number
|
||||||
@@ -25,6 +26,7 @@ class Math
|
|||||||
/**
|
/**
|
||||||
* round inside an a number, not the decimal part only
|
* round inside an a number, not the decimal part only
|
||||||
* eg 48767 with -2 -> 48700
|
* eg 48767 with -2 -> 48700
|
||||||
|
*
|
||||||
* @param float $number number to round
|
* @param float $number number to round
|
||||||
* @param int $precision negative number for position in number (default -2)
|
* @param int $precision negative number for position in number (default -2)
|
||||||
* @return float rounded number
|
* @return float rounded number
|
||||||
@@ -42,6 +44,7 @@ class Math
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* inits input to 0, if value is not numeric
|
* inits input to 0, if value is not numeric
|
||||||
|
*
|
||||||
* @param string|int|float $number string or number to check
|
* @param string|int|float $number string or number to check
|
||||||
* @return float if not number, then returns 0, else original input
|
* @return float if not number, then returns 0, else original input
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class MimeAppName
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets or updates a mime type
|
* Sets or updates a mime type
|
||||||
|
*
|
||||||
* @param string $mime MIME Name, no validiation
|
* @param string $mime MIME Name, no validiation
|
||||||
* @param string $app Applicaiton name
|
* @param string $app Applicaiton name
|
||||||
* @return void
|
* @return void
|
||||||
@@ -71,6 +72,7 @@ class MimeAppName
|
|||||||
/**
|
/**
|
||||||
* get the application name from mime type
|
* get the application name from mime type
|
||||||
* if not set returns "Other file"
|
* if not set returns "Other file"
|
||||||
|
*
|
||||||
* @param string $mime MIME Name
|
* @param string $mime MIME Name
|
||||||
* @return string Application name matching
|
* @return string Application name matching
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class Hash
|
|||||||
* hash returns false
|
* hash returns false
|
||||||
* preg_replace fails for older php version
|
* preg_replace fails for older php version
|
||||||
* Use __hash with crc32b or hash('crc32b', ...) for correct output
|
* Use __hash with crc32b or hash('crc32b', ...) for correct output
|
||||||
|
*
|
||||||
* @param string $string string to crc
|
* @param string $string string to crc
|
||||||
* @return string crc32b hash (old type)
|
* @return string crc32b hash (old type)
|
||||||
*/
|
*/
|
||||||
@@ -39,6 +40,7 @@ class Hash
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* replacement for __crc32b call
|
* replacement for __crc32b call
|
||||||
|
*
|
||||||
* @param string $string string to hash
|
* @param string $string string to hash
|
||||||
* @param bool $use_sha use sha instead of crc32b (default false)
|
* @param bool $use_sha use sha instead of crc32b (default false)
|
||||||
* @return string hash of the string
|
* @return string hash of the string
|
||||||
@@ -58,6 +60,7 @@ class Hash
|
|||||||
* defaults to adler 32
|
* defaults to adler 32
|
||||||
* allowed crc32b, adler32, fnv132, fnv1a32, joaat
|
* allowed crc32b, adler32, fnv132, fnv1a32, joaat
|
||||||
* all that create 8 char long hashes
|
* all that create 8 char long hashes
|
||||||
|
*
|
||||||
* @param string $string string to hash
|
* @param string $string string to hash
|
||||||
* @param string $hash_type hash type (default adler32)
|
* @param string $hash_type hash type (default adler32)
|
||||||
* @return string hash of the string
|
* @return string hash of the string
|
||||||
@@ -79,6 +82,7 @@ class Hash
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper function for standard long hashd
|
* Wrapper function for standard long hashd
|
||||||
|
*
|
||||||
* @param string $string String to be hashed
|
* @param string $string String to be hashed
|
||||||
* @return string Hashed string
|
* @return string Hashed string
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class RandomKey
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* sets the random key range with the default values
|
* sets the random key range with the default values
|
||||||
|
*
|
||||||
* @return void has no return
|
* @return void has no return
|
||||||
*/
|
*/
|
||||||
private static function initRandomKeyData()
|
private static function initRandomKeyData()
|
||||||
@@ -44,6 +45,7 @@ class RandomKey
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* validates they key length for random string generation
|
* validates they key length for random string generation
|
||||||
|
*
|
||||||
* @param int $key_length key length
|
* @param int $key_length key length
|
||||||
* @return bool true for valid, false for invalid length
|
* @return bool true for valid, false for invalid length
|
||||||
*/
|
*/
|
||||||
@@ -63,6 +65,7 @@ class RandomKey
|
|||||||
/**
|
/**
|
||||||
* sets the key length and checks that they key given is valid
|
* sets the key length and checks that they key given is valid
|
||||||
* if failed it will not change the default key length and return false
|
* if failed it will not change the default key length and return false
|
||||||
|
*
|
||||||
* @param int $key_length key length
|
* @param int $key_length key length
|
||||||
* @return bool true/false for set status
|
* @return bool true/false for set status
|
||||||
*/
|
*/
|
||||||
@@ -91,6 +94,7 @@ class RandomKey
|
|||||||
* creates a random key based on the key_range with key_length
|
* creates a random key based on the key_range with key_length
|
||||||
* if override key length is set, it will check on valid key and use this
|
* if override key length is set, it will check on valid key and use this
|
||||||
* this will not set the class key length variable
|
* this will not set the class key length variable
|
||||||
|
*
|
||||||
* @param int $key_length key length override, -1 for use default
|
* @param int $key_length key length override, -1 for use default
|
||||||
* @return string random key
|
* @return string random key
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,8 +15,21 @@ namespace CoreLibs\Create;
|
|||||||
|
|
||||||
class Session
|
class Session
|
||||||
{
|
{
|
||||||
/** @var string list for errors*/
|
/** @var string list for errors */
|
||||||
private $error_str = '';
|
private $session_intern_error_str = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start session
|
||||||
|
* startSession should be called for complete check
|
||||||
|
* If this is called without any name set before the php.ini name is
|
||||||
|
* used.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function startSessionCall(): void
|
||||||
|
{
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init a session, if array is empty or array does not have session_name set
|
* init a session, if array is empty or array does not have session_name set
|
||||||
@@ -32,23 +45,41 @@ class Session
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if we are in CLI, we set this, so we can mock this too
|
* check if we are in CLI, we set this, so we can mock this
|
||||||
|
* Not this is just a wrapper for the static System::checkCLI call
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool True if we are in a CLI enviroment, or false for everything else
|
||||||
*/
|
*/
|
||||||
private function checkCLI(): bool
|
public function checkCliStatus(): bool
|
||||||
{
|
{
|
||||||
return \CoreLibs\Get\System::checkCLI();
|
return \CoreLibs\Get\System::checkCLI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set session name call. If not valid session name, will return false
|
||||||
|
*
|
||||||
|
* @param string $session_name A valid string for session name
|
||||||
|
* @return bool True if session name is valid,
|
||||||
|
* False if not
|
||||||
|
*/
|
||||||
|
public function setSessionName(string $session_name): bool
|
||||||
|
{
|
||||||
|
if (!$this->checkValidSessionName($session_name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
session_name($session_name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return set error string, empty if none set
|
* Return set error string, empty if none set
|
||||||
|
* Error strings are only set in the startSession method
|
||||||
*
|
*
|
||||||
* @return string Last error string
|
* @return string Last error string
|
||||||
*/
|
*/
|
||||||
public function getErrorStr(): string
|
public function getErrorStr(): string
|
||||||
{
|
{
|
||||||
return $this->error_str;
|
return $this->session_intern_error_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,13 +119,13 @@ class Session
|
|||||||
public function startSession(?string $session_name = null)
|
public function startSession(?string $session_name = null)
|
||||||
{
|
{
|
||||||
// we can't start sessions on command line
|
// we can't start sessions on command line
|
||||||
if ($this->checkCLI()) {
|
if ($this->checkCliStatus()) {
|
||||||
$this->error_str = '[SESSION] No sessions in php cli';
|
$this->session_intern_error_str = '[SESSION] No sessions in php cli';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// if session are OFF
|
// if session are OFF
|
||||||
if ($this->getSessionStatus() === PHP_SESSION_DISABLED) {
|
if ($this->getSessionStatus() === PHP_SESSION_DISABLED) {
|
||||||
$this->error_str = '[SESSION] Sessions are disabled';
|
$this->session_intern_error_str = '[SESSION] Sessions are disabled';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// session_status
|
// session_status
|
||||||
@@ -108,20 +139,23 @@ class Session
|
|||||||
if (!empty($session_name)) {
|
if (!empty($session_name)) {
|
||||||
// invalid session name, abort
|
// invalid session name, abort
|
||||||
if (!$this->checkValidSessionName($session_name)) {
|
if (!$this->checkValidSessionName($session_name)) {
|
||||||
$this->error_str = '[SESSION] Invalid session name: ' . $session_name;
|
$this->session_intern_error_str = '[SESSION] Invalid session name: ' . $session_name;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
session_name($session_name);
|
$this->setSessionName($session_name);
|
||||||
}
|
}
|
||||||
// start session
|
// start session
|
||||||
session_start();
|
$this->startSessionCall();
|
||||||
}
|
}
|
||||||
// if we still have no active session
|
// if we still have no active session
|
||||||
if (!$this->checkActiveSession()) {
|
if (!$this->checkActiveSession()) {
|
||||||
$this->error_str = '[SESSION] Failed to activate session';
|
$this->session_intern_error_str = '[SESSION] Failed to activate session';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $this->getSessionId();
|
if (false === ($session_id = $this->getSessionId())) {
|
||||||
|
$this->session_intern_error_str = '[SESSION] getSessionId did not return a session id';
|
||||||
|
}
|
||||||
|
return $session_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,6 +206,39 @@ class Session
|
|||||||
return session_write_close();
|
return session_write_close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Proper destroy a session
|
||||||
|
* - unset the _SESSION array
|
||||||
|
* - unset cookie if cookie on and we have not strict mode
|
||||||
|
* - destroy session
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function sessionDestroy(): bool
|
||||||
|
{
|
||||||
|
$_SESSION = [];
|
||||||
|
if (
|
||||||
|
ini_get('session.use_cookies') &&
|
||||||
|
!ini_get('session.use_strict_mode')
|
||||||
|
) {
|
||||||
|
$session_name = $this->getSessionName();
|
||||||
|
if ($session_name === false) {
|
||||||
|
$session_name = '';
|
||||||
|
}
|
||||||
|
$params = session_get_cookie_params();
|
||||||
|
setcookie(
|
||||||
|
(string)$session_name,
|
||||||
|
'',
|
||||||
|
time() - 42000,
|
||||||
|
$params['path'],
|
||||||
|
$params['domain'],
|
||||||
|
$params['secure'],
|
||||||
|
$params['httponly']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return session_destroy();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get session status
|
* get session status
|
||||||
* PHP_SESSION_DISABLED if sessions are disabled.
|
* PHP_SESSION_DISABLED if sessions are disabled.
|
||||||
@@ -180,12 +247,125 @@ class Session
|
|||||||
*
|
*
|
||||||
* https://www.php.net/manual/en/function.session-status.php
|
* https://www.php.net/manual/en/function.session-status.php
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int See possible return int values above
|
||||||
*/
|
*/
|
||||||
public function getSessionStatus(): int
|
public function getSessionStatus(): int
|
||||||
{
|
{
|
||||||
return session_status();
|
return session_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _SESSION set/unset methods
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unset all _SESSION entries
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function unsetAllS(): void
|
||||||
|
{
|
||||||
|
foreach (array_keys($_SESSION ?? []) as $name) {
|
||||||
|
unset($_SESSION[$name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set _SESSION entry 'name' with any value
|
||||||
|
*
|
||||||
|
* @param string|int $name array name in _SESSION
|
||||||
|
* @param mixed $value value to set (can be anything)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setS($name, $value): void
|
||||||
|
{
|
||||||
|
$_SESSION[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get _SESSION 'name' entry or empty string if not set
|
||||||
|
*
|
||||||
|
* @param string|int $name value key to get from _SESSION
|
||||||
|
* @return mixed value stored in _SESSION
|
||||||
|
*/
|
||||||
|
public function getS($name)
|
||||||
|
{
|
||||||
|
return $_SESSION[$name] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a name is set in the _SESSION array
|
||||||
|
*
|
||||||
|
* @param string|int $name Name to check for
|
||||||
|
* @return bool True for set, False fornot set
|
||||||
|
*/
|
||||||
|
public function issetS($name): bool
|
||||||
|
{
|
||||||
|
return isset($_SESSION[$name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unset one _SESSION entry 'name' if exists
|
||||||
|
*
|
||||||
|
* @param string|int $name _SESSION key name to remove
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function unsetS($name): void
|
||||||
|
{
|
||||||
|
if (isset($_SESSION[$name])) {
|
||||||
|
unset($_SESSION[$name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set/get below
|
||||||
|
// ->var = value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @param string|int $name
|
||||||
|
* @param mixed $value
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __set($name, $value): void
|
||||||
|
{
|
||||||
|
$_SESSION[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @param string|int $name
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function __get($name)
|
||||||
|
{
|
||||||
|
if (isset($_SESSION[$name])) {
|
||||||
|
return $_SESSION[$name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @param string|int $name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function __isset($name): bool
|
||||||
|
{
|
||||||
|
return isset($_SESSION[$name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @param string|int $name
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __unset($name): void
|
||||||
|
{
|
||||||
|
if (isset($_SESSION[$name])) {
|
||||||
|
unset($_SESSION[$name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class Uids
|
|||||||
* creates psuedo random uuid v4
|
* creates psuedo random uuid v4
|
||||||
* Code take from class here:
|
* Code take from class here:
|
||||||
* https://www.php.net/manual/en/function.uniqid.php#94959
|
* https://www.php.net/manual/en/function.uniqid.php#94959
|
||||||
|
*
|
||||||
* @return string pseudo random uuid v4
|
* @return string pseudo random uuid v4
|
||||||
*/
|
*/
|
||||||
public static function uuidv4(): string
|
public static function uuidv4(): string
|
||||||
@@ -44,6 +45,7 @@ class Uids
|
|||||||
* TODO: make this a proper uniq ID creation
|
* TODO: make this a proper uniq ID creation
|
||||||
* add uuidv4 subcall to the uuid function too
|
* add uuidv4 subcall to the uuid function too
|
||||||
* creates a uniq id
|
* creates a uniq id
|
||||||
|
*
|
||||||
* @param string $type uniq id type, currently md5 or sha256 allowed
|
* @param string $type uniq id type, currently md5 or sha256 allowed
|
||||||
* if not set will use DEFAULT_HASH if set
|
* if not set will use DEFAULT_HASH if set
|
||||||
* @return string uniq id
|
* @return string uniq id
|
||||||
@@ -81,7 +83,7 @@ class Uids
|
|||||||
return $uniq_id;
|
return $uniq_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a unique id with the standard hash type defined in __hash
|
* create a unique id with the standard hash type defined in __hash
|
||||||
*
|
*
|
||||||
* @return string Unique ID with fixed length of 8 characters
|
* @return string Unique ID with fixed length of 8 characters
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
/**
|
/**
|
||||||
* constructor for the array io class, set the
|
* constructor for the array io class, set the
|
||||||
* primary key name automatically (from array)
|
* primary key name automatically (from array)
|
||||||
|
*
|
||||||
* @param array<mixed> $db_config db connection config
|
* @param array<mixed> $db_config db connection config
|
||||||
* @param array<mixed> $table_array table array config
|
* @param array<mixed> $table_array table array config
|
||||||
* @param string $table_name table name string
|
* @param string $table_name table name string
|
||||||
@@ -93,6 +94,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
* works for <b>,<i>, and <a> (thought <a> can be / or should
|
* works for <b>,<i>, and <a> (thought <a> can be / or should
|
||||||
* be handled with the magic links functions
|
* be handled with the magic links functions
|
||||||
* used with the read function
|
* used with the read function
|
||||||
|
*
|
||||||
* @param string $text any html encoded string
|
* @param string $text any html encoded string
|
||||||
* @return string decoded html string
|
* @return string decoded html string
|
||||||
*/
|
*/
|
||||||
@@ -111,6 +113,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* changeds all HTML entities into non HTML ones
|
* changeds all HTML entities into non HTML ones
|
||||||
|
*
|
||||||
* @param string $text encoded html string
|
* @param string $text encoded html string
|
||||||
* @return string decoded html string
|
* @return string decoded html string
|
||||||
*/
|
*/
|
||||||
@@ -126,6 +129,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* dumps the current data
|
* dumps the current data
|
||||||
|
*
|
||||||
* @param bool $write write to error message, default false
|
* @param bool $write write to error message, default false
|
||||||
* @return string the array data as html string entry
|
* @return string the array data as html string entry
|
||||||
*/
|
*/
|
||||||
@@ -144,7 +148,9 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks if pk is set and if not, set from pk_id and if this also not set return 0
|
* checks if pk is set and if not, set from pk_id and
|
||||||
|
* if this also not set return 0
|
||||||
|
*
|
||||||
* @return bool true if pk value is set, else false
|
* @return bool true if pk value is set, else false
|
||||||
*/
|
*/
|
||||||
public function dbCheckPkSet()
|
public function dbCheckPkSet()
|
||||||
@@ -171,7 +177,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
public function dbResetArray($reset_pk = false): void
|
public function dbResetArray($reset_pk = false): void
|
||||||
{
|
{
|
||||||
reset($this->table_array);
|
reset($this->table_array);
|
||||||
foreach ($this->table_array as $column => $data_array) {
|
foreach (array_keys($this->table_array) as $column) {
|
||||||
if (!$this->table_array[$column]['pk']) {
|
if (!$this->table_array[$column]['pk']) {
|
||||||
unset($this->table_array[$column]['value']);
|
unset($this->table_array[$column]['value']);
|
||||||
} elseif ($reset_pk) {
|
} elseif ($reset_pk) {
|
||||||
@@ -182,6 +188,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* deletes one dataset
|
* deletes one dataset
|
||||||
|
*
|
||||||
* @param array<mixed> $table_array optional override for table array set
|
* @param array<mixed> $table_array optional override for table array set
|
||||||
* set this as new table array too
|
* set this as new table array too
|
||||||
* @return array<mixed> returns the table array that was deleted
|
* @return array<mixed> returns the table array that was deleted
|
||||||
@@ -201,7 +208,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
// delete files and build FK query
|
// delete files and build FK query
|
||||||
reset($this->table_array);
|
reset($this->table_array);
|
||||||
$q_where = '';
|
$q_where = '';
|
||||||
foreach ($this->table_array as $column => $data_array) {
|
foreach (array_keys($this->table_array) as $column) {
|
||||||
// suchen nach bildern und lschen ...
|
// suchen nach bildern und lschen ...
|
||||||
if (
|
if (
|
||||||
!empty($this->table_array[$column]['file']) &&
|
!empty($this->table_array[$column]['file']) &&
|
||||||
@@ -241,8 +248,10 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* reads one row into the array
|
* reads one row into the array
|
||||||
|
*
|
||||||
* @param boolean $edit on true convert data, else as is
|
* @param boolean $edit on true convert data, else as is
|
||||||
* @param array<mixed> $table_array optional table array, overwrites internal set array
|
* @param array<mixed> $table_array optional table array, overwrites
|
||||||
|
* internal set array
|
||||||
* @return array<mixed> set table array with values
|
* @return array<mixed> set table array with values
|
||||||
*/
|
*/
|
||||||
public function dbRead($edit = false, $table_array = [])
|
public function dbRead($edit = false, $table_array = [])
|
||||||
@@ -262,11 +271,22 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
if ($q_select) {
|
if ($q_select) {
|
||||||
$q_select .= ', ';
|
$q_select .= ', ';
|
||||||
}
|
}
|
||||||
$q_select .= $column;
|
if (
|
||||||
|
!empty($data_array['type']) && $data_array['type'] == 'datetime' &&
|
||||||
|
!empty($data_array['sql_read'])
|
||||||
|
) {
|
||||||
|
// convert tom different timestamp type
|
||||||
|
$q_select .= "TO_CHAR($column, '" . $data_array['sql_read'] . "') AS $column";
|
||||||
|
} else {
|
||||||
|
$q_select .= $column;
|
||||||
|
}
|
||||||
|
|
||||||
// check FK ...
|
// check FK ...
|
||||||
if (isset($this->table_array[$column]['fk']) && isset($this->table_array[$column]['value'])) {
|
if (
|
||||||
if ($q_where) {
|
isset($this->table_array[$column]['fk']) &&
|
||||||
|
isset($this->table_array[$column]['value'])
|
||||||
|
) {
|
||||||
|
if (!empty($q_where)) {
|
||||||
$q_where .= ' AND ';
|
$q_where .= ' AND ';
|
||||||
}
|
}
|
||||||
$q_where .= $column .= ' = ' . $this->table_array[$column]['value'];
|
$q_where .= $column .= ' = ' . $this->table_array[$column]['value'];
|
||||||
@@ -315,6 +335,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* writes one set into DB or updates one set (if PK exists)
|
* writes one set into DB or updates one set (if PK exists)
|
||||||
|
*
|
||||||
* @param boolean $addslashes old convert entities and set set escape
|
* @param boolean $addslashes old convert entities and set set escape
|
||||||
* @param array<mixed> $table_array optional table array, overwrites internal one
|
* @param array<mixed> $table_array optional table array, overwrites internal one
|
||||||
* @return array<mixed> table array or null
|
* @return array<mixed> table array or null
|
||||||
@@ -440,7 +461,12 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
} elseif (isset($this->table_array[$column]['bool'])) {
|
} elseif (isset($this->table_array[$column]['bool'])) {
|
||||||
// boolean storeage (reverse check on ifset)
|
// boolean storeage (reverse check on ifset)
|
||||||
$q_data .= "'" . $this->dbBoolean($this->table_array[$column]['value'], true) . "'";
|
$q_data .= "'" . $this->dbBoolean($this->table_array[$column]['value'], true) . "'";
|
||||||
} elseif (isset($this->table_array[$column]['interval'])) {
|
} elseif (
|
||||||
|
isset($this->table_array[$column]['interval']) ||
|
||||||
|
isset($this->table_array[$column]['date']) ||
|
||||||
|
isset($this->table_array[$column]['datetime']) ||
|
||||||
|
isset($this->table_array[$column]['emptynull'])
|
||||||
|
) {
|
||||||
// for interval we check if no value, then we set null
|
// for interval we check if no value, then we set null
|
||||||
if (
|
if (
|
||||||
!isset($this->table_array[$column]['value']) ||
|
!isset($this->table_array[$column]['value']) ||
|
||||||
@@ -448,7 +474,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
) {
|
) {
|
||||||
$_value = 'NULL';
|
$_value = 'NULL';
|
||||||
} elseif (isset($this->table_array[$column]['value'])) {
|
} elseif (isset($this->table_array[$column]['value'])) {
|
||||||
$_value = $this->table_array[$column]['value'];
|
$_value = $this->dbEscapeLiteral($this->table_array[$column]['value']);
|
||||||
} else {
|
} else {
|
||||||
// fallback
|
// fallback
|
||||||
$_value = 'NULL';
|
$_value = 'NULL';
|
||||||
@@ -490,7 +516,10 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
// create select part & addition FK part
|
// create select part & addition FK part
|
||||||
foreach ($this->table_array as $column => $data_array) {
|
foreach ($this->table_array as $column => $data_array) {
|
||||||
// check FK ...
|
// check FK ...
|
||||||
if (isset($this->table_array[$column]['fk']) && isset($this->table_array[$column]['value'])) {
|
if (
|
||||||
|
isset($this->table_array[$column]['fk']) &&
|
||||||
|
isset($this->table_array[$column]['value'])
|
||||||
|
) {
|
||||||
if (!empty($q_where)) {
|
if (!empty($q_where)) {
|
||||||
$q_where .= ' AND ';
|
$q_where .= ' AND ';
|
||||||
}
|
}
|
||||||
@@ -536,7 +565,6 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
}
|
}
|
||||||
// set primary key
|
// set primary key
|
||||||
if ($insert) {
|
if ($insert) {
|
||||||
// FIXME: this has to be fixes by fixing DB::IO clas
|
|
||||||
$insert_id = $this->dbGetInsertPK();
|
$insert_id = $this->dbGetInsertPK();
|
||||||
if (is_array($insert_id)) {
|
if (is_array($insert_id)) {
|
||||||
$insert_id = 0;
|
$insert_id = 0;
|
||||||
|
|||||||
@@ -263,15 +263,15 @@ use CoreLibs\Create\Uids;
|
|||||||
class IO
|
class IO
|
||||||
{
|
{
|
||||||
// 0: normal read, store in cache
|
// 0: normal read, store in cache
|
||||||
// 1: read cache, clean at the end
|
// 1: read new, keep at end, clean before new run
|
||||||
// 2: read new, clean at end
|
// 2: read new, clean at the end (temporary cache)
|
||||||
// 3: never cache
|
// 3: never cache
|
||||||
/** @var int */
|
/** @var int */
|
||||||
public const USE_CACHE = 0;
|
public const USE_CACHE = 0;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
public const CLEAR_CACHE = 1;
|
public const READ_NEW = 1;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
public const READ_NEW = 2;
|
public const CLEAR_CACHE = 2;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
public const NO_CACHE = 3;
|
public const NO_CACHE = 3;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
@@ -1384,7 +1384,7 @@ class IO
|
|||||||
// we only compare the first two
|
// we only compare the first two
|
||||||
preg_match(
|
preg_match(
|
||||||
"/^(\d{1,})\.(\d{1,})\.?(\d{1,})?/",
|
"/^(\d{1,})\.(\d{1,})\.?(\d{1,})?/",
|
||||||
$this->db_functions->__dbVersion(),
|
$this->dbVersion(),
|
||||||
$matches
|
$matches
|
||||||
);
|
);
|
||||||
$master = $matches[1];
|
$master = $matches[1];
|
||||||
@@ -1682,18 +1682,18 @@ class IO
|
|||||||
* data, or with reset flag set calls data from DB again
|
* data, or with reset flag set calls data from DB again
|
||||||
* NOTE on $cache param:
|
* NOTE on $cache param:
|
||||||
* - if set to 0, if same query run again, will read from cache
|
* - if set to 0, if same query run again, will read from cache
|
||||||
* - if set to 1, at the end of the query (last row returned),
|
* - if set to 1, the data will be read new and cached, cache reset a new run
|
||||||
* the stored array will be deleted ...
|
|
||||||
* - if set to 2, the data will be read new and cached
|
|
||||||
* (wheres 1 reads cache AND destroys at end of read)
|
* (wheres 1 reads cache AND destroys at end of read)
|
||||||
|
* - if set to 2, at the end of the query (last row returned),
|
||||||
|
* the stored array will be deleted ...
|
||||||
* - if set to 3, after EACH row, the data will be reset,
|
* - if set to 3, after EACH row, the data will be reset,
|
||||||
* no caching is done except for basic (count, etc)
|
* no caching is done except for basic (count, etc)
|
||||||
* @param string $query Query string
|
* @param string $query Query string
|
||||||
* @param int $cache reset status: default: USE_CACHE
|
* @param int $cache reset status: default: USE_CACHE
|
||||||
* USE_CACHE/0: normal read from cache on second run
|
* USE_CACHE/0: normal read from cache on second run
|
||||||
* CLEAR_CACHE/1: read cache, clean at the end
|
* READ_NEW/1: write to cache, clean before new run
|
||||||
* READ_NEW/2: read new, clean at end
|
* CLEAR_CACHE/2: write cache, clean after finished
|
||||||
* NO_CACHE/3: never cache [default]
|
* NO_CACHE/3: don't write cache
|
||||||
* @param bool $assoc_only True to only returned the named and not
|
* @param bool $assoc_only True to only returned the named and not
|
||||||
* index position ones
|
* index position ones
|
||||||
* @return array<mixed>|bool return array data or false on error/end
|
* @return array<mixed>|bool return array data or false on error/end
|
||||||
@@ -1714,17 +1714,44 @@ class IO
|
|||||||
// pre declare array
|
// pre declare array
|
||||||
if (!isset($this->cursor_ext[$query_hash])) {
|
if (!isset($this->cursor_ext[$query_hash])) {
|
||||||
$this->cursor_ext[$query_hash] = [
|
$this->cursor_ext[$query_hash] = [
|
||||||
|
// cursor, null: unset, 1: finished read/cache, 2: object/resource reading
|
||||||
'cursor' => null,
|
'cursor' => null,
|
||||||
|
// cached data
|
||||||
'data' => [],
|
'data' => [],
|
||||||
|
// field names as array
|
||||||
'field_names' => [],
|
'field_names' => [],
|
||||||
'firstcall' => 0,
|
// number of fields (field names)
|
||||||
'num_fields' => 0,
|
'num_fields' => 0,
|
||||||
|
// number of rows that will be maximum returned
|
||||||
'num_rows' => 0,
|
'num_rows' => 0,
|
||||||
'pos' => 0,
|
// how many rows have been read from db
|
||||||
'query' => '',
|
|
||||||
'read_rows' => 0,
|
'read_rows' => 0,
|
||||||
|
// current read pos (db/cache), 0 on last read (finished)
|
||||||
|
'pos' => 0,
|
||||||
|
// the query used in this call
|
||||||
|
'query' => '',
|
||||||
|
// cache flag from method call
|
||||||
|
'cache_flag' => $cache,
|
||||||
|
// flag if we only have assoc data
|
||||||
|
'assoc_flag' => $assoc_only,
|
||||||
|
// 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
|
||||||
|
'finished' => false,
|
||||||
|
// read from cache/db (pos == rows)
|
||||||
|
'read_finished' => false,
|
||||||
|
// read from db only (read == rows)
|
||||||
|
'db_read_finished' => false,
|
||||||
|
// for debug
|
||||||
|
'log_pos' => 1, // how many times called overall
|
||||||
|
'log' => [], // current run log
|
||||||
];
|
];
|
||||||
|
} else {
|
||||||
|
$this->cursor_ext[$query_hash]['log_pos'] ++;
|
||||||
}
|
}
|
||||||
|
// reset log for each read
|
||||||
|
$this->cursor_ext[$query_hash]['log'] = [];
|
||||||
// set the query
|
// set the query
|
||||||
$this->cursor_ext[$query_hash]['query'] = $query;
|
$this->cursor_ext[$query_hash]['query'] = $query;
|
||||||
// before doing ANYTHING check if query is "SELECT ..." everything else does not work
|
// before doing ANYTHING check if query is "SELECT ..." everything else does not work
|
||||||
@@ -1732,20 +1759,25 @@ class IO
|
|||||||
$this->__dbError(17, false, $this->cursor_ext[$query_hash]['query']);
|
$this->__dbError(17, false, $this->cursor_ext[$query_hash]['query']);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// set first call to false
|
||||||
|
$first_call = false;
|
||||||
// init return als false
|
// init return als false
|
||||||
$return = false;
|
$return = false;
|
||||||
// if it is a call with reset in it we reset the cursor,
|
// if it is a call with reset in it we reset the cursor,
|
||||||
// so we get an uncached return
|
// so we get an uncached return
|
||||||
// but only for the FIRST call (pos == 0)
|
// but only for the FIRST call (pos == 0)
|
||||||
if ($cache > self::USE_CACHE && !$this->cursor_ext[$query_hash]['pos']) {
|
if ($cache > self::USE_CACHE && !$this->cursor_ext[$query_hash]['pos']) {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'Reset cursor';
|
||||||
$this->cursor_ext[$query_hash]['cursor'] = null;
|
$this->cursor_ext[$query_hash]['cursor'] = null;
|
||||||
|
if ($cache == self::READ_NEW) {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'Cache reset';
|
||||||
|
$this->cursor_ext[$query_hash]['data'] = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// $this->debug('MENU', 'Reset: '.$reset.', Cursor: '
|
|
||||||
// .$this->cursor_ext[$query_hash]['cursor'].', Pos: '.$this->cursor_ext[$query_hash]['pos']
|
|
||||||
// .', Query: '.$query);
|
|
||||||
|
|
||||||
// if no cursor yet, execute
|
// if no cursor yet, execute
|
||||||
if (!$this->cursor_ext[$query_hash]['cursor']) {
|
if (!$this->cursor_ext[$query_hash]['cursor']) {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'No cursor';
|
||||||
// for DEBUG, print out each query executed
|
// for DEBUG, print out each query executed
|
||||||
if ($this->db_debug) {
|
if ($this->db_debug) {
|
||||||
$this->__dbDebug('db', $this->cursor_ext[$query_hash]['query'], 'dbReturn', 'Q');
|
$this->__dbDebug('db', $this->cursor_ext[$query_hash]['query'], 'dbReturn', 'Q');
|
||||||
@@ -1773,13 +1805,14 @@ class IO
|
|||||||
$this->__dbError(13, $this->cursor_ext[$query_hash]['cursor']);
|
$this->__dbError(13, $this->cursor_ext[$query_hash]['cursor']);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
$this->cursor_ext[$query_hash]['firstcall'] = 1;
|
$first_call = true;
|
||||||
}
|
}
|
||||||
} // only go if NO cursor exists
|
} // only go if NO cursor exists
|
||||||
|
|
||||||
// if cursor exists ...
|
// if cursor exists ...
|
||||||
if ($this->cursor_ext[$query_hash]['cursor']) {
|
if ($this->cursor_ext[$query_hash]['cursor']) {
|
||||||
if ($this->cursor_ext[$query_hash]['firstcall'] == 1) {
|
if ($first_call === true) {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'First call';
|
||||||
// count the rows returned (if select)
|
// count the rows returned (if select)
|
||||||
$this->cursor_ext[$query_hash]['num_rows'] =
|
$this->cursor_ext[$query_hash]['num_rows'] =
|
||||||
$this->db_functions->__dbNumRows($this->cursor_ext[$query_hash]['cursor']);
|
$this->db_functions->__dbNumRows($this->cursor_ext[$query_hash]['cursor']);
|
||||||
@@ -1799,35 +1832,51 @@ class IO
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->field_names = $this->cursor_ext[$query_hash]['field_names'];
|
$this->field_names = $this->cursor_ext[$query_hash]['field_names'];
|
||||||
// reset first call vars
|
// reset first call var
|
||||||
$this->cursor_ext[$query_hash]['firstcall'] = 0;
|
$first_call = false;
|
||||||
// reset the internal pos counter
|
// reset the internal pos counter
|
||||||
$this->cursor_ext[$query_hash]['pos'] = 0;
|
$this->cursor_ext[$query_hash]['pos'] = 0;
|
||||||
// reset the global (for cache) read counter
|
// reset the global (for cache) read counter
|
||||||
$this->cursor_ext[$query_hash]['read_rows'] = 0;
|
$this->cursor_ext[$query_hash]['read_rows'] = 0;
|
||||||
|
// reset read finished flag
|
||||||
|
$this->cursor_ext[$query_hash]['finished'] = false;
|
||||||
|
$this->cursor_ext[$query_hash]['read_finished'] = false;
|
||||||
|
$this->cursor_ext[$query_hash]['db_read_finished'] = false;
|
||||||
|
// set cursor ccached flag based on cache flag
|
||||||
|
if ($cache < self::NO_CACHE) {
|
||||||
|
$this->cursor_ext[$query_hash]['cached'] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// read data for further work ... but only if necessarry
|
// main database read if not all read and we have an active cursor
|
||||||
if (
|
if (
|
||||||
$this->cursor_ext[$query_hash]['read_rows'] ==
|
$this->cursor_ext[$query_hash]['read_rows'] !=
|
||||||
$this->cursor_ext[$query_hash]['num_rows']
|
$this->cursor_ext[$query_hash]['num_rows'] &&
|
||||||
|
!is_int($this->cursor_ext[$query_hash]['cursor'])
|
||||||
) {
|
) {
|
||||||
$return = false;
|
|
||||||
} else {
|
|
||||||
$return = $this->__dbConvertEncoding(
|
$return = $this->__dbConvertEncoding(
|
||||||
$this->db_functions->__dbFetchArray(
|
$this->db_functions->__dbFetchArray(
|
||||||
$this->cursor_ext[$query_hash]['cursor'],
|
$this->cursor_ext[$query_hash]['cursor'],
|
||||||
$this->db_functions->__dbResultType($assoc_only)
|
$this->db_functions->__dbResultType($assoc_only)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'DB Reading data: '
|
||||||
|
. (is_bool($return) ? 'EOF' : 'DATA');
|
||||||
// if returned is NOT an array, abort to false
|
// if returned is NOT an array, abort to false
|
||||||
if (!is_array($return)) {
|
if (!is_array($return)) {
|
||||||
$return = false;
|
$return = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check if cached call or reset call ...
|
// read from cache, or do partial cache set and caching
|
||||||
if (!$return && $cache == self::USE_CACHE) {
|
if (!$return && $cache == self::USE_CACHE) {
|
||||||
// check if end of output ...
|
// check if end of output ...
|
||||||
if ($this->cursor_ext[$query_hash]['pos'] >= $this->cursor_ext[$query_hash]['num_rows']) {
|
if (
|
||||||
|
$this->cursor_ext[$query_hash]['pos'] >=
|
||||||
|
$this->cursor_ext[$query_hash]['num_rows']
|
||||||
|
) {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'USE CACHE, end';
|
||||||
|
// finish read
|
||||||
|
$this->cursor_ext[$query_hash]['finished'] = true;
|
||||||
|
// reset pos for next read
|
||||||
$this->cursor_ext[$query_hash]['pos'] = 0;
|
$this->cursor_ext[$query_hash]['pos'] = 0;
|
||||||
// if not reset given, set the cursor to true, so in a cached
|
// if not reset given, set the cursor to true, so in a cached
|
||||||
// call on a different page we don't get problems from
|
// call on a different page we don't get problems from
|
||||||
@@ -1835,36 +1884,55 @@ class IO
|
|||||||
$this->cursor_ext[$query_hash]['cursor'] = 1;
|
$this->cursor_ext[$query_hash]['cursor'] = 1;
|
||||||
$return = false;
|
$return = false;
|
||||||
} else {
|
} else {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'USE CACHE, read data';
|
||||||
|
$this->cursor_ext[$query_hash]['read_finished'] = false;
|
||||||
|
$this->cursor_ext[$query_hash]['finished'] = false;
|
||||||
// cached data read
|
// cached data read
|
||||||
$return = $this->__dbReturnCacheRead($query_hash, $assoc_only);
|
$return = $this->__dbReturnCacheRead($query_hash, $assoc_only);
|
||||||
|
if (
|
||||||
|
$this->cursor_ext[$query_hash]['pos'] ==
|
||||||
|
$this->cursor_ext[$query_hash]['num_rows']
|
||||||
|
) {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'USE CACHE, all cache rows read';
|
||||||
|
$this->cursor_ext[$query_hash]['read_finished'] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// return row, if last && reset, then unset the hole hash array
|
// return row, if last && reset, then unset the whole hash array
|
||||||
if (
|
if (!$return && $this->cursor_ext[$query_hash]['pos']) {
|
||||||
!$return &&
|
|
||||||
($cache == self::CLEAR_CACHE || $cache == self::NO_CACHE) &&
|
|
||||||
$this->cursor_ext[$query_hash]['pos']
|
|
||||||
) {
|
|
||||||
// unset data block only
|
|
||||||
$this->cursor_ext[$query_hash]['data'] = [];
|
|
||||||
$this->cursor_ext[$query_hash]['pos'] = 0;
|
|
||||||
} elseif (
|
|
||||||
!$return && $cache == self::READ_NEW &&
|
|
||||||
$this->cursor_ext[$query_hash]['pos']
|
|
||||||
) {
|
|
||||||
// at end of read reset pos & set cursor to 1
|
|
||||||
// (so it does not get lost in session transfer)
|
|
||||||
$this->cursor_ext[$query_hash]['pos'] = 0;
|
$this->cursor_ext[$query_hash]['pos'] = 0;
|
||||||
$this->cursor_ext[$query_hash]['cursor'] = 1;
|
$this->cursor_ext[$query_hash]['cursor'] = 1;
|
||||||
$return = false;
|
$this->cursor_ext[$query_hash]['finished'] = true;
|
||||||
|
// for clear cache, clear cache, else only write log info
|
||||||
|
if ($cache == self::CLEAR_CACHE) {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'CLEAR CACHE, end';
|
||||||
|
// unset data block only
|
||||||
|
$this->cursor_ext[$query_hash]['data'] = [];
|
||||||
|
$this->cursor_ext[$query_hash]['cached'] = false;
|
||||||
|
} elseif ($cache == self::READ_NEW) {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'READ NEW, end';
|
||||||
|
} elseif ($cache == self::NO_CACHE) {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'NO CACHE, end';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// if something found, write data into hash array
|
// if something found, write data into hash array
|
||||||
if ($return) {
|
if ($return) {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'Return Data';
|
||||||
// internal position counter
|
// internal position counter
|
||||||
$this->cursor_ext[$query_hash]['pos'] ++;
|
$this->cursor_ext[$query_hash]['pos'] ++;
|
||||||
$this->cursor_ext[$query_hash]['read_rows'] ++;
|
$this->cursor_ext[$query_hash]['read_rows'] ++;
|
||||||
|
// read is finished
|
||||||
|
if (
|
||||||
|
$this->cursor_ext[$query_hash]['read_rows'] ==
|
||||||
|
$this->cursor_ext[$query_hash]['num_rows']
|
||||||
|
) {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'Return data all db rows read';
|
||||||
|
$this->cursor_ext[$query_hash]['db_read_finished'] = true;
|
||||||
|
$this->cursor_ext[$query_hash]['read_finished'] = true;
|
||||||
|
}
|
||||||
// if reset is < NO_CACHE level caching is done, else no
|
// if reset is < NO_CACHE level caching is done, else no
|
||||||
if ($cache < self::NO_CACHE) {
|
if ($cache < self::NO_CACHE) {
|
||||||
|
$this->cursor_ext[$query_hash]['log'][] = 'Cache Data';
|
||||||
// why was this here?
|
// why was this here?
|
||||||
// $temp = [];
|
// $temp = [];
|
||||||
// foreach ($return as $field_name => $data) {
|
// foreach ($return as $field_name => $data) {
|
||||||
|
|||||||
@@ -59,15 +59,9 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
/** @var object|resource|bool */ // replace object with PgSql\Connection
|
/** @var object|resource|bool */ // replace object with PgSql\Connection
|
||||||
private $dbh;
|
private $dbh;
|
||||||
|
|
||||||
/**
|
|
||||||
* class constructor, empty does nothing
|
|
||||||
*/
|
|
||||||
// public function __construct()
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* queries last error query and returns true or false if error was set
|
* queries last error query and returns true or false if error was set
|
||||||
|
*
|
||||||
* @return bool true/false if last error is set
|
* @return bool true/false if last error is set
|
||||||
*/
|
*/
|
||||||
public function __dbLastErrorQuery(): bool
|
public function __dbLastErrorQuery(): bool
|
||||||
@@ -81,6 +75,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_query, catches error and stores it in class var
|
* wrapper for pg_query, catches error and stores it in class var
|
||||||
|
*
|
||||||
* @param string $query Query string
|
* @param string $query Query string
|
||||||
* @return object|resource|bool query result (PgSql\Result)
|
* @return object|resource|bool query result (PgSql\Result)
|
||||||
*/
|
*/
|
||||||
@@ -102,6 +97,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
* Proposed
|
* Proposed
|
||||||
* wrapperf or pg_query_params for queries in the style of
|
* wrapperf or pg_query_params for queries in the style of
|
||||||
* SELECT foo FROM bar WHERE foobar = $1
|
* SELECT foo FROM bar WHERE foobar = $1
|
||||||
|
*
|
||||||
* @param string $query Query string with placeholders $1, ..
|
* @param string $query Query string with placeholders $1, ..
|
||||||
* @param array<mixed> $params Matching parameters for each placerhold
|
* @param array<mixed> $params Matching parameters for each placerhold
|
||||||
* @return object|resource|bool Query result (PgSql\Result)
|
* @return object|resource|bool Query result (PgSql\Result)
|
||||||
@@ -124,6 +120,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* sends an async query to the server
|
* sends an async query to the server
|
||||||
|
*
|
||||||
* @param string $query query string
|
* @param string $query query string
|
||||||
* @return bool true/false if query was sent successful
|
* @return bool true/false if query was sent successful
|
||||||
*/
|
*/
|
||||||
@@ -138,6 +135,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_get_result
|
* wrapper for pg_get_result
|
||||||
|
*
|
||||||
* @return object|resource|bool resource handler or false for error (PgSql\Result)
|
* @return object|resource|bool resource handler or false for error (PgSql\Result)
|
||||||
*/
|
*/
|
||||||
public function __dbGetResult()
|
public function __dbGetResult()
|
||||||
@@ -158,6 +156,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_close
|
* wrapper for pg_close
|
||||||
|
*
|
||||||
* @return void has no return
|
* @return void has no return
|
||||||
*/
|
*/
|
||||||
public function __dbClose(): void
|
public function __dbClose(): void
|
||||||
@@ -173,9 +172,11 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_prepare
|
* wrapper for pg_prepare
|
||||||
|
*
|
||||||
* @param string $name statement name
|
* @param string $name statement name
|
||||||
* @param string $query query string
|
* @param string $query query string
|
||||||
* @return object|resource|bool prepare statement handler or false for error (PgSql\Result)
|
* @return object|resource|bool prepare statement handler or
|
||||||
|
* false for error (PgSql\Result)
|
||||||
*/
|
*/
|
||||||
public function __dbPrepare(string $name, string $query)
|
public function __dbPrepare(string $name, string $query)
|
||||||
{
|
{
|
||||||
@@ -191,6 +192,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_execute for running a prepared statement
|
* wrapper for pg_execute for running a prepared statement
|
||||||
|
*
|
||||||
* @param string $name statement name
|
* @param string $name statement name
|
||||||
* @param array<mixed> $data data array
|
* @param array<mixed> $data data array
|
||||||
* @return object|resource|bool returns status or false for error (PgSql\Result)
|
* @return object|resource|bool returns status or false for error (PgSql\Result)
|
||||||
@@ -209,6 +211,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_num_rows
|
* wrapper for pg_num_rows
|
||||||
|
*
|
||||||
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
||||||
* @return int number of rows, -1 on error
|
* @return int number of rows, -1 on error
|
||||||
*/
|
*/
|
||||||
@@ -222,6 +225,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_num_fields
|
* wrapper for pg_num_fields
|
||||||
|
*
|
||||||
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
||||||
* @return int number for fields in result, -1 on error
|
* @return int number for fields in result, -1 on error
|
||||||
*/
|
*/
|
||||||
@@ -235,6 +239,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_field_name
|
* wrapper for pg_field_name
|
||||||
|
*
|
||||||
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
||||||
* @param int $i field position
|
* @param int $i field position
|
||||||
* @return string|bool name or false on error
|
* @return string|bool name or false on error
|
||||||
@@ -250,6 +255,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
/**
|
/**
|
||||||
* wrapper for pg_fetch_array
|
* wrapper for pg_fetch_array
|
||||||
* if through/true false, use __dbResultType(true)
|
* if through/true false, use __dbResultType(true)
|
||||||
|
*
|
||||||
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
||||||
* @param int $result_type result type as int number
|
* @param int $result_type result type as int number
|
||||||
* @return array<mixed>|bool array result data or false on end/error
|
* @return array<mixed>|bool array result data or false on end/error
|
||||||
@@ -265,6 +271,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* simple match up between assoc true/false
|
* simple match up between assoc true/false
|
||||||
|
*
|
||||||
* @param bool $assoc_type true (default) for PGSQL_ASSOC, false for PGSQL_BOTH
|
* @param bool $assoc_type true (default) for PGSQL_ASSOC, false for PGSQL_BOTH
|
||||||
* @return int valid result type for fetch array
|
* @return int valid result type for fetch array
|
||||||
*/
|
*/
|
||||||
@@ -279,6 +286,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_fetch_all
|
* wrapper for pg_fetch_all
|
||||||
|
*
|
||||||
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
||||||
* @return array<mixed>|bool data array or false for end/error
|
* @return array<mixed>|bool data array or false for end/error
|
||||||
*/
|
*/
|
||||||
@@ -292,6 +300,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_affected_rows
|
* wrapper for pg_affected_rows
|
||||||
|
*
|
||||||
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
||||||
* @return int affected rows, 0 for none, -1 for error
|
* @return int affected rows, 0 for none, -1 for error
|
||||||
*/
|
*/
|
||||||
@@ -306,7 +315,9 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
/**
|
/**
|
||||||
* reads the last inserted primary key for the query
|
* reads the last inserted primary key for the query
|
||||||
* if there is no pk_name tries to auto built it from the table name
|
* if there is no pk_name tries to auto built it from the table name
|
||||||
* this only works if db schema is after "no plural names. and pk name is table name + _id
|
* this only works if db schema is after no plural names
|
||||||
|
* and pk name is table name + _id
|
||||||
|
*
|
||||||
* detects schema prefix in table name
|
* detects schema prefix in table name
|
||||||
* @param string $query query string
|
* @param string $query query string
|
||||||
* @param string|null $pk_name primary key name, if '' then auto detect
|
* @param string|null $pk_name primary key name, if '' then auto detect
|
||||||
@@ -355,6 +366,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* queries database for the primary key name to this table in the selected schema
|
* queries database for the primary key name to this table in the selected schema
|
||||||
|
*
|
||||||
* @param string $table table name
|
* @param string $table table name
|
||||||
* @param string $schema optional schema name, '' for default
|
* @param string $schema optional schema name, '' for default
|
||||||
* @return string|bool primary key name or false if not found
|
* @return string|bool primary key name or false if not found
|
||||||
@@ -407,6 +419,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
|
* wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
|
||||||
|
*
|
||||||
* @param string $db_host host name
|
* @param string $db_host host name
|
||||||
* @param string $db_user user name
|
* @param string $db_user user name
|
||||||
* @param string $db_pass password
|
* @param string $db_pass password
|
||||||
@@ -456,6 +469,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
/**
|
/**
|
||||||
* reads the last error for this cursor and returns
|
* reads the last error for this cursor and returns
|
||||||
* html formatted string with error name
|
* html formatted string with error name
|
||||||
|
*
|
||||||
* @param bool|object|resource $cursor cursor PgSql\Result (former resource)
|
* @param bool|object|resource $cursor cursor PgSql\Result (former resource)
|
||||||
* or null
|
* or null
|
||||||
* @return string error string
|
* @return string error string
|
||||||
@@ -481,6 +495,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_meta_data
|
* wrapper for pg_meta_data
|
||||||
|
*
|
||||||
* @param string $table table name
|
* @param string $table table name
|
||||||
* @param bool $extended show extended info (default true)
|
* @param bool $extended show extended info (default true)
|
||||||
* @return array<mixed>|bool array data for the table info or false on error
|
* @return array<mixed>|bool array data for the table info or false on error
|
||||||
@@ -496,6 +511,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_escape_string
|
* wrapper for pg_escape_string
|
||||||
|
*
|
||||||
* @param string|int|float|bool $string any string/int/float/bool
|
* @param string|int|float|bool $string any string/int/float/bool
|
||||||
* @return string excaped string
|
* @return string excaped string
|
||||||
*/
|
*/
|
||||||
@@ -511,6 +527,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
* wrapper for pg_escape_literal
|
* wrapper for pg_escape_literal
|
||||||
* difference to escape string is that this one adds quotes ('') around
|
* difference to escape string is that this one adds quotes ('') around
|
||||||
* the string too
|
* the string too
|
||||||
|
*
|
||||||
* @param string|int|float|bool $string any string/int/float/bool
|
* @param string|int|float|bool $string any string/int/float/bool
|
||||||
* @return string excaped string including quites
|
* @return string excaped string including quites
|
||||||
*/
|
*/
|
||||||
@@ -526,6 +543,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
/**
|
/**
|
||||||
* wrapper for pg_escape_identifier
|
* wrapper for pg_escape_identifier
|
||||||
* Only used for table names, column names
|
* Only used for table names, column names
|
||||||
|
*
|
||||||
* @param string $string any string
|
* @param string $string any string
|
||||||
* @return string escaped string
|
* @return string escaped string
|
||||||
*/
|
*/
|
||||||
@@ -540,6 +558,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_escape_byte
|
* wrapper for pg_escape_byte
|
||||||
|
*
|
||||||
* @param string $bytea bytea data stream
|
* @param string $bytea bytea data stream
|
||||||
* @return string escaped bytea string
|
* @return string escaped bytea string
|
||||||
*/
|
*/
|
||||||
@@ -553,6 +572,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for pg_connection_busy
|
* wrapper for pg_connection_busy
|
||||||
|
*
|
||||||
* @return bool True if connection is busy, False if not or no db connection at all
|
* @return bool True if connection is busy, False if not or no db connection at all
|
||||||
*/
|
*/
|
||||||
public function __dbConnectionBusy(): bool
|
public function __dbConnectionBusy(): bool
|
||||||
@@ -565,6 +585,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Experimental wrapper with scoket timetout
|
* Experimental wrapper with scoket timetout
|
||||||
|
*
|
||||||
* @param integer $timeout_seconds Wait how many seconds on timeout
|
* @param integer $timeout_seconds Wait how many seconds on timeout
|
||||||
* @return boolean True if connection is busy, or false on
|
* @return boolean True if connection is busy, or false on
|
||||||
* not busy or no db connection at all
|
* not busy or no db connection at all
|
||||||
@@ -593,6 +614,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
* if not in array return empty string
|
* if not in array return empty string
|
||||||
* On default 'version' will be stripped of any space attached info
|
* On default 'version' will be stripped of any space attached info
|
||||||
* eg 13.5 (other info) will return only 13.5
|
* eg 13.5 (other info) will return only 13.5
|
||||||
|
*
|
||||||
* @param string $parameter Parameter string to extract from array
|
* @param string $parameter Parameter string to extract from array
|
||||||
* @param boolean $strip If parameter is server strip out on default
|
* @param boolean $strip If parameter is server strip out on default
|
||||||
* Set to false to get original string AS is
|
* Set to false to get original string AS is
|
||||||
@@ -617,6 +639,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all parameters that are possible from the db_version
|
* Returns all parameters that are possible from the db_version
|
||||||
|
*
|
||||||
* @return array<mixed> Parameter key names from pg_version
|
* @return array<mixed> Parameter key names from pg_version
|
||||||
*/
|
*/
|
||||||
public function __dbVersionInfoParameterList(): array
|
public function __dbVersionInfoParameterList(): array
|
||||||
@@ -631,6 +654,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
* wrapper for pg_version
|
* wrapper for pg_version
|
||||||
* Note: this only returns server version
|
* Note: this only returns server version
|
||||||
* not connection version OR client version
|
* not connection version OR client version
|
||||||
|
*
|
||||||
* @return string version string
|
* @return string version string
|
||||||
*/
|
*/
|
||||||
public function __dbVersion(): string
|
public function __dbVersion(): string
|
||||||
@@ -649,6 +673,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
* Old version is 9.5.6 where 9.5 is the major version
|
* Old version is 9.5.6 where 9.5 is the major version
|
||||||
* Newer Postgresql (10 on) have only one major version so eg 13.5
|
* Newer Postgresql (10 on) have only one major version so eg 13.5
|
||||||
* is returned as 130005
|
* is returned as 130005
|
||||||
|
*
|
||||||
* @return integer Server version
|
* @return integer Server version
|
||||||
*/
|
*/
|
||||||
public function __dbVersionNumeric(): int
|
public function __dbVersionNumeric(): int
|
||||||
@@ -662,6 +687,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
* This is a fallback for old PostgreSQL versions
|
* This is a fallback for old PostgreSQL versions
|
||||||
* postgresql array to php array
|
* postgresql array to php array
|
||||||
* https://stackoverflow.com/a/27964420
|
* https://stackoverflow.com/a/27964420
|
||||||
|
*
|
||||||
* @param string $array_text Array text from PostgreSQL
|
* @param string $array_text Array text from PostgreSQL
|
||||||
* @param int $start Start string position
|
* @param int $start Start string position
|
||||||
* @param int|null $end End string position from recursive call
|
* @param int|null $end End string position from recursive call
|
||||||
@@ -721,6 +747,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
* Returns any server setting
|
* Returns any server setting
|
||||||
* if no connection or empty parameter or other error returns false
|
* if no connection or empty parameter or other error returns false
|
||||||
* else returns a string
|
* else returns a string
|
||||||
|
*
|
||||||
* @param string $parameter Parameter to query
|
* @param string $parameter Parameter to query
|
||||||
* @return string|bool Settings value as string
|
* @return string|bool Settings value as string
|
||||||
*/
|
*/
|
||||||
@@ -738,6 +765,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
/**
|
/**
|
||||||
* wrapper for any SHOW data blocks
|
* wrapper for any SHOW data blocks
|
||||||
* eg search_path or client_encoding
|
* eg search_path or client_encoding
|
||||||
|
*
|
||||||
* @param string $show_string Part to show, if invalid will return empty string
|
* @param string $show_string Part to show, if invalid will return empty string
|
||||||
* @return string Found part as is
|
* @return string Found part as is
|
||||||
*/
|
*/
|
||||||
@@ -758,6 +786,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
/**
|
/**
|
||||||
* Sets a new database schema/search_path
|
* Sets a new database schema/search_path
|
||||||
* Checks if schema exits and if not aborts with error code 2
|
* Checks if schema exits and if not aborts with error code 2
|
||||||
|
*
|
||||||
* @param string $db_schema Schema to set
|
* @param string $db_schema Schema to set
|
||||||
* @return int Returns 0 if no error
|
* @return int Returns 0 if no error
|
||||||
* 1 for check query failed
|
* 1 for check query failed
|
||||||
@@ -788,6 +817,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns current set schema/search_path
|
* Returns current set schema/search_path
|
||||||
|
*
|
||||||
* @return string Search Path as currently set in DB
|
* @return string Search Path as currently set in DB
|
||||||
*/
|
*/
|
||||||
public function __dbGetSchema(): string
|
public function __dbGetSchema(): string
|
||||||
@@ -798,6 +828,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
/**
|
/**
|
||||||
* set the client encoding
|
* set the client encoding
|
||||||
* Returns 0 on set ok, or 3 if the client encoding could not be set
|
* Returns 0 on set ok, or 3 if the client encoding could not be set
|
||||||
|
*
|
||||||
* @param string $db_encoding
|
* @param string $db_encoding
|
||||||
* @return int Returns 0 for no error
|
* @return int Returns 0 for no error
|
||||||
* [not used] 1 for check query failed
|
* [not used] 1 for check query failed
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class FileWriter
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
private static $debug_folder;
|
private static $debug_folder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a debug log folder, if not set BASE+LOG folders are set
|
* Set a debug log folder, if not set BASE+LOG folders are set
|
||||||
* if they are defined
|
* if they are defined
|
||||||
* This folder name must exist and must be writeable
|
* This folder name must exist and must be writeable
|
||||||
@@ -60,6 +60,7 @@ class FileWriter
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* writes a string to a file immediatly, for fast debug output
|
* writes a string to a file immediatly, for fast debug output
|
||||||
|
*
|
||||||
* @param string $string string to write to the file
|
* @param string $string string to write to the file
|
||||||
* @param boolean $enter default true, if set adds a linebreak \n at the end
|
* @param boolean $enter default true, if set adds a linebreak \n at the end
|
||||||
* @return bool True for log written, false for not wirrten
|
* @return bool True for log written, false for not wirrten
|
||||||
|
|||||||
@@ -310,6 +310,7 @@ class Logging
|
|||||||
* Needs debug/echo/print ad target for which of the debug flag groups we check
|
* Needs debug/echo/print ad target for which of the debug flag groups we check
|
||||||
* also needs level string to check in the per level output flag check.
|
* also needs level string to check in the per level output flag check.
|
||||||
* In case we have invalid target it will return false
|
* In case we have invalid target it will return false
|
||||||
|
*
|
||||||
* @param string $target target group to check debug/echo/print
|
* @param string $target target group to check debug/echo/print
|
||||||
* @param string $level level to check in detailed level flag
|
* @param string $level level to check in detailed level flag
|
||||||
* @return bool true on access allowed or false on no access
|
* @return bool true on access allowed or false on no access
|
||||||
@@ -332,6 +333,7 @@ class Logging
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* writes error msg data to file for current level
|
* writes error msg data to file for current level
|
||||||
|
*
|
||||||
* @param string $level the level to write
|
* @param string $level the level to write
|
||||||
* @param string $error_string error string to write
|
* @param string $error_string error string to write
|
||||||
* @return bool True if message written, FAlse if not
|
* @return bool True if message written, FAlse if not
|
||||||
@@ -412,6 +414,7 @@ class Logging
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporary method to read all class variables for testing purpose
|
* Temporary method to read all class variables for testing purpose
|
||||||
|
*
|
||||||
* @param string $name what variable to return
|
* @param string $name what variable to return
|
||||||
* @return mixed can be anything, bool, string, int, array
|
* @return mixed can be anything, bool, string, int, array
|
||||||
*/
|
*/
|
||||||
@@ -425,6 +428,7 @@ class Logging
|
|||||||
* sets the internal log file prefix id
|
* sets the internal log file prefix id
|
||||||
* string must be a alphanumeric string
|
* string must be a alphanumeric string
|
||||||
* if non valid string is given it returns the previous set one only
|
* if non valid string is given it returns the previous set one only
|
||||||
|
*
|
||||||
* @param string $string log file id string value
|
* @param string $string log file id string value
|
||||||
* @return string returns the set log file id string
|
* @return string returns the set log file id string
|
||||||
* @deprecated Use $log->setLogId()
|
* @deprecated Use $log->setLogId()
|
||||||
@@ -438,6 +442,7 @@ class Logging
|
|||||||
* sets the internal log file prefix id
|
* sets the internal log file prefix id
|
||||||
* string must be a alphanumeric string
|
* string must be a alphanumeric string
|
||||||
* if non valid string is given it returns the previous set one only
|
* if non valid string is given it returns the previous set one only
|
||||||
|
*
|
||||||
* @param string $string log file id string value
|
* @param string $string log file id string value
|
||||||
* @return string returns the set log file id string
|
* @return string returns the set log file id string
|
||||||
*/
|
*/
|
||||||
@@ -460,6 +465,7 @@ class Logging
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* old name for setLogLevel
|
* old name for setLogLevel
|
||||||
|
*
|
||||||
* @param string $type debug, echo, print
|
* @param string $type debug, echo, print
|
||||||
* @param string $flag on/off
|
* @param string $flag on/off
|
||||||
* array $array of levels to turn on/off debug
|
* array $array of levels to turn on/off debug
|
||||||
@@ -475,6 +481,7 @@ class Logging
|
|||||||
/**
|
/**
|
||||||
* set log level settings for All types
|
* set log level settings for All types
|
||||||
* if invalid type, skip
|
* if invalid type, skip
|
||||||
|
*
|
||||||
* @param string $type Type to get: debug, echo, print
|
* @param string $type Type to get: debug, echo, print
|
||||||
* @param bool $set True or False
|
* @param bool $set True or False
|
||||||
* @return bool Return false if type invalid
|
* @return bool Return false if type invalid
|
||||||
@@ -491,6 +498,7 @@ class Logging
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get the current log level setting for All level blocks
|
* get the current log level setting for All level blocks
|
||||||
|
*
|
||||||
* @param string $type Type to get: debug, echo, print
|
* @param string $type Type to get: debug, echo, print
|
||||||
* @return bool False on failure, or the boolean flag from the all var
|
* @return bool False on failure, or the boolean flag from the all var
|
||||||
*/
|
*/
|
||||||
@@ -506,6 +514,7 @@ class Logging
|
|||||||
/**
|
/**
|
||||||
* passes list of level names, to turn on debug
|
* passes list of level names, to turn on debug
|
||||||
* eg $foo->debugFor('print', 'on', ['LOG', 'DEBUG', 'INFO']);
|
* eg $foo->debugFor('print', 'on', ['LOG', 'DEBUG', 'INFO']);
|
||||||
|
*
|
||||||
* @param string $type debug, echo, print
|
* @param string $type debug, echo, print
|
||||||
* @param string $flag on/off
|
* @param string $flag on/off
|
||||||
* @param array<mixed> $debug_on Array of levels to turn on/off debug
|
* @param array<mixed> $debug_on Array of levels to turn on/off debug
|
||||||
@@ -541,6 +550,7 @@ class Logging
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* return the log level for the array type normal and not (disable)
|
* return the log level for the array type normal and not (disable)
|
||||||
|
*
|
||||||
* @param string $type debug, echo, print
|
* @param string $type debug, echo, print
|
||||||
* @param string $flag on/off
|
* @param string $flag on/off
|
||||||
* @param string|null $level if not null then check if this array entry is set
|
* @param string|null $level if not null then check if this array entry is set
|
||||||
@@ -572,6 +582,7 @@ class Logging
|
|||||||
* - class: split by class
|
* - class: split by class
|
||||||
* - page: split per page called
|
* - page: split per page called
|
||||||
* - run: for each run
|
* - run: for each run
|
||||||
|
*
|
||||||
* @param string $type Type to get: level, class, page, run
|
* @param string $type Type to get: level, class, page, run
|
||||||
* @param bool $set True or False
|
* @param bool $set True or False
|
||||||
* @return bool Return false if type invalid
|
* @return bool Return false if type invalid
|
||||||
@@ -587,6 +598,7 @@ class Logging
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* return current set log per flag in bool
|
* return current set log per flag in bool
|
||||||
|
*
|
||||||
* @param string $type Type to get: level, class, page, run
|
* @param string $type Type to get: level, class, page, run
|
||||||
* @return bool True of false for turned on or off
|
* @return bool True of false for turned on or off
|
||||||
*/
|
*/
|
||||||
@@ -601,6 +613,7 @@ class Logging
|
|||||||
/**
|
/**
|
||||||
* Set or get the log file date extension flag
|
* Set or get the log file date extension flag
|
||||||
* if null or empty parameter gets current flag
|
* if null or empty parameter gets current flag
|
||||||
|
*
|
||||||
* @param boolean|null $set Set the date suffix for log files
|
* @param boolean|null $set Set the date suffix for log files
|
||||||
* If set to null return current set
|
* If set to null return current set
|
||||||
* @return boolean Current set flag
|
* @return boolean Current set flag
|
||||||
@@ -615,6 +628,7 @@ class Logging
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return current set log file name
|
* Return current set log file name
|
||||||
|
*
|
||||||
* @return string Filename set set after the last time debug was called
|
* @return string Filename set set after the last time debug was called
|
||||||
*/
|
*/
|
||||||
public function getLogFileName(): string
|
public function getLogFileName(): string
|
||||||
@@ -628,6 +642,7 @@ class Logging
|
|||||||
* It uses some special code sets so we can convert that to pre flags
|
* It uses some special code sets so we can convert that to pre flags
|
||||||
* for echo output {##HTMLPRE##} ... {##/HTMLPRE##}
|
* for echo output {##HTMLPRE##} ... {##/HTMLPRE##}
|
||||||
* Do not use this without using it in a string in debug function
|
* Do not use this without using it in a string in debug function
|
||||||
|
*
|
||||||
* @param array<mixed> $a Array to format
|
* @param array<mixed> $a Array to format
|
||||||
* @return string print_r formated
|
* @return string print_r formated
|
||||||
*/
|
*/
|
||||||
@@ -636,14 +651,32 @@ class Logging
|
|||||||
return '##HTMLPRE##' . print_r($a, true) . '##/HTMLPRE##';
|
return '##HTMLPRE##' . print_r($a, true) . '##/HTMLPRE##';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert bool value to string value
|
||||||
|
*
|
||||||
|
* @param bool $bool Bool value to be transformed
|
||||||
|
* @param string $true Override default string 'true'
|
||||||
|
* @param string $false Override default string 'false'
|
||||||
|
* @return string $true or $false string for true/false bool
|
||||||
|
*/
|
||||||
|
public function prBl(
|
||||||
|
bool $bool,
|
||||||
|
string $true = 'true',
|
||||||
|
string $false = 'false'
|
||||||
|
): string {
|
||||||
|
return $bool ? $true : $false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* write debug data to error_msg array
|
* write debug data to error_msg array
|
||||||
|
*
|
||||||
* @param string $level id for error message, groups messages together
|
* @param string $level id for error message, groups messages together
|
||||||
* @param string $string the actual error message
|
* @param string $string the actual error message
|
||||||
* @param bool $strip default on false, if set to true,
|
* @param bool $strip default on false, if set to true,
|
||||||
* all html tags will be stripped and <br> changed to \n
|
* all html tags will be stripped and <br> changed to \n
|
||||||
* this is only used for debug output
|
* this is only used for debug output
|
||||||
* @param string $prefix Attach some block before $string. Will not be stripped even
|
* @param string $prefix Attach some block before $string.
|
||||||
|
* Will not be stripped even
|
||||||
* when strip is true
|
* when strip is true
|
||||||
* if strip is false, recommended to add that to $string
|
* if strip is false, recommended to add that to $string
|
||||||
* @return bool True if logged, false if not logged
|
* @return bool True if logged, false if not logged
|
||||||
@@ -729,6 +762,7 @@ class Logging
|
|||||||
/**
|
/**
|
||||||
* for ECHO ON only
|
* for ECHO ON only
|
||||||
* returns error data as string so it can be echoed out
|
* returns error data as string so it can be echoed out
|
||||||
|
*
|
||||||
* @param string $header_prefix prefix string for header
|
* @param string $header_prefix prefix string for header
|
||||||
* @return string error msg for all levels
|
* @return string error msg for all levels
|
||||||
*/
|
*/
|
||||||
@@ -780,6 +814,7 @@ class Logging
|
|||||||
* unsests the error message array
|
* unsests the error message array
|
||||||
* can be used if writing is primary to file
|
* can be used if writing is primary to file
|
||||||
* if no level given resets all
|
* if no level given resets all
|
||||||
|
*
|
||||||
* @param string $level optional level
|
* @param string $level optional level
|
||||||
* @return void has no return
|
* @return void has no return
|
||||||
*/
|
*/
|
||||||
@@ -795,6 +830,7 @@ class Logging
|
|||||||
/**
|
/**
|
||||||
* for ECHO ON only
|
* for ECHO ON only
|
||||||
* Get current error message array
|
* Get current error message array
|
||||||
|
*
|
||||||
* @return array<mixed> error messages collected
|
* @return array<mixed> error messages collected
|
||||||
*/
|
*/
|
||||||
public function getErrorMsg(): array
|
public function getErrorMsg(): array
|
||||||
@@ -806,6 +842,7 @@ class Logging
|
|||||||
* for ECHO ON only
|
* for ECHO ON only
|
||||||
* merges the given error array with the one from this class
|
* merges the given error array with the one from this class
|
||||||
* only merges visible ones
|
* only merges visible ones
|
||||||
|
*
|
||||||
* @param array<mixed> $error_msg error array
|
* @param array<mixed> $error_msg error array
|
||||||
* @return void has no return
|
* @return void has no return
|
||||||
*/
|
*/
|
||||||
|
|||||||
129
www/lib/CoreLibs/Debug/MemoryUsage.php
Normal file
129
www/lib/CoreLibs/Debug/MemoryUsage.php
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* dump memory usage
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Debug;
|
||||||
|
|
||||||
|
use CoreLibs\Convert\Byte;
|
||||||
|
|
||||||
|
class MemoryUsage
|
||||||
|
{
|
||||||
|
/** @var int */
|
||||||
|
private static $start_memory = 0;
|
||||||
|
/** @var int */
|
||||||
|
private static $set_memory = 0;
|
||||||
|
/** @var int */
|
||||||
|
private static $previous_memory = 0;
|
||||||
|
/** @var bool */
|
||||||
|
private static $debug_memory = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set memory flag, or return set memory flag
|
||||||
|
*
|
||||||
|
* @param bool|null $set_debug
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function debugMemoryFlag(?bool $set_debug = null): bool
|
||||||
|
{
|
||||||
|
if ($set_debug === null) {
|
||||||
|
return self::$debug_memory;
|
||||||
|
}
|
||||||
|
self::$debug_memory = $set_debug;
|
||||||
|
return self::$debug_memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset all memory variables to 0
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function resetMemory(): void
|
||||||
|
{
|
||||||
|
self::$start_memory = 0;
|
||||||
|
self::$set_memory = 0;
|
||||||
|
self::$previous_memory = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the start memory velue, or reset to a new start value
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function setStartMemory(): void
|
||||||
|
{
|
||||||
|
self::$start_memory = memory_get_usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the and independent memory set for a sub tracking outside main
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function setMemory(): void
|
||||||
|
{
|
||||||
|
self::$set_memory = memory_get_usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calculate and set memory usage values
|
||||||
|
* this will return an array with all the data that can be used in
|
||||||
|
* printMemoryUsage for human readable output
|
||||||
|
*
|
||||||
|
* @param string $prefix A prefix tag
|
||||||
|
* @return array<string,int|string> return array
|
||||||
|
*/
|
||||||
|
public static function memoryUsage(string $prefix): array
|
||||||
|
{
|
||||||
|
// skip if DEBUG is off
|
||||||
|
if (self::$debug_memory === false) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if (empty(self::$start_memory)) {
|
||||||
|
self::$start_memory = memory_get_usage();
|
||||||
|
}
|
||||||
|
$memory_usage = memory_get_usage();
|
||||||
|
$data = [
|
||||||
|
'prefix' => $prefix,
|
||||||
|
'peak' => memory_get_peak_usage(),
|
||||||
|
'usage' => $memory_usage,
|
||||||
|
'start' => $memory_usage - self::$start_memory,
|
||||||
|
'last' => $memory_usage - self::$previous_memory,
|
||||||
|
'set' => $memory_usage - self::$set_memory
|
||||||
|
];
|
||||||
|
self::$previous_memory = $memory_usage;
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a human readable output from the memoryUsage function
|
||||||
|
* can be used for logging purpose
|
||||||
|
*
|
||||||
|
* @param array<string,int|string> $data Data array from memoryUsage
|
||||||
|
* @param bool $raw Flag to shaw unconverted memory numbers
|
||||||
|
* @return string Return debug string with memory usage
|
||||||
|
*/
|
||||||
|
public static function printMemoryUsage(array $data, bool $raw = false): string
|
||||||
|
{
|
||||||
|
return
|
||||||
|
'[' . $data['prefix'] . '] Peak/Curr/Change: '
|
||||||
|
. Byte::humanReadableByteFormat($data['peak'])
|
||||||
|
. '/'
|
||||||
|
. Byte::humanReadableByteFormat($data['usage'])
|
||||||
|
// . ($raw === true ? ' [' . $data['usage'] . ']' : '')
|
||||||
|
. '/Since Start: '
|
||||||
|
. Byte::humanReadableByteFormat($data['start'])
|
||||||
|
. ($raw === true ? ' [' . $data['start'] . ']' : '')
|
||||||
|
. ' | Since Last: '
|
||||||
|
. Byte::humanReadableByteFormat($data['last'])
|
||||||
|
. ($raw === true ? ' [' . $data['last'] . ']' : '')
|
||||||
|
. ' | Since Set: '
|
||||||
|
. Byte::humanReadableByteFormat($data['set'])
|
||||||
|
. ($raw === true ? ' [' . $data['set'] . ']' : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -12,43 +12,30 @@ class RunningTime
|
|||||||
{
|
{
|
||||||
// hr
|
// hr
|
||||||
/** @var float */
|
/** @var float */
|
||||||
private static $hr_starttime;
|
private static $hr_start_time;
|
||||||
/** @var float */
|
/** @var float */
|
||||||
private static $hr_runtime;
|
private static $hr_end_time;
|
||||||
/** @var float */
|
/** @var float */
|
||||||
private static $hr_endtime;
|
private static $hr_last_time;
|
||||||
// normal
|
// normal
|
||||||
/** @var float */
|
/** @var float */
|
||||||
private static $starttime;
|
private static $start_time;
|
||||||
/** @var float */
|
/** @var float */
|
||||||
private static $endtime;
|
private static $end_time;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private static $runningtime_string;
|
private static $running_time_string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for messure run time between two calls for this method
|
* sub calculation for running time based on out time.
|
||||||
* uses the hrtime() for running time
|
* If no running time set, return 0
|
||||||
* first call sets start time and returns 0,
|
*
|
||||||
* second call sets end time and returns the run time
|
* @param string $out_time
|
||||||
* the out_time parameter can be:
|
* @return float
|
||||||
* n/ns (nano), y/ys (micro), m/ms (milli), s (seconds)
|
|
||||||
* default is milliseconds
|
|
||||||
* @param string $out_time set return time adjustment calculation
|
|
||||||
* @return float running time without out_time suffix
|
|
||||||
*/
|
*/
|
||||||
public static function hrRunningTime(string $out_time = 'ms'): float
|
private static function hrRunningTimeCalc(
|
||||||
{
|
float $run_time,
|
||||||
// if start time not set, set start time
|
string $out_time = 'ms'
|
||||||
if (!self::$hr_starttime) {
|
): float {
|
||||||
self::$hr_starttime = hrtime(true);
|
|
||||||
self::$hr_runtime = 0;
|
|
||||||
} else {
|
|
||||||
self::$hr_endtime = hrtime(true);
|
|
||||||
self::$hr_runtime = self::$hr_endtime - self::$hr_starttime;
|
|
||||||
// reset start and end time past run
|
|
||||||
self::$hr_starttime = 0;
|
|
||||||
self::$hr_endtime = 0;
|
|
||||||
}
|
|
||||||
// init divisor, just in case
|
// init divisor, just in case
|
||||||
$divisor = 1;
|
$divisor = 1;
|
||||||
// check through valid out time, if nothing matches default to ms
|
// check through valid out time, if nothing matches default to ms
|
||||||
@@ -74,8 +61,67 @@ class RunningTime
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// return the run time in converted format
|
// return the run time in converted format
|
||||||
self::$hr_runtime /= $divisor;
|
return $run_time /= $divisor;
|
||||||
return self::$hr_runtime;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for messure run time between two calls for this method
|
||||||
|
* uses the hrtime() for running time
|
||||||
|
* first call sets start time and returns 0,
|
||||||
|
* every other call sets end time and returns the run time since start
|
||||||
|
* the out_time parameter can be:
|
||||||
|
* n/ns (nano), y/ys (micro), m/ms (milli), s (seconds)
|
||||||
|
* default is milliseconds
|
||||||
|
*
|
||||||
|
* @param string $out_time set return time adjustment calculation
|
||||||
|
* @return float running time without out_time suffix
|
||||||
|
*/
|
||||||
|
public static function hrRunningTime(string $out_time = 'ms'): float
|
||||||
|
{
|
||||||
|
// if start time not set, set start time
|
||||||
|
if (!self::$hr_start_time) {
|
||||||
|
self::$hr_start_time = hrtime(true);
|
||||||
|
self::$hr_last_time = self::$hr_start_time;
|
||||||
|
$run_time = 0;
|
||||||
|
} else {
|
||||||
|
self::$hr_end_time = hrtime(true);
|
||||||
|
$run_time = self::$hr_end_time - self::$hr_last_time;
|
||||||
|
self::$hr_last_time = self::$hr_end_time;
|
||||||
|
}
|
||||||
|
return self::hrRunningTimeCalc($run_time, $out_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* print overall end time , can only be called after hrRunningtime
|
||||||
|
* see $out_time parameter description in hrRunningtime.
|
||||||
|
* Does not record a new timestamp, only prints different between start and
|
||||||
|
* last recoreded timestamp
|
||||||
|
*
|
||||||
|
* @param string $out_time set return time adjustment calculation
|
||||||
|
* @return float overall running time without out_time suffix
|
||||||
|
*/
|
||||||
|
public static function hrRunningTimeFromStart(string $out_time = 'ms'): float
|
||||||
|
{
|
||||||
|
if (!self::$hr_start_time) {
|
||||||
|
return (float)0;
|
||||||
|
}
|
||||||
|
$time = self::hrRunningTimeCalc(
|
||||||
|
self::$hr_end_time - self::$hr_start_time,
|
||||||
|
$out_time
|
||||||
|
);
|
||||||
|
return $time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reset hr running time internal variables (start, end, last)
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function hrRunningTimeReset(): void
|
||||||
|
{
|
||||||
|
self::$hr_start_time = 0;
|
||||||
|
self::$hr_end_time = 0;
|
||||||
|
self::$hr_last_time = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,24 +137,24 @@ class RunningTime
|
|||||||
list($micro, $timestamp) = explode(' ', microtime());
|
list($micro, $timestamp) = explode(' ', microtime());
|
||||||
$running_time = 0;
|
$running_time = 0;
|
||||||
// set start & end time
|
// set start & end time
|
||||||
if (!self::$starttime) {
|
if (!self::$start_time) {
|
||||||
// always reset running time string on first call
|
// always reset running time string on first call
|
||||||
self::$runningtime_string = '';
|
self::$running_time_string = '';
|
||||||
self::$starttime = ((float)$micro + (float)$timestamp);
|
self::$start_time = ((float)$micro + (float)$timestamp);
|
||||||
self::$runningtime_string .= $simple ? 'Start: ' : "<b>Started at</b>: ";
|
self::$running_time_string .= $simple ? 'Start: ' : "<b>Started at</b>: ";
|
||||||
} else {
|
} else {
|
||||||
self::$endtime = ((float)$micro + (float)$timestamp);
|
self::$end_time = ((float)$micro + (float)$timestamp);
|
||||||
self::$runningtime_string .= $simple ? 'End: ' : "<b>Stopped at</b>: ";
|
self::$running_time_string .= $simple ? 'End: ' : "<b>Stopped at</b>: ";
|
||||||
}
|
}
|
||||||
self::$runningtime_string .= date('Y-m-d H:i:s', (int)$timestamp);
|
self::$running_time_string .= date('Y-m-d H:i:s', (int)$timestamp);
|
||||||
self::$runningtime_string .= ' ' . $micro . ($simple ? ', ' : '<br>');
|
self::$running_time_string .= ' ' . $micro . ($simple ? ', ' : '<br>');
|
||||||
// if both are set
|
// if both are set
|
||||||
if (self::$starttime && self::$endtime) {
|
if (self::$start_time && self::$end_time) {
|
||||||
$running_time = self::$endtime - self::$starttime;
|
$running_time = self::$end_time - self::$start_time;
|
||||||
self::$runningtime_string .= ($simple ? 'Run: ' : "<b>Script running time</b>: ") . $running_time . " s";
|
self::$running_time_string .= ($simple ? 'Run: ' : "<b>Script running time</b>: ") . $running_time . " s";
|
||||||
// reset start & end time after run
|
// reset start & end time after run
|
||||||
self::$starttime = 0;
|
self::$start_time = 0;
|
||||||
self::$endtime = 0;
|
self::$end_time = 0;
|
||||||
}
|
}
|
||||||
return $running_time;
|
return $running_time;
|
||||||
}
|
}
|
||||||
@@ -120,7 +166,7 @@ class RunningTime
|
|||||||
*/
|
*/
|
||||||
public static function runningTimeString(): string
|
public static function runningTimeString(): string
|
||||||
{
|
{
|
||||||
return self::$runningtime_string;
|
return self::$running_time_string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ class Support
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* wrapper around microtime function to print out y-m-d h:i:s.ms
|
* wrapper around microtime function to print out y-m-d h:i:s.ms
|
||||||
* @param int $set_microtime -1 to set micro time, 0 for none, positive for rounding
|
*
|
||||||
|
* @param int $set_microtime -1 to set micro time, 0 for none,
|
||||||
|
* positive for rounding
|
||||||
* @return string formated datetime string with microtime
|
* @return string formated datetime string with microtime
|
||||||
*/
|
*/
|
||||||
public static function printTime(int $set_microtime = -1): string
|
public static function printTime(int $set_microtime = -1): string
|
||||||
@@ -31,6 +33,7 @@ class Support
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* prints a html formatted (pre) array
|
* prints a html formatted (pre) array
|
||||||
|
*
|
||||||
* @param array<mixed> $array any array
|
* @param array<mixed> $array any array
|
||||||
* @param bool $no_html set to true to use ##HTMLPRE##
|
* @param bool $no_html set to true to use ##HTMLPRE##
|
||||||
* @return string formatted array for output with <pre> tag added
|
* @return string formatted array for output with <pre> tag added
|
||||||
@@ -44,12 +47,47 @@ class Support
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* alternate name for printAr function
|
||||||
|
*
|
||||||
|
* @param array<mixed> $array any array
|
||||||
|
* @param bool $no_html set to true to use ##HTMLPRE##
|
||||||
|
* @return string formatted array for output with <pre> tag added
|
||||||
|
*/
|
||||||
|
public static function printArray(array $array, bool $no_html = false): string
|
||||||
|
{
|
||||||
|
return self::printAr($array, $no_html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert bool value to string
|
||||||
|
* if $name is set prefix with nae
|
||||||
|
* default true: true, false: false
|
||||||
|
*
|
||||||
|
* @param bool $bool Variable to convert
|
||||||
|
* @param string $name [default: ''] Prefix name
|
||||||
|
* @param string $true [default: true] True string
|
||||||
|
* @param string $false [default: false] False string
|
||||||
|
* @return string String with converted bool text for debug
|
||||||
|
*/
|
||||||
|
public static function printBool(
|
||||||
|
bool $bool,
|
||||||
|
string $name = '',
|
||||||
|
string $true = 'true',
|
||||||
|
string $false = 'false'
|
||||||
|
): string {
|
||||||
|
$string = (!empty($name) ? '<b>' . $name . '</b>: ' : '')
|
||||||
|
. ($bool ? $true : $false);
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* print out any data as string
|
* print out any data as string
|
||||||
* will convert boolean to TRUE/FALSE
|
* will convert boolean to TRUE/FALSE
|
||||||
* if object return get_class
|
* if object return get_class
|
||||||
* for array use printAr function, can be controlled with no_html for
|
* for array use printAr function, can be controlled with no_html for
|
||||||
* Debug\Logging compatible output
|
* Debug\Logging compatible output
|
||||||
|
*
|
||||||
* @param mixed $mixed
|
* @param mixed $mixed
|
||||||
* @param bool $no_html set to true to use ##HTMLPRE##
|
* @param bool $no_html set to true to use ##HTMLPRE##
|
||||||
* @return string
|
* @return string
|
||||||
@@ -57,7 +95,7 @@ class Support
|
|||||||
public static function printToString($mixed, bool $no_html = false): string
|
public static function printToString($mixed, bool $no_html = false): string
|
||||||
{
|
{
|
||||||
if (is_bool($mixed)) {
|
if (is_bool($mixed)) {
|
||||||
return $mixed ? 'TRUE' : 'FALSE';
|
return self::printBool($mixed, '', 'TRUE', 'FALSE');
|
||||||
} elseif (is_resource($mixed)) {
|
} elseif (is_resource($mixed)) {
|
||||||
return (string)$mixed;
|
return (string)$mixed;
|
||||||
} elseif (is_object($mixed)) {
|
} elseif (is_object($mixed)) {
|
||||||
@@ -74,9 +112,11 @@ class Support
|
|||||||
/**
|
/**
|
||||||
* if there is a need to find out which parent method called a child method,
|
* if there is a need to find out which parent method called a child method,
|
||||||
* eg for debugging, this function does this
|
* eg for debugging, this function does this
|
||||||
|
*
|
||||||
* call this method in the child method and you get the parent function that called
|
* call this method in the child method and you get the parent function that called
|
||||||
* @param int $level debug level, default 1
|
* @param int $level debug level, default 1
|
||||||
* @return ?string null or the function that called the function where this method is called
|
* @return ?string null or the function that called the function
|
||||||
|
* where this method is called
|
||||||
*/
|
*/
|
||||||
public static function getCallerMethod(int $level = 1): ?string
|
public static function getCallerMethod(int $level = 1): ?string
|
||||||
{
|
{
|
||||||
@@ -95,6 +135,7 @@ class Support
|
|||||||
* called is last in order
|
* called is last in order
|
||||||
* Will start with start_level to skip unwanted from stack
|
* Will start with start_level to skip unwanted from stack
|
||||||
* Defaults to skip level 0 wich is this methid
|
* Defaults to skip level 0 wich is this methid
|
||||||
|
*
|
||||||
* @param integer $start_level From what level on, as defaul starts with 1
|
* @param integer $start_level From what level on, as defaul starts with 1
|
||||||
* to exclude self
|
* to exclude self
|
||||||
* @return array<mixed> All method names in list where max is last called
|
* @return array<mixed> All method names in list where max is last called
|
||||||
@@ -119,6 +160,7 @@ class Support
|
|||||||
* was called
|
* was called
|
||||||
* gets top level class
|
* gets top level class
|
||||||
* loops over the debug backtrace until if finds the first class (from the end)
|
* loops over the debug backtrace until if finds the first class (from the end)
|
||||||
|
*
|
||||||
* @return string Class name with namespace
|
* @return string Class name with namespace
|
||||||
*/
|
*/
|
||||||
public static function getCallerClass(): string
|
public static function getCallerClass(): string
|
||||||
|
|||||||
106
www/lib/CoreLibs/Get/DotEnv.php
Normal file
106
www/lib/CoreLibs/Get/DotEnv.php
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Get;
|
||||||
|
|
||||||
|
class DotEnv
|
||||||
|
{
|
||||||
|
/** @var string constant comment char, set to # */
|
||||||
|
private const COMMENT_CHAR = '#';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parses .env file
|
||||||
|
*
|
||||||
|
* Rules for .env file
|
||||||
|
* variable is any alphanumeric string followed by = on the same line
|
||||||
|
* content starts with the first non space part
|
||||||
|
* strings can be contained in "
|
||||||
|
* strings MUST be contained in " if they are multiline
|
||||||
|
* if string starts with " it will match until another " is found
|
||||||
|
* anything AFTER " is ignored
|
||||||
|
* if there are two variables with the same name only the first is used
|
||||||
|
* variables are case sensitive
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
* 0 for success full load
|
||||||
|
* 1 for file loadable, no data or data already loaded
|
||||||
|
* 2 for file not readable or open failed
|
||||||
|
* 3 for file not found
|
||||||
|
*/
|
||||||
|
public static function readEnvFile(
|
||||||
|
string $path = __DIR__,
|
||||||
|
string $env_file = '.env'
|
||||||
|
): int {
|
||||||
|
// default -1;
|
||||||
|
$status = -1;
|
||||||
|
$env_file_target = $path . DIRECTORY_SEPARATOR . $env_file;
|
||||||
|
// this is not a file -> abort
|
||||||
|
if (!is_file($env_file_target)) {
|
||||||
|
$status = 3;
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
// cannot open file -> abort
|
||||||
|
if (!is_readable($env_file_target)) {
|
||||||
|
$status = 2;
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
// open file
|
||||||
|
if (($fp = fopen($env_file_target, 'r')) === false) {
|
||||||
|
$status = 2;
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
// set to readable but not yet any data loaded
|
||||||
|
$status = 1;
|
||||||
|
$block = false;
|
||||||
|
$var = '';
|
||||||
|
while ($line = fgets($fp)) {
|
||||||
|
// main match for variable = value part
|
||||||
|
if (preg_match("/^\s*([\w_.]+)\s*=\s*((\"?).*)/", $line, $matches)) {
|
||||||
|
$var = $matches[1];
|
||||||
|
$value = $matches[2];
|
||||||
|
$quotes = $matches[3];
|
||||||
|
// write only if env is not set yet, and write only the first time
|
||||||
|
if (empty($_ENV[$var])) {
|
||||||
|
if (!empty($quotes)) {
|
||||||
|
// match greedy for first to last so we move any " if there are
|
||||||
|
if (preg_match('/^"(.*[^\\\])"/U', $value, $matches)) {
|
||||||
|
$value = $matches[1];
|
||||||
|
} else {
|
||||||
|
// this is a multi line
|
||||||
|
$block = true;
|
||||||
|
// first " in string remove
|
||||||
|
// add removed new line back because this is a multi line
|
||||||
|
$value = ltrim($value, '"') . PHP_EOL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// strip any quotes at end for unquoted single line
|
||||||
|
// an right hand spaces are removed too
|
||||||
|
$value = false !== ($pos = strpos($value, self::COMMENT_CHAR)) ?
|
||||||
|
rtrim(substr($value, 0, $pos)) : $value;
|
||||||
|
}
|
||||||
|
// if block is set, we strip line of slashes
|
||||||
|
$_ENV[$var] = $block === true ? stripslashes($value) : $value;
|
||||||
|
// set successful load
|
||||||
|
$status = 0;
|
||||||
|
}
|
||||||
|
} elseif ($block === true) {
|
||||||
|
// read line until there is a unescaped "
|
||||||
|
// this also strips everything after the last "
|
||||||
|
if (preg_match("/(.*[^\\\])\"/", $line, $matches)) {
|
||||||
|
$block = false;
|
||||||
|
// strip ending " and EVERYTHING that follows after that
|
||||||
|
$line = $matches[1];
|
||||||
|
}
|
||||||
|
// strip line of slashes
|
||||||
|
$_ENV[$var] .= stripslashes($line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace CoreLibs\Get;
|
namespace CoreLibs\Get;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use \CoreLibs\Get\DotEnv instead
|
||||||
|
*/
|
||||||
class ReadEnvFile
|
class ReadEnvFile
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -24,71 +27,16 @@ class ReadEnvFile
|
|||||||
* @return int -1 other error
|
* @return int -1 other error
|
||||||
* 0 for success full load
|
* 0 for success full load
|
||||||
* 1 for file loadable, but no data inside
|
* 1 for file loadable, but no data inside
|
||||||
* 2 for file not readable
|
* 2 for file not readable or open failed
|
||||||
* 3 for file not found
|
* 3 for file not found
|
||||||
|
* @deprecated Use \CoreLibs\Get\DotEnv::readEnvFile() instead
|
||||||
*/
|
*/
|
||||||
public static function readEnvFile(
|
public static function readEnvFile(
|
||||||
string $path = __DIR__,
|
string $path = __DIR__,
|
||||||
string $env_file = '.env'
|
string $env_file = '.env'
|
||||||
): int {
|
): int {
|
||||||
// default -1;
|
return \CoreLibs\Get\DotEnv::readEnvFile($path, $env_file);
|
||||||
$status = -1;
|
|
||||||
$env_file_target = $path . DIRECTORY_SEPARATOR . $env_file;
|
|
||||||
// this is not a file -> abort
|
|
||||||
if (!is_file($env_file_target)) {
|
|
||||||
$status = 3;
|
|
||||||
return $status;
|
|
||||||
}
|
|
||||||
// cannot open file -> abort
|
|
||||||
if (($fp = fopen($env_file_target, 'r')) === false) {
|
|
||||||
$status = 2;
|
|
||||||
return $status;
|
|
||||||
}
|
|
||||||
// set to readable but not yet any data loaded
|
|
||||||
$status = 1;
|
|
||||||
$block = false;
|
|
||||||
$var = '';
|
|
||||||
while ($line = fgets($fp)) {
|
|
||||||
// main match for variable = value part
|
|
||||||
if (preg_match("/^\s*([\w_.]+)\s*=\s*((\"?).*)/", $line, $matches)) {
|
|
||||||
$var = $matches[1];
|
|
||||||
$value = $matches[2];
|
|
||||||
$quotes = $matches[3];
|
|
||||||
// write only if env is not set yet, and write only the first time
|
|
||||||
if (empty($_ENV[$var])) {
|
|
||||||
if (!empty($quotes)) {
|
|
||||||
// match greedy for first to last so we move any " if there are
|
|
||||||
if (preg_match('/^"(.*[^\\\])"/U', $value, $matches)) {
|
|
||||||
$value = $matches[1];
|
|
||||||
} else {
|
|
||||||
// this is a multi line
|
|
||||||
$block = true;
|
|
||||||
// first " in string remove
|
|
||||||
// add removed new line back because this is a multi line
|
|
||||||
$value = ltrim($value, '"') . PHP_EOL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if block is set, we strip line of slashes
|
|
||||||
$_ENV[$var] = $block === true ? stripslashes($value) : $value;
|
|
||||||
// set successful load
|
|
||||||
$status = 0;
|
|
||||||
}
|
|
||||||
} elseif ($block === true) {
|
|
||||||
// read line until there is a unescaped "
|
|
||||||
// this also strips everything after the last "
|
|
||||||
if (preg_match("/(.*[^\\\])\"/", $line, $matches)) {
|
|
||||||
$block = false;
|
|
||||||
// strip ending " and EVERYTHING that follows after that
|
|
||||||
$line = $matches[1];
|
|
||||||
}
|
|
||||||
// strip line of slashes
|
|
||||||
$_ENV[$var] .= stripslashes($line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose($fp);
|
|
||||||
return $status;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class System
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* helper function for PHP file upload error messgaes to messge string
|
* helper function for PHP file upload error messgaes to messge string
|
||||||
|
*
|
||||||
* @param int $error_code integer _FILE upload error code
|
* @param int $error_code integer _FILE upload error code
|
||||||
* @return string message string, translated
|
* @return string message string, translated
|
||||||
*/
|
*/
|
||||||
@@ -53,6 +54,7 @@ class System
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get the host name without the port as given by the SELF var
|
* get the host name without the port as given by the SELF var
|
||||||
|
*
|
||||||
* @return array<mixed> host name/port name
|
* @return array<mixed> host name/port name
|
||||||
*/
|
*/
|
||||||
public static function getHostName(): array
|
public static function getHostName(): array
|
||||||
@@ -64,6 +66,7 @@ class System
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get the page name of the curronte page
|
* get the page name of the curronte page
|
||||||
|
*
|
||||||
* @param int $strip_ext WITH_EXTENSION: keep filename as is (default)
|
* @param int $strip_ext WITH_EXTENSION: keep filename as is (default)
|
||||||
* NO_EXTENSION: strip page file name extension
|
* NO_EXTENSION: strip page file name extension
|
||||||
* FULL_PATH: keep filename as is, but add dirname too
|
* FULL_PATH: keep filename as is, but add dirname too
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class FileReader
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* file read constructor
|
* file read constructor
|
||||||
|
*
|
||||||
* @param string $filename file name to load
|
* @param string $filename file name to load
|
||||||
*/
|
*/
|
||||||
public function __construct(string $filename)
|
public function __construct(string $filename)
|
||||||
@@ -55,6 +56,7 @@ class FileReader
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* read byte data length
|
* read byte data length
|
||||||
|
*
|
||||||
* @param int $bytes how many bytes to read
|
* @param int $bytes how many bytes to read
|
||||||
* @return string read data as string
|
* @return string read data as string
|
||||||
*/
|
*/
|
||||||
@@ -83,6 +85,7 @@ class FileReader
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* seek to a position in the file
|
* seek to a position in the file
|
||||||
|
*
|
||||||
* @param int $pos position where to go to
|
* @param int $pos position where to go to
|
||||||
* @return int file position after seek done
|
* @return int file position after seek done
|
||||||
*/
|
*/
|
||||||
@@ -98,6 +101,7 @@ class FileReader
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* get current position in file
|
* get current position in file
|
||||||
|
*
|
||||||
* @return int current position in bytes
|
* @return int current position in bytes
|
||||||
*/
|
*/
|
||||||
public function currentpos(): int
|
public function currentpos(): int
|
||||||
@@ -107,6 +111,7 @@ class FileReader
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* file length/size
|
* file length/size
|
||||||
|
*
|
||||||
* @return int file size in bytes
|
* @return int file size in bytes
|
||||||
*/
|
*/
|
||||||
public function length(): int
|
public function length(): int
|
||||||
@@ -116,6 +121,7 @@ class FileReader
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* close open file handler
|
* close open file handler
|
||||||
|
*
|
||||||
* @return void has no return
|
* @return void has no return
|
||||||
*/
|
*/
|
||||||
public function close(): void
|
public function close(): void
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user