Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e80b3b8dfd | ||
|
|
2b079ff836 | ||
|
|
37201799b5 | ||
|
|
b9d8911c7b | ||
|
|
c51ceb926e | ||
|
|
b4b33d6873 |
@@ -267,6 +267,8 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'GROUP_ACL_LEVEL' => -1,
|
'GROUP_ACL_LEVEL' => -1,
|
||||||
'PAGES_ACL_LEVEL' => [],
|
'PAGES_ACL_LEVEL' => [],
|
||||||
'USER_ACL_LEVEL' => -1,
|
'USER_ACL_LEVEL' => -1,
|
||||||
|
'USER_ADDITIONAL_ACL' => [],
|
||||||
|
'GROUP_ADDITIONAL_ACL' => [],
|
||||||
'UNIT_UID' => [
|
'UNIT_UID' => [
|
||||||
'AdminAccess' => 1,
|
'AdminAccess' => 1,
|
||||||
],
|
],
|
||||||
@@ -280,6 +282,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'data' => [
|
'data' => [
|
||||||
'test' => 'value',
|
'test' => 'value',
|
||||||
],
|
],
|
||||||
|
'additional_acl' => []
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
// 'UNIT_DEFAULT' => '',
|
// 'UNIT_DEFAULT' => '',
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
4,
|
4,
|
||||||
'b',
|
'b',
|
||||||
'c' => 'test',
|
'c' => 'test',
|
||||||
|
'single' => 'single',
|
||||||
'same' => 'same',
|
'same' => 'same',
|
||||||
'deep' => [
|
'deep' => [
|
||||||
'sub' => [
|
'sub' => [
|
||||||
@@ -288,6 +289,188 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function arraySearchKeyProvider(): array
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
0: search in array
|
||||||
|
1: search keys
|
||||||
|
2: flat flag
|
||||||
|
3: prefix flag
|
||||||
|
4: expected array
|
||||||
|
*/
|
||||||
|
return [
|
||||||
|
// single
|
||||||
|
'find single, standard' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['single'],
|
||||||
|
2 => null,
|
||||||
|
3 => null,
|
||||||
|
4 => [
|
||||||
|
0 => [
|
||||||
|
'value' => 'single',
|
||||||
|
'path' => ['single'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'find single, prefix' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['single'],
|
||||||
|
2 => null,
|
||||||
|
3 => true,
|
||||||
|
4 => [
|
||||||
|
'single' => [
|
||||||
|
0 => [
|
||||||
|
'value' => 'single',
|
||||||
|
'path' => ['single'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'find single, flat' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['single'],
|
||||||
|
2 => true,
|
||||||
|
3 => null,
|
||||||
|
4 => [
|
||||||
|
'single',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'find single, flat, prefix' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['single'],
|
||||||
|
2 => true,
|
||||||
|
3 => true,
|
||||||
|
4 => [
|
||||||
|
'single' => [
|
||||||
|
'single',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
// not found
|
||||||
|
'not found, standard' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['NOT FOUND'],
|
||||||
|
2 => null,
|
||||||
|
3 => null,
|
||||||
|
4 => [],
|
||||||
|
],
|
||||||
|
'not found, standard, prefix' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['NOT FOUND'],
|
||||||
|
2 => null,
|
||||||
|
3 => true,
|
||||||
|
4 => [
|
||||||
|
'NOT FOUND' => [],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'not found, flat' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['NOT FOUND'],
|
||||||
|
2 => true,
|
||||||
|
3 => null,
|
||||||
|
4 => [],
|
||||||
|
],
|
||||||
|
'not found, flat, prefix' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['NOT FOUND'],
|
||||||
|
2 => true,
|
||||||
|
3 => true,
|
||||||
|
4 => [
|
||||||
|
'NOT FOUND' => [],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
// multi
|
||||||
|
'multiple found, standard' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['same'],
|
||||||
|
2 => null,
|
||||||
|
3 => null,
|
||||||
|
4 => [
|
||||||
|
[
|
||||||
|
'value' => 'same',
|
||||||
|
'path' => ['a', 'same', ],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => 'same',
|
||||||
|
'path' => ['same', ],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => 'same',
|
||||||
|
'path' => ['deep', 'sub', 'same', ],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'multiple found, flat' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['same'],
|
||||||
|
2 => true,
|
||||||
|
3 => null,
|
||||||
|
4 => ['same', 'same', 'same', ],
|
||||||
|
],
|
||||||
|
// search with multiple
|
||||||
|
'search multiple, standard' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['single', 'nested'],
|
||||||
|
2 => null,
|
||||||
|
3 => null,
|
||||||
|
4 => [
|
||||||
|
[
|
||||||
|
'value' => 'single',
|
||||||
|
'path' => ['single'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => 'bar',
|
||||||
|
'path' => ['deep', 'sub', 'nested', ],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'search multiple, prefix' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['single', 'nested'],
|
||||||
|
2 => null,
|
||||||
|
3 => true,
|
||||||
|
4 => [
|
||||||
|
'single' => [
|
||||||
|
[
|
||||||
|
'value' => 'single',
|
||||||
|
'path' => ['single'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'nested' => [
|
||||||
|
[
|
||||||
|
'value' => 'bar',
|
||||||
|
'path' => ['deep', 'sub', 'nested', ],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'search multiple, flat' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['single', 'nested'],
|
||||||
|
2 => true,
|
||||||
|
3 => null,
|
||||||
|
4 => [
|
||||||
|
'single', 'bar',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'search multiple, flat, prefix' => [
|
||||||
|
0 => self::$array,
|
||||||
|
1 => ['single', 'nested'],
|
||||||
|
2 => true,
|
||||||
|
3 => true,
|
||||||
|
4 => [
|
||||||
|
'single' => ['single', ],
|
||||||
|
'nested' => ['bar', ],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* provides array listing for the merge test
|
* provides array listing for the merge test
|
||||||
*
|
*
|
||||||
@@ -691,6 +874,44 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers::arraySearchKey
|
||||||
|
* @dataProvider arraySearchKeyProvider
|
||||||
|
* @testdox arraySearchKey Search array with keys and flat: $flat, prefix: $prefix [$_dataName]
|
||||||
|
*
|
||||||
|
* @param array $input
|
||||||
|
* @param array $needles
|
||||||
|
* @param bool|null $flat
|
||||||
|
* @param bool|null $prefix
|
||||||
|
* @param array $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testArraySearchKey(
|
||||||
|
array $input,
|
||||||
|
array $needles,
|
||||||
|
?bool $flat,
|
||||||
|
?bool $prefix,
|
||||||
|
array $expected
|
||||||
|
): void {
|
||||||
|
if ($flat === null && $prefix === null) {
|
||||||
|
$result = \CoreLibs\Combined\ArrayHandler::arraySearchKey($input, $needles);
|
||||||
|
} elseif ($flat === null) {
|
||||||
|
$result = \CoreLibs\Combined\ArrayHandler::arraySearchKey($input, $needles, prefix: $prefix);
|
||||||
|
} elseif ($prefix === null) {
|
||||||
|
$result = \CoreLibs\Combined\ArrayHandler::arraySearchKey($input, $needles, flat: $flat);
|
||||||
|
} else {
|
||||||
|
$result = \CoreLibs\Combined\ArrayHandler::arraySearchKey($input, $needles, $flat, $prefix);
|
||||||
|
}
|
||||||
|
// print "E: " . print_r($expected, true) . "\n";
|
||||||
|
// print "R: " . print_r($result, true) . "\n";
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$result
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -149,6 +149,38 @@ function rec(string $pre, string $cur, array $node = [])
|
|||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'image' => 'foo',
|
||||||
|
'element' => 'w-1',
|
||||||
|
'rotate' => 360,
|
||||||
|
'html' => [
|
||||||
|
'image' => 'bar',
|
||||||
|
'result_image' => 'baz',
|
||||||
|
'rule' => 'wrong'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'image' => 'large'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'nothing' => 'wrong'
|
||||||
|
],
|
||||||
|
'nest' => [
|
||||||
|
'nust' => [
|
||||||
|
'nist' => [
|
||||||
|
'foo' => 'bar',
|
||||||
|
'image' => 'long, long'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
's' => [
|
||||||
|
'image' => 'path?'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$search = ['image', 'result_image', 'nothing', 'EMPTY'];
|
||||||
|
$result = ArrayHandler::arraySearchKey($data, $search);
|
||||||
|
print "ARRAYSEARCHKEY: Search: " . DgS::printAr($search) . ", Found: " . DgS::printAr($result) . "<br>";
|
||||||
|
|
||||||
// $test = [
|
// $test = [
|
||||||
// 'A' => [
|
// 'A' => [
|
||||||
// 'B' => [],
|
// 'B' => [],
|
||||||
|
|||||||
@@ -212,11 +212,11 @@ $query = <<<EOM
|
|||||||
INSERT INTO
|
INSERT INTO
|
||||||
test_foo
|
test_foo
|
||||||
(
|
(
|
||||||
test
|
test, string_a
|
||||||
) VALUES (
|
) VALUES (
|
||||||
$1
|
$1, '$2'
|
||||||
)
|
)
|
||||||
RETURNING test
|
RETURNING test, string_a
|
||||||
EOM;
|
EOM;
|
||||||
$db->dbPrepare("ins_test_foo_eom", $query);
|
$db->dbPrepare("ins_test_foo_eom", $query);
|
||||||
$status = $db->dbExecute("ins_test_foo_eom", ['EOM BAR TEST ' . time()]);
|
$status = $db->dbExecute("ins_test_foo_eom", ['EOM BAR TEST ' . time()]);
|
||||||
@@ -413,13 +413,35 @@ if (is_array($s_res = $db->dbReturnRow($q)) && !empty($s_res['test'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UPDATE WITH RETURNING
|
// UPDATE WITH RETURNING
|
||||||
$status = $db->dbExec("UPDATE test_foo SET test = 'SOMETHING DIFFERENT' "
|
$status = $db->dbExec("UPDATE test_foo SET test = 'SOMETHING DIFFERENT', string_a = '" . (string)rand(1, 100) . "' "
|
||||||
. "WHERE test_foo_id = " . (int)$last_insert_pk . " RETURNING test");
|
. "WHERE test_foo_id = " . (int)$last_insert_pk . " RETURNING test_foo.test, string_a");
|
||||||
print "UPDATE WITH PK " . Support::printToString($last_insert_pk)
|
print "UPDATE WITH PK " . Support::printToString($last_insert_pk)
|
||||||
. " RETURN STATUS: " . Support::printToString($status) . " |<br>"
|
. " RETURN STATUS: " . Support::printToString($status) . " |<br>"
|
||||||
. "QUERY: " . $db->dbGetQuery() . " |<br>"
|
. "QUERY: " . $db->dbGetQuery() . " |<br>"
|
||||||
. "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>";
|
||||||
|
// UPDATE BUT EOM STYLE
|
||||||
|
$status = $db->dbExecParams(
|
||||||
|
<<<EOM
|
||||||
|
UPDATE
|
||||||
|
test_foo
|
||||||
|
SET
|
||||||
|
test = ?,
|
||||||
|
string_a = ?
|
||||||
|
WHERE
|
||||||
|
tset_foo_id = ?
|
||||||
|
RETURNING
|
||||||
|
test_foo.test, string_a
|
||||||
|
EOM,
|
||||||
|
['SOMETHING DIFFERENT EOM', (string)rand(1, 100)]
|
||||||
|
);
|
||||||
|
print "UPDATE EOM WITH PK " . Support::printToString($last_insert_pk)
|
||||||
|
. " RETURN STATUS: " . Support::printToString($status) . " |<br>"
|
||||||
|
. "QUERY: " . $db->dbGetQuery() . " |<br>"
|
||||||
|
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||||
|
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||||
|
|
||||||
|
// a stand alone insert?
|
||||||
$db->dbExec("INSERT INTO test_foo (test) VALUES ('STAND ALONE')");
|
$db->dbExec("INSERT INTO test_foo (test) VALUES ('STAND ALONE')");
|
||||||
|
|
||||||
// INSERT WITH NO RETURNING
|
// INSERT WITH NO RETURNING
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ declare(strict_types=1);
|
|||||||
namespace CoreLibs\ACL;
|
namespace CoreLibs\ACL;
|
||||||
|
|
||||||
use CoreLibs\Check\Password;
|
use CoreLibs\Check\Password;
|
||||||
|
use CoreLibs\Convert\Json;
|
||||||
|
|
||||||
class Login
|
class Login
|
||||||
{
|
{
|
||||||
@@ -753,7 +754,10 @@ class Login
|
|||||||
// we have to get the themes in here too
|
// we have to get the themes in here too
|
||||||
$q = "SELECT eu.edit_user_id, eu.username, eu.password, "
|
$q = "SELECT eu.edit_user_id, eu.username, eu.password, "
|
||||||
. "eu.edit_group_id, "
|
. "eu.edit_group_id, "
|
||||||
. "eg.name AS edit_group_name, admin, "
|
. "eg.name AS edit_group_name, eu.admin, "
|
||||||
|
// additinal acl lists
|
||||||
|
. "eu.additional_acl AS user_additional_acl, "
|
||||||
|
. "eg.additional_acl AS group_additional_acl, "
|
||||||
// login error + locked
|
// login error + locked
|
||||||
. "eu.login_error_count, eu.login_error_date_last, "
|
. "eu.login_error_count, eu.login_error_date_last, "
|
||||||
. "eu.login_error_date_first, eu.strict, eu.locked, "
|
. "eu.login_error_date_first, eu.strict, eu.locked, "
|
||||||
@@ -901,8 +905,10 @@ class Login
|
|||||||
$_SESSION['GROUP_NAME'] = $res['edit_group_name'];
|
$_SESSION['GROUP_NAME'] = $res['edit_group_name'];
|
||||||
$_SESSION['USER_ACL_LEVEL'] = $res['user_level'];
|
$_SESSION['USER_ACL_LEVEL'] = $res['user_level'];
|
||||||
$_SESSION['USER_ACL_TYPE'] = $res['user_type'];
|
$_SESSION['USER_ACL_TYPE'] = $res['user_type'];
|
||||||
|
$_SESSION['USER_ADDITIONAL_ACL'] = Json::jsonConvertToArray($res['user_additional_acl']);
|
||||||
$_SESSION['GROUP_ACL_LEVEL'] = $res['group_level'];
|
$_SESSION['GROUP_ACL_LEVEL'] = $res['group_level'];
|
||||||
$_SESSION['GROUP_ACL_TYPE'] = $res['group_type'];
|
$_SESSION['GROUP_ACL_TYPE'] = $res['group_type'];
|
||||||
|
$_SESSION['GROUP_ADDITIONAL_ACL'] = Json::jsonConvertToArray($res['group_additional_acl']);
|
||||||
// deprecated TEMPLATE setting
|
// deprecated TEMPLATE setting
|
||||||
$_SESSION['TEMPLATE'] = $res['template'] ? $res['template'] : '';
|
$_SESSION['TEMPLATE'] = $res['template'] ? $res['template'] : '';
|
||||||
$_SESSION['HEADER_COLOR'] = !empty($res['second_header_color']) ?
|
$_SESSION['HEADER_COLOR'] = !empty($res['second_header_color']) ?
|
||||||
@@ -1021,7 +1027,8 @@ class Login
|
|||||||
$_SESSION['PAGES'] = $pages;
|
$_SESSION['PAGES'] = $pages;
|
||||||
$_SESSION['PAGES_ACL_LEVEL'] = $pages_acl;
|
$_SESSION['PAGES_ACL_LEVEL'] = $pages_acl;
|
||||||
// load the edit_access user rights
|
// load the edit_access user rights
|
||||||
$q = "SELECT ea.edit_access_id, level, type, ea.name, ea.color, ea.uid, edit_default "
|
$q = "SELECT ea.edit_access_id, level, type, ea.name, "
|
||||||
|
. "ea.color, ea.uid, edit_default, ea.additional_acl "
|
||||||
. "FROM edit_access_user eau, edit_access_right ear, edit_access ea "
|
. "FROM edit_access_user eau, edit_access_right ear, edit_access ea "
|
||||||
. "WHERE eau.edit_access_id = ea.edit_access_id "
|
. "WHERE eau.edit_access_id = ea.edit_access_id "
|
||||||
. "AND eau.edit_access_right_id = ear.edit_access_right_id "
|
. "AND eau.edit_access_right_id = ear.edit_access_right_id "
|
||||||
@@ -1048,6 +1055,7 @@ class Login
|
|||||||
'uid' => $res['uid'],
|
'uid' => $res['uid'],
|
||||||
'color' => $res['color'],
|
'color' => $res['color'],
|
||||||
'default' => $res['edit_default'],
|
'default' => $res['edit_default'],
|
||||||
|
'additional_acl' => Json::jsonConvertToArray($res['additional_acl']),
|
||||||
'data' => $ea_data
|
'data' => $ea_data
|
||||||
];
|
];
|
||||||
// set the default unit
|
// set the default unit
|
||||||
@@ -1122,6 +1130,11 @@ class Login
|
|||||||
// username (login), group name
|
// username (login), group name
|
||||||
$this->acl['user_name'] = $_SESSION['USER_NAME'];
|
$this->acl['user_name'] = $_SESSION['USER_NAME'];
|
||||||
$this->acl['group_name'] = $_SESSION['GROUP_NAME'];
|
$this->acl['group_name'] = $_SESSION['GROUP_NAME'];
|
||||||
|
// set additional acl
|
||||||
|
$this->acl['additional_acl'] = [
|
||||||
|
'user' => $_SESSION['USER_ADDITIONAL_ACL'],
|
||||||
|
'group' => $_SESSION['GROUP_ADDITIONAL_ACL'],
|
||||||
|
];
|
||||||
// we start with the default acl
|
// we start with the default acl
|
||||||
$this->acl['base'] = $this->default_acl_level;
|
$this->acl['base'] = $this->default_acl_level;
|
||||||
|
|
||||||
@@ -1184,7 +1197,8 @@ class Login
|
|||||||
'uid' => $unit['uid'],
|
'uid' => $unit['uid'],
|
||||||
'level' => $this->default_acl_list[$this->acl['unit'][$ea_id]]['name'] ?? -1,
|
'level' => $this->default_acl_list[$this->acl['unit'][$ea_id]]['name'] ?? -1,
|
||||||
'default' => $unit['default'],
|
'default' => $unit['default'],
|
||||||
'data' => $unit['data']
|
'data' => $unit['data'],
|
||||||
|
'additional_acl' => $unit['additional_acl']
|
||||||
];
|
];
|
||||||
// set default
|
// set default
|
||||||
if (!empty($unit['default'])) {
|
if (!empty($unit['default'])) {
|
||||||
|
|||||||
@@ -177,6 +177,63 @@ class ArrayHandler
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* search for one or many keys in array and return matching values
|
||||||
|
* If flat is set to true, return flat array with found values only
|
||||||
|
* If prefix is turned on each found group will be prefixed with the
|
||||||
|
* search key
|
||||||
|
*
|
||||||
|
* @param array<mixed> $array array to search in
|
||||||
|
* @param array<mixed> $needles keys to find in array
|
||||||
|
* @param bool $flat [false] Turn on flat output
|
||||||
|
* @param bool $prefix [false] Prefix found with needle key
|
||||||
|
* @return array<mixed> Found values
|
||||||
|
*/
|
||||||
|
public static function arraySearchKey(
|
||||||
|
array $array,
|
||||||
|
array $needles,
|
||||||
|
bool $flat = false,
|
||||||
|
bool $prefix = false
|
||||||
|
): array {
|
||||||
|
$iterator = new \RecursiveArrayIterator($array);
|
||||||
|
$recursive = new \RecursiveIteratorIterator(
|
||||||
|
$iterator,
|
||||||
|
\RecursiveIteratorIterator::SELF_FIRST
|
||||||
|
);
|
||||||
|
$hit_list = [];
|
||||||
|
if ($prefix === true) {
|
||||||
|
$hit_list = array_fill_keys($needles, []);
|
||||||
|
}
|
||||||
|
$key_path = [];
|
||||||
|
$prev_depth = 0;
|
||||||
|
foreach ($recursive as $key => $value) {
|
||||||
|
if ($prev_depth > $recursive->getDepth()) {
|
||||||
|
$key_path = [];
|
||||||
|
}
|
||||||
|
$prev_depth = $recursive->getDepth();
|
||||||
|
if ($flat === false) {
|
||||||
|
$key_path[$recursive->getDepth()] = $key;
|
||||||
|
}
|
||||||
|
if (in_array($key, $needles, true)) {
|
||||||
|
ksort($key_path);
|
||||||
|
if ($flat === true) {
|
||||||
|
$hit = $value;
|
||||||
|
} else {
|
||||||
|
$hit = [
|
||||||
|
'value' => $value,
|
||||||
|
'path' => $key_path
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if ($prefix === true) {
|
||||||
|
$hit_list[$key][] = $hit;
|
||||||
|
} else {
|
||||||
|
$hit_list[] = $hit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $hit_list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* correctly recursive merges as an array as array_merge_recursive
|
* correctly recursive merges as an array as array_merge_recursive
|
||||||
* just glues things together
|
* just glues things together
|
||||||
|
|||||||
@@ -279,8 +279,20 @@ class IO
|
|||||||
public const NO_CACHE = 3;
|
public const NO_CACHE = 3;
|
||||||
/** @var string default hash type */
|
/** @var string default hash type */
|
||||||
public const ERROR_HASH_TYPE = 'adler32';
|
public const ERROR_HASH_TYPE = 'adler32';
|
||||||
|
/**
|
||||||
|
* @var string regex for params: only stand alone $number allowed
|
||||||
|
* never allowed to start with '
|
||||||
|
* must be after space/tab, =, (
|
||||||
|
*/
|
||||||
|
public const REGEX_PARAMS = '/[^\'][\s(=](\$[0-9]{1,})/';
|
||||||
/** @var string regex to get returning with matches at position 1 */
|
/** @var string regex to get returning with matches at position 1 */
|
||||||
public const REGEX_RETURNING = '/\s+returning\s+(.+?);?$/i';
|
public const REGEX_RETURNING = '/\s+returning\s+(.+\s*(?:.+\s*)+);?$/i';
|
||||||
|
// REGEX_SELECT
|
||||||
|
// REGEX_UPDATE
|
||||||
|
// REGEX INSERT
|
||||||
|
// REGEX_INSERT_UPDATE_DELETE
|
||||||
|
// REGEX_FROM_TABLE
|
||||||
|
// REGEX_INSERT_UPDATE_DELETE_TABLE
|
||||||
|
|
||||||
// recommend to set private/protected and only allow setting via method
|
// recommend to set private/protected and only allow setting via method
|
||||||
// can bet set from outside
|
// can bet set from outside
|
||||||
@@ -1017,7 +1029,7 @@ class IO
|
|||||||
{
|
{
|
||||||
// search for $1, $2, in the query and push it into the control array
|
// search for $1, $2, in the query and push it into the control array
|
||||||
// skip counts for same eg $1, $1, $2 = 2 and not 3
|
// skip counts for same eg $1, $1, $2 = 2 and not 3
|
||||||
preg_match_all('/(\$[0-9]{1,})/', $query, $match);
|
preg_match_all(self::REGEX_PARAMS, $query, $match);
|
||||||
$placeholder_count = count(array_unique($match[1]));
|
$placeholder_count = count(array_unique($match[1]));
|
||||||
if ($params_count != $placeholder_count) {
|
if ($params_count != $placeholder_count) {
|
||||||
$this->__dbError(
|
$this->__dbError(
|
||||||
@@ -1134,7 +1146,7 @@ class IO
|
|||||||
$this->params
|
$this->params
|
||||||
),
|
),
|
||||||
'__dbPrepareExec',
|
'__dbPrepareExec',
|
||||||
($this->params === [] ? 'Q' : 'Qp'),
|
($this->params === [] ? 'Q' : 'Qp')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// import protection, hash needed
|
// import protection, hash needed
|
||||||
@@ -1154,7 +1166,15 @@ class IO
|
|||||||
$this->query_called[$query_hash] > $this->MAX_QUERY_CALL
|
$this->query_called[$query_hash] > $this->MAX_QUERY_CALL
|
||||||
) {
|
) {
|
||||||
$this->__dbError(30, false, $this->query);
|
$this->__dbError(30, false, $this->query);
|
||||||
$this->__dbDebug('db', $this->query, 'dbExec', 'Q[nc]');
|
$this->__dbDebug(
|
||||||
|
'db',
|
||||||
|
$this->__dbDebugPrepare(
|
||||||
|
$this->query,
|
||||||
|
$this->params
|
||||||
|
),
|
||||||
|
'dbExec',
|
||||||
|
($this->params === [] ? 'Q[nc]' : 'Qp[nc]')
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->query_called[$query_hash] ++;
|
$this->query_called[$query_hash] ++;
|
||||||
@@ -1933,6 +1953,18 @@ class IO
|
|||||||
// check if params count matches
|
// check if params count matches
|
||||||
// checks if the params count given matches the expected count
|
// checks if the params count given matches the expected count
|
||||||
if ($this->__dbCheckQueryParams($query, count($params)) === false) {
|
if ($this->__dbCheckQueryParams($query, count($params)) === false) {
|
||||||
|
// in case we got an error print out query
|
||||||
|
if ($this->db_debug) {
|
||||||
|
$this->__dbDebug(
|
||||||
|
'db',
|
||||||
|
$this->__dbDebugPrepare(
|
||||||
|
$this->query,
|
||||||
|
$this->params
|
||||||
|
),
|
||||||
|
'dbReturn',
|
||||||
|
($this->params === [] ? 'Q[e]' : 'Qp[e]')
|
||||||
|
);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// set first call to false
|
// set first call to false
|
||||||
@@ -1956,7 +1988,15 @@ class IO
|
|||||||
$this->cursor_ext[$query_hash]['log'][] = 'No 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->__dbDebugPrepare(
|
||||||
|
$this->cursor_ext[$query_hash]['query'],
|
||||||
|
$this->cursor_ext[$query_hash]['params']
|
||||||
|
),
|
||||||
|
'dbReturn',
|
||||||
|
($this->cursor_ext[$query_hash]['params'] === [] ? 'Q' : 'Qp'),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// if no DB Handler try to reconnect
|
// if no DB Handler try to reconnect
|
||||||
if (!$this->dbh) {
|
if (!$this->dbh) {
|
||||||
@@ -1985,7 +2025,15 @@ class IO
|
|||||||
// if still no cursor ...
|
// if still no cursor ...
|
||||||
if (!$this->cursor_ext[$query_hash]['cursor']) {
|
if (!$this->cursor_ext[$query_hash]['cursor']) {
|
||||||
if ($this->db_debug) {
|
if ($this->db_debug) {
|
||||||
$this->__dbDebug('db', $this->cursor_ext[$query_hash]['query'], 'dbReturn', 'Q');
|
$this->__dbDebug(
|
||||||
|
'db',
|
||||||
|
$this->__dbDebugPrepare(
|
||||||
|
$this->cursor_ext[$query_hash]['query'],
|
||||||
|
$this->cursor_ext[$query_hash]['params']
|
||||||
|
),
|
||||||
|
'dbReturn',
|
||||||
|
($this->cursor_ext[$query_hash]['params'] === [] ? 'Q[e]' : 'Qp[e]'),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// internal error handling
|
// internal error handling
|
||||||
$this->__dbError(13, $this->cursor_ext[$query_hash]['cursor']);
|
$this->__dbError(13, $this->cursor_ext[$query_hash]['cursor']);
|
||||||
@@ -2288,10 +2336,6 @@ class IO
|
|||||||
$this->__dbError(17, false, $query);
|
$this->__dbError(17, false, $query);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// checks if the params count given matches the expected count
|
|
||||||
if ($this->__dbCheckQueryParams($query, count($params)) === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$cursor = $this->dbExecParams($query, $params);
|
$cursor = $this->dbExecParams($query, $params);
|
||||||
if ($cursor === false) {
|
if ($cursor === false) {
|
||||||
return false;
|
return false;
|
||||||
@@ -2336,10 +2380,6 @@ class IO
|
|||||||
$this->__dbError(17, false, $query);
|
$this->__dbError(17, false, $query);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// checks if the params count given matches the expected count
|
|
||||||
if ($this->__dbCheckQueryParams($query, count($params)) === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$cursor = $this->dbExecParams($query, $params);
|
$cursor = $this->dbExecParams($query, $params);
|
||||||
if ($cursor === false) {
|
if ($cursor === false) {
|
||||||
return false;
|
return false;
|
||||||
@@ -2588,7 +2628,7 @@ class IO
|
|||||||
$match = [];
|
$match = [];
|
||||||
// search for $1, $2, in the query and push it into the control array
|
// search for $1, $2, in the query and push it into the control array
|
||||||
// skip counts for same eg $1, $1, $2 = 2 and not 3
|
// skip counts for same eg $1, $1, $2 = 2 and not 3
|
||||||
preg_match_all('/(\$[0-9]{1,})/', $query, $match);
|
preg_match_all(self::REGEX_PARAMS, $query, $match);
|
||||||
$this->prepare_cursor[$stm_name]['count'] = count(array_unique($match[1]));
|
$this->prepare_cursor[$stm_name]['count'] = count(array_unique($match[1]));
|
||||||
$this->prepare_cursor[$stm_name]['query'] = $query;
|
$this->prepare_cursor[$stm_name]['query'] = $query;
|
||||||
$result = $this->db_functions->__dbPrepare($stm_name, $query);
|
$result = $this->db_functions->__dbPrepare($stm_name, $query);
|
||||||
@@ -2649,6 +2689,17 @@ class IO
|
|||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if ($this->db_debug) {
|
||||||
|
$this->__dbDebug(
|
||||||
|
'db',
|
||||||
|
$this->__dbDebugPrepare(
|
||||||
|
$this->prepare_cursor[$stm_name]['query'],
|
||||||
|
$data
|
||||||
|
),
|
||||||
|
'dbExecPrep',
|
||||||
|
'Qpe'
|
||||||
|
);
|
||||||
|
}
|
||||||
// if the count does not match
|
// if the count does not match
|
||||||
if ($this->prepare_cursor[$stm_name]['count'] != count($data)) {
|
if ($this->prepare_cursor[$stm_name]['count'] != count($data)) {
|
||||||
$this->__dbError(
|
$this->__dbError(
|
||||||
@@ -2661,17 +2712,6 @@ class IO
|
|||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($this->db_debug) {
|
|
||||||
$this->__dbDebug(
|
|
||||||
'db',
|
|
||||||
$this->__dbDebugPrepare(
|
|
||||||
$this->prepare_cursor[$stm_name]['query'],
|
|
||||||
$data
|
|
||||||
),
|
|
||||||
'dbExecPrep',
|
|
||||||
'Qp'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$result = $this->db_functions->__dbExecute($stm_name, $data);
|
$result = $this->db_functions->__dbExecute($stm_name, $data);
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
$this->log->debug('ExecuteData', 'ERROR in STM[' . $stm_name . '|'
|
$this->log->debug('ExecuteData', 'ERROR in STM[' . $stm_name . '|'
|
||||||
|
|||||||
Reference in New Issue
Block a user