[php-symfony] Support for default scalar value of properties in model (#16605)

* Add support for default scalar value of properties in php-symfony models. Default values now returns in getter-functions

* Revert nullable type-hinting. Move default values from getter to property initialize.
Made changes in __construct:
Now value of properties rewrites only if key exist in $data array.
This commit is contained in:
Artem
2023-10-01 15:32:32 +02:00
committed by GitHub
parent 03781d3a93
commit 039c1698b0
9 changed files with 47 additions and 33 deletions

View File

@@ -93,7 +93,7 @@ class Order
* @Assert\Type("bool")
* @Type("bool")
*/
protected ?bool $complete = null;
protected ?bool $complete = false;
/**
* Constructor
@@ -101,12 +101,14 @@ class Order
*/
public function __construct(array $data = null)
{
$this->id = $data['id'] ?? null;
$this->petId = $data['petId'] ?? null;
$this->quantity = $data['quantity'] ?? null;
$this->shipDate = $data['shipDate'] ?? null;
$this->status = $data['status'] ?? null;
$this->complete = $data['complete'] ?? null;
if (is_array($data)) {
$this->id = array_key_exists('id', $data) ? $data['id'] : $this->id;
$this->petId = array_key_exists('petId', $data) ? $data['petId'] : $this->petId;
$this->quantity = array_key_exists('quantity', $data) ? $data['quantity'] : $this->quantity;
$this->shipDate = array_key_exists('shipDate', $data) ? $data['shipDate'] : $this->shipDate;
$this->status = array_key_exists('status', $data) ? $data['status'] : $this->status;
$this->complete = array_key_exists('complete', $data) ? $data['complete'] : $this->complete;
}
}
/**