mirror of
https://codeberg.org/vlw/scaffold.git
synced 2025-11-05 06:02:42 +01:00
Compare commits
No commits in common. "master" and "1.3.0" have entirely different histories.
2 changed files with 39 additions and 45 deletions
|
|
@ -55,7 +55,7 @@
|
|||
|
||||
$this->_resolved = true;
|
||||
$this->_row = $this->db
|
||||
->from($this->table)
|
||||
->for($this->table)
|
||||
->where($this->where)
|
||||
->limit(1)
|
||||
->select($this->columns)
|
||||
|
|
@ -72,13 +72,14 @@
|
|||
*
|
||||
* @return bool Entity exists
|
||||
*/
|
||||
public function isset(): bool {
|
||||
return $this->_isset ??= new Database()
|
||||
->from($this->table)
|
||||
->where($this->where)
|
||||
->limit(1)
|
||||
->select()
|
||||
->num_rows === 1;
|
||||
public bool $isset {
|
||||
// Returns bool if row is set or attempts to resolve and set if null
|
||||
get => $this->_isset ??= new Database()
|
||||
->for($this->table)
|
||||
->where($this->where)
|
||||
->limit(1)
|
||||
->select()
|
||||
->num_rows === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -102,7 +103,7 @@
|
|||
$this->_row[$key] = $value;
|
||||
|
||||
return $this->db
|
||||
->from($this->table)
|
||||
->for($this->table)
|
||||
->where($this->where)
|
||||
->update([$key => $value]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,41 +3,34 @@
|
|||
namespace vlw\Scaffold\Helpers;
|
||||
|
||||
/**
|
||||
* Generate Universally unique identifiers
|
||||
* Generate an all binary 0:s UUID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
class UUID {
|
||||
public const LENGTH = 36;
|
||||
|
||||
/**
|
||||
* Generate an all binary 0:s UUID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function nil(): string {
|
||||
return "00000000-0000-0000-0000-000000000000";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an all binary 1:s UUID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function max(): string {
|
||||
return "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a version 4 UUID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function v4(): string {
|
||||
return sprintf("%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0x0fff) | 0x4000,
|
||||
mt_rand(0, 0x3fff) | 0x8000,
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||||
);
|
||||
}
|
||||
function uuid_nil(): string {
|
||||
return "00000000-0000-0000-0000-000000000000";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an all binary 1:s UUID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function uuid_max(): string {
|
||||
return "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a version 4 UUID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function uuid_v4(): string {
|
||||
return sprintf("%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0x0fff) | 0x4000,
|
||||
mt_rand(0, 0x3fff) | 0x8000,
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue