Files
oficial/app/src/Model/Persona.php

68 lines
1.8 KiB
PHP
Raw Normal View History

2024-06-18 22:41:03 -04:00
<?php
namespace Incoviba\Model;
2025-08-12 19:17:32 -04:00
use Incoviba\Common\Implement\Exception\EmptyResult;
2025-05-07 19:24:33 -04:00
use InvalidArgumentException;
2024-06-18 22:41:03 -04:00
use Incoviba\Common\Ideal;
2024-12-03 16:45:20 -03:00
use Incoviba\Model\Persona\Datos;
2024-06-18 22:41:03 -04:00
class Persona extends Ideal\Model
{
public int $rut;
public string $digito;
public string $nombres;
public string $apellidoPaterno;
public string $apellidoMaterno;
public function nombreCompleto(): string
{
return $this->nombres . ' ' . $this->apellidoPaterno . ' ' . $this->apellidoMaterno;
}
public function rutCompleto(): string
{
return number_format($this->rut, 0, ',', '.') . '-' . $this->digito;
}
2024-12-03 16:45:20 -03:00
protected ?Datos $datos;
public function datos(): ?Datos
2024-06-18 22:41:03 -04:00
{
if (!isset($this->datos)) {
2025-08-12 19:17:32 -04:00
try {
$this->datos = $this->runFactory('datos');
} catch (EmptyResult) {
$this->datos = null;
}
2024-06-18 22:41:03 -04:00
}
return $this->datos;
}
2025-05-07 19:24:33 -04:00
public function __get(string $name): mixed
{
if ($name === 'datos') {
return $this->datos();
}
if ($name === 'dv') {
return $this->digito;
}
2025-09-09 16:24:48 -03:00
if (property_exists($this, $name)) {
return $this->{$name};
}
2025-05-07 19:24:33 -04:00
throw new InvalidArgumentException("Property {$name} is not found in " . __CLASS__);
}
2024-06-18 22:41:03 -04:00
public function jsonSerialize(): mixed
{
return [
'rut' => $this->rut,
'digito' => $this->digito,
'nombres' => $this->nombres,
'apellidoPaterno' => $this->apellidoPaterno,
'apellidoMaterno' => $this->apellidoMaterno,
'nombreCompleto' => $this->nombreCompleto(),
'rutCompleto' => $this->rutCompleto(),
2024-12-03 16:45:20 -03:00
'datos' => $this->datos() ?? null,
2024-06-18 22:41:03 -04:00
];
}
}