108 lines
3.1 KiB
PHP
108 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Lib\Instagram\ApiFetcher;
|
|
use Illuminate\Pagination\Paginator;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Illuminate\Support\Facades\Vite;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
// * HTTPS FIX
|
|
URL::forceScheme('https');
|
|
|
|
// * HA PROXY FIX
|
|
App::singleton('clientIp', function () {
|
|
if (config('app.env') === 'local') {
|
|
return request()->getClientIp();
|
|
} else {
|
|
return request()->server('HTTP_X_FORWARDED_FOR') ??
|
|
request()->getClientIp();
|
|
}
|
|
});
|
|
|
|
// * LOCAL FORCE eg: for Carbon
|
|
setlocale(LC_ALL, \sprintf(
|
|
'%s_%s.UTF-8',
|
|
config('app.locale'),
|
|
\strtoupper(config('app.locale'))
|
|
));
|
|
Carbon::setLocale(config('app.locale'));
|
|
|
|
$this->sharetoView();
|
|
|
|
// * Instagram Singleton
|
|
App::singleton('Instagram', function () {
|
|
$url = config('services.facebook.graph_url');
|
|
$version = config('services.facebook.graph_version');
|
|
$access_token = config('services.facebook.graph_access_token');
|
|
|
|
if (empty($url) or !is_string($url)) {
|
|
throw new \RuntimeException(
|
|
'Missing services.facebook.graph_url, FACEBOOK_GRAPH_URL'
|
|
);
|
|
}
|
|
if (empty($version) or !is_string($version)) {
|
|
throw new \RuntimeException(
|
|
'Missing services.facebook.graph_version, FACEBOOK_GRAPH_ACCESS_TOKEN'
|
|
);
|
|
}
|
|
if (empty($access_token) or !is_string($access_token)) {
|
|
throw new \RuntimeException(
|
|
'Missing services.facebook.graph_access_token, FACEBOOK_GRAPH_VERSION'
|
|
);
|
|
}
|
|
|
|
return new ApiFetcher(
|
|
$url,
|
|
$version,
|
|
$access_token
|
|
);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Share Vars to view
|
|
*
|
|
* @return void
|
|
*/
|
|
private function sharetoView()
|
|
{
|
|
if (!app()->runningInConsole()) {
|
|
// * VITE ALIASES
|
|
Vite::macro('image', function (string $asset) {
|
|
/** @var \Illuminate\Foundation\Vite $self */
|
|
$self = $this;
|
|
$self->asset("resources/assets/images/{$asset}");
|
|
});
|
|
|
|
// * FORCE BOOTSTRAP PAGINATOR (or custom if in front)
|
|
// Early boot, request wont be filled as expected.
|
|
if (collect(explode('/', \request()->getPathInfo()))->get(1) === 'bo') {
|
|
Paginator::useBootstrap();
|
|
} else {
|
|
Paginator::useBootstrap();
|
|
}
|
|
}
|
|
}
|
|
}
|