Bicycle/Services/DataBase/Model.php
Egor Isaev 9d4edf147a dev
2026-08-07 11:40:03 +03:00

59 lines
1.6 KiB
PHP
Raw Permalink 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
/**
* @package Bicycle
* @author Egor Isaev
* @description Model.php
* @copyright (c) 07/08/2026
*/
namespace Services\DataBase;
use AllowDynamicProperties;
/**
* Лёгкий пассивный носитель данных одной строки — не ActiveRecord: чтение/запись
* в БД делает Repository. Свойства настоящие (не спрятаны за внутренним массивом),
* потому что PDO::FETCH_CLASS/fetchObject() выставляет их напрямую, минуя __set()
* (это внутренний механизм PDO, работает до вызова конструктора) — #[AllowDynamicProperties]
* нужен, чтобы это не ловило deprecation в PHP 8.2+.
*/
#[AllowDynamicProperties]
class Model
{
/**
* @param string $name Имя свойства
* @param mixed $value Значение
* @return void
*/
public function __set(string $name, mixed $value): void
{
$this->$name = $value;
}
/**
* @param string $name Имя свойства
* @return mixed null, если свойства нет
*/
public function __get(string $name): mixed
{
return $this->$name ?? null;
}
/**
* @param string $name Имя свойства
* @return bool
*/
public function __isset(string $name): bool
{
return isset($this->$name);
}
/**
* @return array<string,mixed> Все свойства
*/
public function toArray(): array
{
return (array) $this;
}
}