Files
php_db_components_pack/tests/data/UserModel.php
2025-08-20 18:09:37 +03:00

157 lines
7.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace goodboyalex\php_db_components_pack\tests\data;
use goodboyalex\php_components_pack\types\GUID;
use goodboyalex\php_db_components_pack\attributes\Compare;
use goodboyalex\php_db_components_pack\attributes\ConvertToDB;
use goodboyalex\php_db_components_pack\attributes\DataType;
use goodboyalex\php_db_components_pack\attributes\DefaultValue;
use goodboyalex\php_db_components_pack\attributes\FieldName;
use goodboyalex\php_db_components_pack\attributes\NotNull;
use goodboyalex\php_db_components_pack\attributes\PrimaryKey;
use goodboyalex\php_db_components_pack\enums\DBType;
use goodboyalex\php_db_components_pack\interfaces\IDBItem;
/**
* Модель информации о пользователе.
*
* Структура таблицы:
*
* -- id - string(36) - Уникальный идентификатор пользователя (индекс).
* -- login - varchar(50) - Имя пользователя.
* -- password - varchar(255) - Пароль пользователя.
* -- salt - varchar(36) - Ключ шифровки пароля.
* -- first_name - varchar(50) - Имя пользователя.
* -- middle_name - varchar(50) - Отчество пользователя.
* -- last_name - varchar(50) - Фамилия пользователя.
* -- email - varchar(100) - Электронная почта пользователя.
* -- email_verified - TinyInt - Статус подтверждения электронной почты.
* -- group - varchar(50) - Имя группы пользователя.
* -- date_created - bigint - Временной штамп даты создания пользователя.
* -- date_updated - bigint - Временной штамп даты обновления пользователя.
* -- data - LONGTEXT - NULL - Массив разных данных о пользователе.
*
* @author Александр Бабаев
* @package php_db_components_pack
* @version 1.0
* @since 1.0.2
*/
final class UserModel implements IDBItem
{
/**
* @var GUID $Id Идентификатор пользователя
*/
#[PrimaryKey, NotNull, DataType(DBType::STRING, 36), ConvertToDB(
fromType: ['\goodboyalex\php_db_components_pack\tests\data\Converters', 'GUIDToString'],
toType: [
'\goodboyalex\php_db_components_pack\tests\data\Converters', 'GUIDFromString'
]), Compare(['\goodboyalex\php_db_components_pack\tests\data\Converters', 'IsGUIDEqual']),
FieldName('id'), DefaultValue(GUID_EMPTY)]
public GUID $Id;
/**
* @var string $Login Логин пользователя (на английском языке)
*/
#[NotNull, FieldName('login'), DataType(DBType::STRING, 50), DefaultValue("")]
public string $Login = "";
/**
* @var string $Password Пароль пользователя
*/
#[NotNull, FieldName('password'), DataType(DBType::STRING, 255), DefaultValue("")]
public string $Password = '';
/**
* @var string $Salt Кодовое слово для пароля (обычно Guid)
*/
#[NotNull, FieldName('salt'), DataType(DBType::STRING, 36), DefaultValue(GUID_EMPTY)]
public string $Salt = '';
/**
* @var string $FirstName Имя пользователя
*/
#[NotNull, FieldName('first_name'), DataType(DBType::STRING, 50), DefaultValue("")]
public string $FirstName = "";
/**
* @var string $MiddleName Отчество пользователя
*/
#[NotNull, FieldName('middle_name'), DataType(DBType::STRING, 50), DefaultValue("")]
public string $MiddleName = "";
/**
* @var string $LastName Фамилия пользователя
*/
#[NotNull, FieldName('last_name'), DataType(DBType::STRING, 50), DefaultValue("")]
public string $LastName = "";
/**
* @var string $Email Электронная почта пользователя
*/
#[NotNull, FieldName('email'), DataType(DBType::STRING, 100), DefaultValue("")]
public string $Email = "";
/**
* @var bool $IsEmailVerified Статус подтверждения электронной почты
*/
#[NotNull, FieldName('email_verified'), DataType(DBType::INT), ConvertToDB(
fromType: ['\goodboyalex\php_db_components_pack\tests\data\Converters', 'BoolToInt'],
toType: ['\goodboyalex\php_db_components_pack\tests\data\Converters', 'BoolFromInt']),
Compare([
'\goodboyalex\php_db_components_pack\tests\data\Converters', 'IsBoolEqual'
]), DefaultValue(0)]
public bool $IsEmailVerified = false;
/**
* @var string $GroupName Имя группы пользователя
*/
#[NotNull, FieldName('group'), DataType(DBType::STRING, 50), DefaultValue('')]
public string $GroupName = '';
/**
* @var int $CreatedAt Штамп даты создания пользователя
*/
#[NotNull, FieldName('date_created'), DataType(DBType::INT), DefaultValue(0)]
public int $CreatedAt = 0;
/**
* @var int $ModifiedAt Штамп даты изменения пользователя
*/
#[NotNull, FieldName('date_updated'), DataType(DBType::INT), DefaultValue(0)]
public int $ModifiedAt = 0;
/**
* @var array $UserData Массив разных данных о пользователе
*/
#[NotNull, FieldName('data'), DataType(DBType::STRING, 0), ConvertToDB(
fromType: ['\goodboyalex\php_db_components_pack\tests\data\Converters', 'ArrayToString'],
toType: ['\goodboyalex\php_db_components_pack\tests\data\Converters', 'ArrayFromString']),
Compare([
'\goodboyalex\php_db_components_pack\tests\data\Converters', 'IsArrayEqual'
]), DefaultValue("[]")]
public array $UserData = [];
/**
* Конструктор.
*/
public function __construct (GUID $id = new GUID(), string $login = "", string $password = "",
string $salt = "", string $firstName = "", string $middleName = "", string $lastName = "",
string $email = "", bool $isEmailVerified = false, string $groupName = "", int $createdAt = 0,
int $updatedAt = 0, array $userData = [])
{
$this->Id = $id;
$this->Login = $login;
$this->Password = $password;
$this->Salt = $salt;
$this->FirstName = $firstName;
$this->MiddleName = $middleName;
$this->LastName = $lastName;
$this->Email = $email;
$this->IsEmailVerified = $isEmailVerified;
$this->GroupName = $groupName;
$this->CreatedAt = $createdAt;
$this->ModifiedAt = $updatedAt;
$this->UserData = $userData;
}
}