Answer the question
In order to leave comments, you need to log in
Does it make sense to use constructors in DTO?
An example of a simple DTO
class UpdateUser extends AbstractRequestEntityDTO {
public ?string $authToken;
public ?string $email;
public ?string $description;
public ?string $fallbackEmail;
public ?string $slug;
public ?string $nickname;
public ?string $countryAlpha2;
public ?string $languageAlpha2;
public ?string $languageNativeName;
public ?string $countryNativeName;
public function __construct(
?string $email = null,
?string $nickname = null,
?string $slug = null,
?string $fallbackEmail = null,
?string $countryAlpha2 = null,
?string $languageAlpha2 = null
) {
$this->nickname = $nickname;
$this->email = $email;
$this->fallbackEmail = $fallbackEmail;
$this->slug = $slug;
$this->countryAlpha2 = $countryAlpha2;
$this->languageAlpha2 = $languageAlpha2;
}
new UpdateUser (null,null,null,null,null,null,'newNickname');
UpdateUser::fromRequest($request)
(new UpdateUser)->setNickname($request->request->get('nickname'))->setOtherFields();
Answer the question
In order to leave comments, you need to log in
and nothing it will be like this
new UpdateUser(nickname: 'newNickname');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question