Move uniqid creation methods from Hash to Uids class
uniq id short and long without parametersare pure uid creations so they have moved over and have been deprecated in the Hash class. Update Logging class for this. Update Form\Generate for cursor ext access
This commit is contained in:
@@ -68,8 +68,8 @@ print "<br>CURRENT STANDARD_HASH_LONG: " . Hash::STANDARD_HASH_LONG . "<br>";
|
||||
print "HASH SHORT: " . $to_crc . ": " . Hash::__hash($to_crc) . "<br>";
|
||||
print "HASH LONG: " . $to_crc . ": " . Hash::__hashLong($to_crc) . "<br>";
|
||||
|
||||
print "UNIQU ID SHORT : " . Hash::__uniqId() . "<br>";
|
||||
print "UNIQU ID LONG : " . Hash::__uniqIdLong() . "<br>";
|
||||
// print "UNIQU ID SHORT : " . Hash::__uniqId() . "<br>";
|
||||
// print "UNIQU ID LONG : " . Hash::__uniqIdLong() . "<br>";
|
||||
|
||||
// DEPRECATED
|
||||
/* print "D/__CRC32B: $to_crc: ".$basic->__crc32b($to_crc)."<br>";
|
||||
|
||||
@@ -91,10 +91,13 @@ class Hash
|
||||
* create a unique id with the standard hash type defined in __hash
|
||||
*
|
||||
* @return string Unique ID with fixed length of 8 characters
|
||||
* @deprecated Use \CoreLibs\Create\Uids::uniqIdShort() instead
|
||||
*/
|
||||
public static function __uniqId(): string
|
||||
{
|
||||
return self::__hash(uniqid((string)rand(), true));
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, '
|
||||
. '\CoreLibs\Create\Uids::uniqIdShort() class', E_USER_DEPRECATED);
|
||||
return \CoreLibs\Create\Uids::uniqIdShort();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,10 +105,13 @@ class Hash
|
||||
* defined in __hashLong
|
||||
*
|
||||
* @return string Unique ID with length of current default long hash
|
||||
* @deprecated Use \CoreLibs\Create\Uids::uniqIdLong() instead
|
||||
*/
|
||||
public static function __uniqIdLong(): string
|
||||
{
|
||||
return self::__hashLong(uniqid((string)rand(), true));
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, '
|
||||
. '\CoreLibs\Create\Uids::uniqIdLong() class', E_USER_DEPRECATED);
|
||||
return \CoreLibs\Create\Uids::uniqIdLong();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ namespace CoreLibs\Create;
|
||||
class Uids
|
||||
{
|
||||
// what to use as a default hash if non ise set and no DEFAULT_HASH is defined
|
||||
public const FALLBACK_HASH = 'sha256';
|
||||
public const DEFAULT_HASH = 'sha256';
|
||||
public const STANDARD_HASH_LONG = 'ripemd160';
|
||||
public const STANDARD_HASH_SHORT = 'adler32';
|
||||
|
||||
/**
|
||||
* creates psuedo random uuid v4
|
||||
@@ -53,23 +55,52 @@ class Uids
|
||||
case 'md5':
|
||||
$uniq_id = md5(uniqid((string)rand(), true));
|
||||
break;
|
||||
case 'sha256':
|
||||
$uniq_id = hash('sha256', uniqid((string)rand(), true));
|
||||
case self::DEFAULT_HASH:
|
||||
$uniq_id = hash(self::DEFAULT_HASH, uniqid((string)rand(), true));
|
||||
break;
|
||||
case 'ripemd160':
|
||||
$uniq_id = hash('ripemd160', uniqid((string)rand(), true));
|
||||
case self::STANDARD_HASH_LONG:
|
||||
$uniq_id = hash(self::STANDARD_HASH_LONG, uniqid((string)rand(), true));
|
||||
break;
|
||||
case 'adler32':
|
||||
$uniq_id = hash('adler32', uniqid((string)rand(), true));
|
||||
case self::STANDARD_HASH_SHORT:
|
||||
$uniq_id = hash(self::STANDARD_HASH_SHORT, uniqid((string)rand(), true));
|
||||
break;
|
||||
default:
|
||||
// fallback to this hash type
|
||||
$hash = self::FALLBACK_HASH;
|
||||
// if not empty, check if in valid list
|
||||
if (
|
||||
!empty($type) &&
|
||||
in_array($type, hash_algos())
|
||||
) {
|
||||
$hash = $type;
|
||||
} else {
|
||||
// fallback to default hash type if none set or invalid
|
||||
$hash = self::DEFAULT_HASH;
|
||||
}
|
||||
$uniq_id = hash($hash, uniqid((string)rand(), true));
|
||||
break;
|
||||
}
|
||||
return $uniq_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* create a unique id with the standard hash type defined in __hash
|
||||
*
|
||||
* @return string Unique ID with fixed length of 8 characters
|
||||
*/
|
||||
public static function uniqIdShort(): string
|
||||
{
|
||||
return self::uniqId(self::STANDARD_HASH_SHORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* create a unique id with the standard long hash type
|
||||
* defined in __hashLong
|
||||
*
|
||||
* @return string Unique ID with length of current default long hash
|
||||
*/
|
||||
public static function uniqIdLong(): string
|
||||
{
|
||||
return self::uniqId(self::STANDARD_HASH_LONG);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -25,7 +25,7 @@ declare(strict_types=1);
|
||||
namespace CoreLibs\Debug;
|
||||
|
||||
use CoreLibs\Debug\Support;
|
||||
use CoreLibs\Create\Hash;
|
||||
use CoreLibs\Create\Uids;
|
||||
use CoreLibs\Get\System;
|
||||
use CoreLibs\Convert\Html;
|
||||
|
||||
@@ -161,7 +161,7 @@ class Logging
|
||||
// running time start for script
|
||||
$this->script_starttime = microtime(true);
|
||||
// set per run UID for logging
|
||||
$this->running_uid = Hash::__uniqId();
|
||||
$this->running_uid = Uids::uniqIdShort();
|
||||
// set the page name
|
||||
$this->page_name = System::getPageName();
|
||||
// set host name
|
||||
|
||||
@@ -2246,17 +2246,17 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
// if drop down db read data for element list from the given sub table as from the query
|
||||
// only two elements are allowed: pos 0 is key, pso 1 is visible output name
|
||||
if (isset($data_array['type']) && $data_array['type'] == 'drop_down_db') {
|
||||
$md_q = md5($data_array['query']);
|
||||
while (is_array($res = $this->dbReturn($data_array['query']))) {
|
||||
/** @phan-suppress-next-line PhanTypeInvalidDimOffset */
|
||||
$this->log->debug('edit', 'Q[' . $md_q . '] pos: ' . $this->cursor_ext[$md_q]['pos']
|
||||
$this->log->debug('edit', 'Q[' . $this->dbGetQueryHash($data_array['query']) . '] pos: '
|
||||
. $this->dbGetCursorExt($data_array['query'], 'pos')
|
||||
. ' | want: ' . ($data_array['preset'] ?? '-')
|
||||
. ' | set: ' . ($data['preset'][$el_name] ?? '-'));
|
||||
// first is default for this element
|
||||
if (
|
||||
isset($data_array['preset']) &&
|
||||
(!isset($data['preset'][$el_name]) || empty($data['preset'][$el_name])) &&
|
||||
($this->cursor_ext[$md_q]['pos'] == $data_array['preset'])
|
||||
($this->dbGetCursorExt($data_array['query'], 'pos') == $data_array['preset'])
|
||||
) {
|
||||
$data['preset'][$el_name] = $res[0];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user