2023-07-24 20:55:26 -04:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Common\Ideal;
|
|
|
|
|
|
|
|
use Incoviba\Common\Define;
|
|
|
|
|
|
|
|
abstract class Model implements Define\Model
|
|
|
|
{
|
|
|
|
public int $id;
|
|
|
|
|
2023-08-08 23:53:49 -04:00
|
|
|
protected array $factories;
|
|
|
|
|
|
|
|
public function addFactory(string $property, Define\Repository\Factory $factory): Model
|
|
|
|
{
|
|
|
|
$this->factories[$property] = $factory;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function runFactory(string $property): mixed
|
|
|
|
{
|
2023-09-13 18:51:46 -03:00
|
|
|
if (isset($this->factories[$property])) {
|
|
|
|
return $this->factories[$property]->run();
|
|
|
|
}
|
|
|
|
return null;
|
2023-08-08 23:53:49 -04:00
|
|
|
}
|
|
|
|
|
2023-07-24 20:55:26 -04:00
|
|
|
public function jsonSerialize(): mixed
|
|
|
|
{
|
|
|
|
return [
|
2025-03-04 11:53:14 -03:00
|
|
|
'id' => $this->id,
|
|
|
|
...$this->jsonComplement()
|
2023-07-24 20:55:26 -04:00
|
|
|
];
|
|
|
|
}
|
2025-03-04 11:53:14 -03:00
|
|
|
|
|
|
|
protected function jsonComplement(): array
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2023-07-24 20:55:26 -04:00
|
|
|
}
|