ldc-boutique-cnc/app/Providers/AppServiceProvider.php

127 lines
3.8 KiB
PHP
Raw Normal View History

2020-10-30 17:26:00 +01:00
<?php
namespace App\Providers;
2023-03-01 11:02:42 +01:00
use App\Models\Shop\DeliveryMode;
use App\Models\Site\GeneralConfig;
use App\Models\Shop\PaymentMode;
use App\Models\Merchandise\Range;
use App\Models\Merchandise\Tag;
2022-11-23 11:10:40 +01:00
use Gloudemans\Shoppingcart\Facades\Cart;
use Illuminate\Support\Facades\View;
2020-10-30 17:26:00 +01:00
use Illuminate\Support\ServiceProvider;
use Illuminate\Pagination\Paginator;
2022-10-03 17:13:44 +02:00
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\File;
2022-09-03 16:56:16 +02:00
use Illuminate\Support\Facades\URL;
2020-10-30 17:26:00 +01:00
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2022-10-03 17:13:44 +02:00
// * HTTPS FIX
2022-09-03 16:56:16 +02:00
URL::forceScheme('https');
2021-06-07 16:12:13 +02:00
2022-10-03 17:13:44 +02:00
// * 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();
}
});
2021-03-18 08:40:20 +01:00
2022-10-03 17:13:44 +02:00
// * 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'));
2022-09-03 16:56:16 +02:00
2022-11-23 11:10:40 +01:00
// * Basket singleton
App::singleton('basket', function () {
return Cart::instance('basket');
});
2022-10-03 17:13:44 +02:00
$this->sharetoView();
}
/**
* Share Vars to view
*
* @return void
*/
private function sharetoView()
{
// * View shares
2023-02-24 09:31:39 +01:00
// ! Add view file pathes (also needed for console xml job).
View::addNamespace('back', resource_path('views'));
View::addNamespace('theme', resource_path('theme/views'));
2023-02-08 12:09:37 +01:00
2023-02-24 09:31:39 +01:00
if (!app()->runningInConsole()) {
2023-02-08 12:09:37 +01:00
$appInfos = Cache::remember(
'composer',
360,
function () {
return json_decode(File::get(\app_path('../composer.json')));
}
);
2022-10-03 17:13:44 +02:00
// Share composer.json infos .
2023-02-17 09:36:31 +01:00
View::share('cpsr_name', $appInfos->name);
View::share('cpsr_version', $appInfos->version);
View::share('cpsr_license', $appInfos->license);
View::share('cpsr_time', now()->parse($appInfos->time)->isoFormat('Y'));
2022-10-03 17:13:44 +02:00
try {
View::share('GeneralConfigGlobal', GeneralConfig::getCachedConfigs());
} catch (\Exception $e) {
report($e);
View::share('GeneralConfigGlobal', collect());
} //end try
2023-02-08 12:09:37 +01:00
// * 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 {
2023-02-15 09:09:06 +01:00
Paginator::defaultview('theme::modules.pagination');
2023-02-08 12:09:37 +01:00
}
// * Payment Modes
View::share('PaymentModesGlobal', PaymentMode::getCachedPaymentModes());
\app()->singleton('PaymentModesGlobal', function () {
return PaymentMode::getCachedPaymentModes();
});
2023-02-08 12:09:37 +01:00
// * Delivery Mode
View::share('DeliveryModesGlobal', DeliveryMode::getCachedDeliveryModes());
\app()->singleton('DeliveryModesGlobal', function () {
return DeliveryMode::getCachedDeliveryModes();
});
// * TAGS
View::share('PublishedTagsGlobal', Tag::getCachedPublishedTags());
// * RANGES
View::share('PublishedRangesGlobal', Range::getCachedPublishedRanges());
2022-10-03 17:13:44 +02:00
} //end if
2020-10-30 17:26:00 +01:00
}
}