fix serialization of converter classes #189
This commit is contained in:
parent
9b9a20b437
commit
0700c96901
@ -12,10 +12,8 @@ class Flight extends Resource
|
|||||||
$flight = parent::toArray($request);
|
$flight = parent::toArray($request);
|
||||||
|
|
||||||
// Return multiple measures so the client can pick what they want
|
// Return multiple measures so the client can pick what they want
|
||||||
if(\in_array('distance', $flight, true)
|
if(filled($this->distance) && $this->distance instanceof Distance) {
|
||||||
&& $flight['distance'] instanceof Distance)
|
$flight['distance'] = $this->distance->toObject();
|
||||||
{
|
|
||||||
$flight['distance'] = $flight['distance']->toObject();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$flight['airline'] = new Airline($this->airline);
|
$flight['airline'] = new Airline($this->airline);
|
||||||
|
@ -17,16 +17,12 @@ class Pirep extends Resource
|
|||||||
{
|
{
|
||||||
$pirep = parent::toArray($request);
|
$pirep = parent::toArray($request);
|
||||||
|
|
||||||
if (\in_array('distance', $pirep, true)
|
if (filled($this->distance) && $this->distance instanceof Distance) {
|
||||||
&& $pirep['distance'] instanceof Distance)
|
$pirep['distance'] = $this->distance->toObject();
|
||||||
{
|
|
||||||
$pirep['distance'] = $pirep['distance']->toObject();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\in_array('planned_distance', $pirep, true)
|
if (filled($this->planned_distance) && $this->planned_distance instanceof Distance) {
|
||||||
&& $pirep['planned_distance'] instanceof Distance)
|
$pirep['planned_distance'] = $this->planned_distance->toObject();
|
||||||
{
|
|
||||||
$pirep['planned_distance'] = $pirep['planned_distance']->toObject();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$pirep['airline'] = new Airline($this->airline);
|
$pirep['airline'] = new Airline($this->airline);
|
||||||
|
@ -155,9 +155,9 @@ class Pirep extends BaseModel
|
|||||||
public function setPlannedDistanceAttribute($value)
|
public function setPlannedDistanceAttribute($value)
|
||||||
{
|
{
|
||||||
if ($value instanceof Distance) {
|
if ($value instanceof Distance) {
|
||||||
$this->attributes['distance'] = $value->toUnit(Distance::STORAGE_UNIT);
|
$this->attributes['planned_distance'] = $value->toUnit(Distance::STORAGE_UNIT);
|
||||||
} else {
|
} else {
|
||||||
$this->attributes['distance'] = $value;
|
$this->attributes['planned_distance'] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +134,8 @@ class AcarsTest extends TestCase
|
|||||||
$this->assertEquals('custom_field', $pirep['fields'][0]['name']);
|
$this->assertEquals('custom_field', $pirep['fields'][0]['name']);
|
||||||
$this->assertEquals('custom_value', $pirep['fields'][0]['value']);
|
$this->assertEquals('custom_value', $pirep['fields'][0]['value']);
|
||||||
|
|
||||||
|
$this->assertHasKeys($pirep['distance'], ['mi', 'nmi', 'km']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the custom field
|
* Update the custom field
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user