class UserPropertyCollection extends AbstractPropertyCollection
{
public function __construct(string $mode)
{
$this->addProperty(new StringProperty('id', 'User UUID'));
$this->addProperty(new StringProperty('email', 'User email address'));
}
}
class UserObject extends AbstractObjectProperty
{
private string $id;
private string $email;
/**
* Defines the object's schema name and description.
*
* Important:
* - Always required.
* - Do not hydrate runtime values here.
* - Documentation is built without needing a populated instance.
*/
public function __construct()
{
parent::__construct('user', 'User details');
}
public function getPropertyCollection(): AbstractPropertyCollection
{
return new UserPropertyCollection(AbstractPropertyCollection::MODE_VIEW);
}
/**
* Optional runtime population.
*
* Populate the object only when you want to use the instance as an
* actual data container at runtime.
*/
public function populate(string $id, string $email): void
{
$this->id = $id;
$this->email = $email;
}
/** Populated response data. This is called when you use the object as a response object in response documentation - and that is converted to array. */
public function toArray(): array
{
return [
'id' => $this->id,
'email' => $this->email,
];
}
}