Answer the question
In order to leave comments, you need to log in
What pattern is needed here?
An object is created based on some data, and in the process, it is possible that a certain property should receive the value of a new instance of the same
type class
class Detail {
function create($data) {
......
$this->nestedDatail = new Detail()->create( $data->nestedDetailData );
return $this;
}
}
Answer the question
In order to leave comments, you need to log in
Is a patch needed here? Perhaps it would be worth describing the shortcomings of what is, Wishlist, and ask how to achieve this.
Your class is very similar to a business logic object (domain entity).
It is preferable to use a constructor when creating an object and setting values (entity must always be valid) and try to get rid of dependency injection through a constructor, like this:
public function updatePassword($plainPassword, PasswordEncoderInterface $encoder) {
$this->password = $this->encoder->encode($plainPassword);
}
public static function create($userName, $email) {
$user = new self();
$user->username = $username;
// ...
return $user;
}
public static function createFromMyVariant($uid) {
$user = new self();
// ...
return $user;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question