Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 71360614d6 | |||
| 670d7a0730 | |||
| b08051ccd3 | |||
| beccbfee1e |
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
composer.json
Normal file → Executable file
0
composer.json
Normal file → Executable file
12
mirzaev/record/system/interfaces/record.php
Normal file → Executable file
12
mirzaev/record/system/interfaces/record.php
Normal file → Executable file
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace mirzaev\record\interfaces;
|
namespace mirzaev\record\interfaces;
|
||||||
|
|
||||||
// Baza database
|
// Baza database
|
||||||
use mirzaev\baza\record as baza;
|
use mirzaev\baza\record as baza_record;
|
||||||
|
|
||||||
// Built-in libraries
|
// Built-in libraries
|
||||||
use InvalidArgumentException as exception_invalid_argument;
|
use InvalidArgumentException as exception_invalid_argument;
|
||||||
@@ -20,7 +20,7 @@ use InvalidArgumentException as exception_invalid_argument;
|
|||||||
* @package mirzaev\record\interfaces
|
* @package mirzaev\record\interfaces
|
||||||
*
|
*
|
||||||
* @method void __construct(record|null $record) Constructor
|
* @method void __construct(record|null $record) Constructor
|
||||||
* @method static|false read(callable $filter) Read from the database
|
* @method static|null read(callable $filter) Read from the database
|
||||||
* @method static|false update() Update the record in 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
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
@@ -33,18 +33,20 @@ interface record
|
|||||||
*
|
*
|
||||||
* @throws exception_invalid_argument If not initialized the database columns parameters
|
* @throws exception_invalid_argument If not initialized the database columns parameters
|
||||||
*
|
*
|
||||||
|
* @param baza_record|null $record The record
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(?baza $record = null);
|
public function __construct(?baza_record $record = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read
|
* Read
|
||||||
*
|
*
|
||||||
* Search for the record in the database
|
* Search for the record in the database
|
||||||
*
|
*
|
||||||
* @return static|false The record impementator object, if found
|
* @return static|null The record implementator object
|
||||||
*/
|
*/
|
||||||
public function read(callable $filter): static|false;
|
public function read(callable $filter): ?static;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update
|
* Update
|
||||||
|
|||||||
29
mirzaev/record/system/traits/record.php
Normal file → Executable file
29
mirzaev/record/system/traits/record.php
Normal file → Executable file
@@ -10,7 +10,8 @@ use svoboda\time\statement as svoboda;
|
|||||||
// Baza database
|
// Baza database
|
||||||
use mirzaev\baza\database,
|
use mirzaev\baza\database,
|
||||||
mirzaev\baza\column,
|
mirzaev\baza\column,
|
||||||
mirzaev\baza\record as baza,
|
mirzaev\baza\record as baza_record,
|
||||||
|
mirzaev\baza\enumerations\encoding,
|
||||||
mirzaev\baza\enumerations\type;
|
mirzaev\baza\enumerations\type;
|
||||||
|
|
||||||
// Built-in libraries
|
// Built-in libraries
|
||||||
@@ -29,7 +30,7 @@ use Exception as exception,
|
|||||||
* @package mirzaev\record\traits
|
* @package mirzaev\record\traits
|
||||||
*
|
*
|
||||||
* @method self __construct(?record $record) Constructor
|
* @method self __construct(?record $record) Constructor
|
||||||
* @method static|false read(callable $filter) Read from the database
|
* @method static|null read(callable $filter) Read from the database
|
||||||
* @method static|false update() Update the record in 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 void __set(string $name, mixed $value = null) Write into the database record property
|
||||||
* @method mixed __get(string $name) Read from the database record property
|
* @method mixed __get(string $name) Read from the database record property
|
||||||
@@ -43,18 +44,18 @@ trait record
|
|||||||
/**
|
/**
|
||||||
* Record
|
* Record
|
||||||
*
|
*
|
||||||
* @var baza $record The record instance
|
* @var baza_record $record The record instance
|
||||||
*/
|
*/
|
||||||
protected baza $record;
|
protected baza_record $record;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @method record|null $record The record
|
* @method baza_record|null $record The record
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(?record $record = null)
|
public function __construct(?baza_record $record = null)
|
||||||
{
|
{
|
||||||
// Initializing the database
|
// Initializing the database
|
||||||
/* $this->database = new database()
|
/* $this->database = new database()
|
||||||
@@ -67,7 +68,7 @@ trait record
|
|||||||
->connect($this->file); */
|
->connect($this->file); */
|
||||||
|
|
||||||
// Initializing the record
|
// Initializing the record
|
||||||
$record instanceof record and $this->record = $record;
|
$record instanceof baza_record and $this->record = $record;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,9 +76,9 @@ trait record
|
|||||||
*
|
*
|
||||||
* Search for the record in the database
|
* Search for the record in the database
|
||||||
*
|
*
|
||||||
* @return static|false The record impementator object, if found
|
* @return static|null The record implementator object
|
||||||
*/
|
*/
|
||||||
public function read(callable $filter): static|false
|
public function read(callable $filter): ?static
|
||||||
{
|
{
|
||||||
// Reading from the database
|
// Reading from the database
|
||||||
$record = $this->database->read(
|
$record = $this->database->read(
|
||||||
@@ -86,7 +87,7 @@ trait record
|
|||||||
offset: 0
|
offset: 0
|
||||||
)[0] ?? false;
|
)[0] ?? false;
|
||||||
|
|
||||||
if ($record instanceof baza) {
|
if ($record instanceof baza_record) {
|
||||||
// Initialized the record
|
// Initialized the record
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
@@ -94,7 +95,7 @@ trait record
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Exit (fail)
|
// Exit (fail)
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,8 +109,8 @@ trait record
|
|||||||
{
|
{
|
||||||
// Writing into the database
|
// Writing into the database
|
||||||
$record = $this->database->read(
|
$record = $this->database->read(
|
||||||
filter: fn(baza $record) => $record->identifier === $this->record->identifier,
|
filter: fn(baza_record $record) => $record->identifier === $this->record->identifier,
|
||||||
update: function (baza &$record) {
|
update: function (baza_record &$record) {
|
||||||
$this->record->updated = svoboda::timestamp();
|
$this->record->updated = svoboda::timestamp();
|
||||||
$record = $this->record;
|
$record = $this->record;
|
||||||
},
|
},
|
||||||
@@ -117,7 +118,7 @@ trait record
|
|||||||
offset: 0
|
offset: 0
|
||||||
)[0] ?? false;
|
)[0] ?? false;
|
||||||
|
|
||||||
if ($record instanceof record) {
|
if ($record instanceof baza_record) {
|
||||||
// Initialized the record
|
// Initialized the record
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
|
|||||||
Reference in New Issue
Block a user