<?php
declare(strict_types = 1);
namespace TypeSchema\DTO;
use PSX\Schema\Attribute\Description;
#[Description('A simple student struct')]
class Student implements \JsonSerializable, \PSX\Record\RecordableInterface
{
protected ?string $firstName = null;
protected ?string $lastName = null;
protected ?int $age = null;
public function setFirstName(?string $firstName) : void
{
$this->firstName = $firstName;
}
public function getFirstName() : ?string
{
return $this->firstName;
}
public function setLastName(?string $lastName) : void
{
$this->lastName = $lastName;
}
public function getLastName() : ?string
{
return $this->lastName;
}
public function setAge(?int $age) : void
{
$this->age = $age;
}
public function getAge() : ?int
{
return $this->age;
}
public function toRecord() : \PSX\Record\RecordInterface
{
/** @var \PSX\Record\Record<mixed> $record */
$record = new \PSX\Record\Record();
$record->put('firstName', $this->firstName);
$record->put('lastName', $this->lastName);
$record->put('age', $this->age);
return $record;
}
public function jsonSerialize() : object
{
return (object) $this->toRecord()->getAll();
}
}