1 Commits

Author SHA1 Message Date
1ad13ddd3f __construct(?record $record) 2025-11-16 12:59:13 +03:00
6 changed files with 19 additions and 22 deletions

0
.gitignore vendored Executable file → Normal file
View File

0
LICENSE Executable file → Normal file
View File

0
README.md Executable file → Normal file
View File

0
composer.json Executable file → Normal file
View File

12
mirzaev/record/system/interfaces/record.php Executable file → Normal file
View File

@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace mirzaev\record\interfaces;
// Baza database
use mirzaev\baza\record as baza_record;
use mirzaev\baza\record as baza;
// Built-in libraries
use InvalidArgumentException as exception_invalid_argument;
@@ -20,7 +20,7 @@ use InvalidArgumentException as exception_invalid_argument;
* @package mirzaev\record\interfaces
*
* @method void __construct(record|null $record) Constructor
* @method static|null read(callable $filter) Read from the database
* @method static|false read(callable $filter) Read from the database
* @method static|false update() Update the record in the database
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
@@ -33,20 +33,18 @@ interface record
*
* @throws exception_invalid_argument If not initialized the database columns parameters
*
* @param baza_record|null $record The record
*
* @return void
*/
public function __construct(?baza_record $record = null);
public function __construct(?baza $record = null);
/**
* Read
*
* Search for the record in the database
*
* @return static|null The record implementator object
* @return static|false The record impementator object, if found
*/
public function read(callable $filter): ?static;
public function read(callable $filter): static|false;
/**
* Update

29
mirzaev/record/system/traits/record.php Executable file → Normal file
View File

@@ -10,8 +10,7 @@ use svoboda\time\statement as svoboda;
// Baza database
use mirzaev\baza\database,
mirzaev\baza\column,
mirzaev\baza\record as baza_record,
mirzaev\baza\enumerations\encoding,
mirzaev\baza\record as baza,
mirzaev\baza\enumerations\type;
// Built-in libraries
@@ -30,7 +29,7 @@ use Exception as exception,
* @package mirzaev\record\traits
*
* @method self __construct(?record $record) Constructor
* @method static|null read(callable $filter) Read from the database
* @method static|false read(callable $filter) Read from the database
* @method static|false update() Update the record in the database
* @method void __set(string $name, mixed $value = null) Write into the database record property
* @method mixed __get(string $name) Read from the database record property
@@ -44,18 +43,18 @@ trait record
/**
* Record
*
* @var baza_record $record The record instance
* @var baza $record The record instance
*/
protected baza_record $record;
protected baza $record;
/**
* Constructor
*
* @method baza_record|null $record The record
* @method record|null $record The record
*
* @return void
*/
public function __construct(?baza_record $record = null)
public function __construct(?record $record = null)
{
// Initializing the database
/* $this->database = new database()
@@ -68,7 +67,7 @@ trait record
->connect($this->file); */
// Initializing the record
$record instanceof baza_record and $this->record = $record;
$record instanceof record and $this->record = $record;
}
/**
@@ -76,9 +75,9 @@ trait record
*
* Search for the record in the database
*
* @return static|null The record implementator object
* @return static|false The record impementator object, if found
*/
public function read(callable $filter): ?static
public function read(callable $filter): static|false
{
// Reading from the database
$record = $this->database->read(
@@ -87,7 +86,7 @@ trait record
offset: 0
)[0] ?? false;
if ($record instanceof baza_record) {
if ($record instanceof baza) {
// Initialized the record
// Exit (success)
@@ -95,7 +94,7 @@ trait record
}
// Exit (fail)
return null;
return false;
}
/**
@@ -109,8 +108,8 @@ trait record
{
// Writing into the database
$record = $this->database->read(
filter: fn(baza_record $record) => $record->identifier === $this->record->identifier,
update: function (baza_record &$record) {
filter: fn(baza $record) => $record->identifier === $this->record->identifier,
update: function (baza &$record) {
$this->record->updated = svoboda::timestamp();
$record = $this->record;
},
@@ -118,7 +117,7 @@ trait record
offset: 0
)[0] ?? false;
if ($record instanceof baza_record) {
if ($record instanceof record) {
// Initialized the record
// Exit (success)