66 lines
2.0 KiB
PHP
Executable File
66 lines
2.0 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Services\Nasa\NavigationService as NasaNavService;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Http\Request;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
public function register(): void {}
|
|
|
|
public function boot(): void
|
|
{
|
|
Request::macro('fullUrlWithAllQuery', function (array $aNewQuery = []) {
|
|
$aCleanQuery = collect($this->query())
|
|
->transform(fn($xV) => is_null($xV) ? '' : $xV)
|
|
->merge($aNewQuery)
|
|
->all();
|
|
|
|
return $this->url() . '?' . http_build_query($aCleanQuery);
|
|
});
|
|
|
|
Http::macro('nasa', function (string $sSiteWww, string $sVersion = 'v1') {
|
|
$iTimestamp = time();
|
|
$sSecret = config('nasa.key');
|
|
$sToken = md5("timestamp={$iTimestamp}&secret={$sSecret}");
|
|
$bVerifySsl = config('nasa.verify_ssl');
|
|
|
|
if ($sSiteWww == 'dd.loc') {
|
|
$h = "http";
|
|
} else {
|
|
$h = "https";
|
|
}
|
|
return Http::baseUrl($h."://" . $sSiteWww . "/api/nasa/{$sVersion}")
|
|
->acceptJson()
|
|
->timeout(10)
|
|
->throw()
|
|
->withHeaders([
|
|
'X-Nasa-Timestamp' => $iTimestamp,
|
|
'X-Nasa-Token' => $sToken,
|
|
])
|
|
->withOptions([
|
|
'verify' => $bVerifySsl,
|
|
// 'debug' => true
|
|
]);
|
|
});
|
|
|
|
View::composer('components.layouts.nasa.app', function ($oView) {
|
|
$oNavService = app(NasaNavService::class);
|
|
$sCurrentPermissionSlug = request()->route() ? request()->route()->getName() : '';
|
|
|
|
$aNavInfo = $oNavService->aGetInfo($sCurrentPermissionSlug);
|
|
|
|
$aWith = [
|
|
"aNavInfo" => $aNavInfo
|
|
];
|
|
|
|
$oView->with($aWith);
|
|
});
|
|
}
|
|
|
|
}
|