48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class MarhunService
|
|
{
|
|
public $norujukan;
|
|
|
|
public function __construct($norujukan) {
|
|
$this->norujukan = $norujukan;
|
|
}
|
|
|
|
public function getMarhunDetails()
|
|
{
|
|
$getMarhunDetails = function ($x) {
|
|
return Http::arrahn()->get('/api/marhun/' . $x)->json();
|
|
};
|
|
|
|
$getMarhunTypeFullName = function ($code) {
|
|
return Http::arrahn()->get('/api/jemas/nama_marhun', ['marhun' => $code['marhun']])->json()['descpt'];
|
|
};
|
|
|
|
$formatMarhunDetailData = function ($x) use($getMarhunTypeFullName) {
|
|
return array_map(function ($y) use ($getMarhunTypeFullName) {
|
|
$y['marhun'] = $getMarhunTypeFullName($y);
|
|
return $y;
|
|
}, $x);
|
|
};
|
|
|
|
$marhunDetailPipelines = [
|
|
fn($x) => $getMarhunDetails($x),
|
|
fn($x) => $x == null ? [] : $x,
|
|
fn($x) => array_map(fn($y) => array_merge([], ...$y), $x),
|
|
fn($x) => $formatMarhunDetailData($x),
|
|
];
|
|
|
|
return array_reduce($marhunDetailPipelines, fn($x, $y) => $y($x), $this->norujukan);
|
|
}
|
|
|
|
public static function from($norujukan)
|
|
{
|
|
return new static($norujukan);
|
|
}
|
|
|
|
}
|