Object Constructors from compiler
luisgon1 opened this issue · 4 comments
luisgon1 commented
Can the compiler generate a constructor for the proto messages with the required params?
FabioBatSilva commented
The constructor already receive the payload and is used to parse messages.
Another option would be to provide a create
method, something like :
message MyMessage
{
required string foo = 1;
}
<?php
$message = MyMessage:create([
'foo' => 'bar'
]);
// throws InvalidArgumentException
$message = MyMessage:create([
]);
luisgon1 commented
A create method would help.
We would have less code and it would be cleaner.
FabioBatSilva commented
Now you should be able to use fromArray
<?php
$person = Person::fromArray([
'id' => 1234,
'name' => 'Fabio',
'phone' => [
PhoneNumber::fromArray([
'number' => '123123123',
'type' => PhoneType::HOME()
]),
PhoneNumber::fromArray([
'number' => '321321321',
'type' => PhoneType::MOBILE()
])
]
]);
luisgon1 commented
Perfect,
Thank You