121 lines
3.7 KiB
PHP
121 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\GeneralConfig;
|
|
use App\Models\Range;
|
|
use App\Models\Tag;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Illuminate\Pagination\Paginator;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Support\Facades\URL;
|
|
|
|
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'));
|
|
|
|
if (!app()->runningInConsole()) {
|
|
// * 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::defaultView('front.modules.paginator');
|
|
}
|
|
}
|
|
|
|
$this->sharetoView();
|
|
|
|
if (Schema::hasTable('ranges')) {
|
|
// On partage les ranges (gammes produit).
|
|
$ranges = Range::where('status', true)->get();
|
|
View::share('published_ranges', $ranges);
|
|
}
|
|
|
|
if (Schema::hasTable('tags')) {
|
|
// On partage les tags.
|
|
$tags = Tag::where('status', true)->orderBy('order', 'ASC')->get();
|
|
View::share('published_tags', $tags);
|
|
}
|
|
|
|
Blade::directive('fmt_sellunit', function ($expression) {
|
|
if (config('bosettings.sell_unit_management') == "strict") {
|
|
return "<?php if(!empty($expression)) { echo sprintf('/ %s', SellUnit::make($expression)->label); } ?>";
|
|
} else {
|
|
return "<?php if(!empty($expression)) { echo sprintf('/ %s', $expression); } ?>";
|
|
}
|
|
});
|
|
|
|
Blade::directive('excerpt_product_title', function ($expression) {
|
|
$limit = config('theme.max_product_title_length');
|
|
return "<?php echo Illuminate\Support\Str::limit($expression,$limit) ?>";
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Share Vars to view
|
|
*
|
|
* @return void
|
|
*/
|
|
private function sharetoView()
|
|
{
|
|
// * View shares
|
|
if (!app()->runningInConsole()) {
|
|
$appInfos = Cache::remember('composer', 360, function () {
|
|
return json_decode(File::get(\app_path('../composer.json')));
|
|
});
|
|
// Share composer.json infos .
|
|
View::share('name', $appInfos->name);
|
|
View::share('version', $appInfos->version);
|
|
View::share('license', $appInfos->license);
|
|
|
|
try {
|
|
View::share('GeneralConfigGlobal', GeneralConfig::getCachedConfigs());
|
|
} catch (\Exception $e) {
|
|
report($e);
|
|
View::share('GeneralConfigGlobal', collect());
|
|
} //end try
|
|
} //end if
|
|
}
|
|
}
|