Cleanup SI Unit classes and interface for REST responses; fixes to a few METAR parsing issues
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Interfaces\Unit;
|
||||
use Illuminate\Http\Resources\Json\Resource;
|
||||
|
||||
/**
|
||||
@@ -9,4 +10,22 @@ use Illuminate\Http\Resources\Json\Resource;
|
||||
*/
|
||||
class Response extends Resource
|
||||
{
|
||||
/**
|
||||
* Iterate through the list of $fields and check if they're a "Unit"
|
||||
* If they are, then add the response
|
||||
*
|
||||
* @param $response
|
||||
* @param array $fields
|
||||
*/
|
||||
public function checkUnitFields(&$response, array $fields): void
|
||||
{
|
||||
foreach ($fields as $f) {
|
||||
if ($this->{$f} instanceof Unit) {
|
||||
$response[$f] = $this->{$f}->getResponseUnits();
|
||||
} else {
|
||||
$response[$f] = $this->{$f};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user