Files
exchange-2.0/app/Classes/Modules/Segments/Services/ConvertsConstantDetailsToResource.php

38 lines
988 B
PHP

<?php
namespace App\Classes\Modules\Segments\Services;
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Http\Resources\ConstantResource;
use App\Http\Resources\CurrencyResource;
use App\Models\SegmentConstant;
class ConvertsConstantDetailsToResource
{
/** @var FetchesCurrency */
private $fetchesCurrency;
/**
* ConvertsConstantDetailsToResource constructor.
* @param FetchesCurrency $fetchesCurrency
*/
public function __construct(FetchesCurrency $fetchesCurrency)
{
$this->fetchesCurrency = $fetchesCurrency;
}
public function execute(SegmentConstant $constant){
if($constant->reference === SegmentConstants::SUPPLIER_CURRENCIES) {
return property_exists($constant->detail, 'id') ? new CurrencyResource($this->fetchesCurrency->execute(['id' => $constant->detail->id])) : '';
}
return $constant->detail;
}
}