Compare commits

...

4 commits

Author SHA1 Message Date
4fa45083d0 feat: expose UUID helper as a class of static methods (#10)
Let's expose the uuid helpers as a class of static methods instead. I'm not sure if this approach is actually better but we're going to live with it for a while. I have done UUID helpers before this library as a class. So let's run with it again.

Reviewed-on: https://codeberg.org/vlw/scaffold/pulls/10
2025-11-02 09:50:03 +01:00
00337cd3aa refactor: replace the Model->isset property with a public instance method (#9)
This change is primarily to accommodate the new `Reflect::serialize()` method since we don't want to include the isset property when returning serialized objects.

Reviewed-on: https://codeberg.org/vlw/scaffold/pulls/9
2025-11-01 18:34:48 +01:00
feea36b190 feat: add UUID string length constant (#8)
Reviewed-on: https://codeberg.org/vlw/scaffold/pulls/8
2025-11-01 16:48:38 +01:00
b1bdf628f2 refactor: replace for() with from() in database Model (#7)
This PR replaces the `vlw\MySQL->for()` with `vlw\MySQL->from()` since for() it's deprecated.

Reviewed-on: https://codeberg.org/vlw/scaffold/pulls/7
2025-11-01 16:37:26 +01:00
2 changed files with 43 additions and 37 deletions

View file

@ -55,7 +55,7 @@
$this->_resolved = true;
$this->_row = $this->db
->for($this->table)
->from($this->table)
->where($this->where)
->limit(1)
->select($this->columns)
@ -72,10 +72,9 @@
*
* @return bool Entity exists
*/
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)
public function isset(): bool {
return $this->_isset ??= new Database()
->from($this->table)
->where($this->where)
->limit(1)
->select()
@ -103,7 +102,7 @@
$this->_row[$key] = $value;
return $this->db
->for($this->table)
->from($this->table)
->where($this->where)
->update([$key => $value]);
}

View file

@ -2,12 +2,18 @@
namespace vlw\Scaffold\Helpers;
/**
* Generate Universally unique identifiers
*/
class UUID {
public const LENGTH = 36;
/**
* Generate an all binary 0:s UUID
*
* @return string
*/
function uuid_nil(): string {
public static function nil(): string {
return "00000000-0000-0000-0000-000000000000";
}
@ -16,7 +22,7 @@
*
* @return string
*/
function uuid_max(): string {
public static function max(): string {
return "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF";
}
@ -25,7 +31,7 @@
*
* @return string
*/
function uuid_v4(): 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),
@ -34,3 +40,4 @@
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
}