A small lib to transfer from one application layer to another.
Valinor and Laravel-Data ain't focussing on a DTO core principle. Data Entities has some convenient methods included.
composer require sinema/data-entities
use Sinemah\DataEntities\Data;
class Message extends Data
{
public string $text;
public string $user;
public int $created_at;
}
use Sinemah\DataEntities\Data;
use Sinemah\DataEntities\Entity\Requireable;
class Message extends Data
{
use Requireable;
protected array $requireable = [
'text',
'user',
'created_at',
];
public string $text;
public string $user;
public int $created_at;
}
$message = Message::from(['user' => 'John Smith', 'text' => 'Lorem Ipsum']);
$message->toArray();
Also works neither attributes are not initialized nor exists.
$message->get('user');