2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2022-11-24 21:44:57 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2020-02-23 17:12:17 +00:00
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
|
use Illuminate\Support\Collection;
|
2026-07-28 19:20:18 +01:00
|
|
|
use Illuminate\Support\Facades\URL;
|
2016-05-19 15:01:28 +01:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2026-04-07 09:01:19 +01:00
|
|
|
use Intervention\Image\ImageManager;
|
2020-11-28 18:21:29 +00:00
|
|
|
use Lcobucci\JWT\Configuration;
|
|
|
|
|
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
|
|
|
|
use Lcobucci\JWT\Signer\Key\InMemory;
|
|
|
|
|
use Lcobucci\JWT\Validation\Constraint\SignedWith;
|
2022-06-02 09:40:34 +01:00
|
|
|
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
|
|
|
|
|
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
|
2016-05-19 15:01:28 +01:00
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
2024-03-19 20:13:36 +00:00
|
|
|
/**
|
|
|
|
|
* Register any application services.
|
|
|
|
|
*/
|
|
|
|
|
public function register(): void
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-19 15:01:28 +01:00
|
|
|
/**
|
|
|
|
|
* Bootstrap any application services.
|
|
|
|
|
*/
|
2023-02-18 09:34:57 +00:00
|
|
|
public function boot(): void
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2017-09-16 11:39:36 +01:00
|
|
|
// configure Intervention/Image
|
|
|
|
|
$this->app->bind('Intervention\Image\ImageManager', function () {
|
2026-04-07 09:01:19 +01:00
|
|
|
return ImageManager::withDriver(config('image.driver'));
|
2017-09-16 11:39:36 +01:00
|
|
|
});
|
2019-10-27 16:15:14 +00:00
|
|
|
|
2020-02-23 17:12:17 +00:00
|
|
|
/**
|
|
|
|
|
* Paginate a standard Laravel Collection.
|
|
|
|
|
*
|
2022-07-09 10:08:26 +01:00
|
|
|
* @param int $perPage
|
|
|
|
|
* @param int $total
|
|
|
|
|
* @param int $page
|
|
|
|
|
* @param string $pageName
|
2020-02-23 17:12:17 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
Collection::macro('paginate', function ($perPage, $total = null, $page = null, $pageName = 'page') {
|
|
|
|
|
$page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName);
|
|
|
|
|
|
|
|
|
|
return new LengthAwarePaginator(
|
|
|
|
|
$this->forPage($page, $perPage),
|
|
|
|
|
$total ?: $this->count(),
|
|
|
|
|
$perPage,
|
|
|
|
|
$page,
|
|
|
|
|
[
|
|
|
|
|
'path' => LengthAwarePaginator::resolveCurrentPath(),
|
|
|
|
|
'pageName' => $pageName,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
});
|
2020-11-28 18:21:29 +00:00
|
|
|
|
|
|
|
|
// Configure JWT builder
|
|
|
|
|
$this->app->bind('Lcobucci\JWT\Configuration', function () {
|
2022-08-23 20:50:19 +01:00
|
|
|
$key = InMemory::plainText(config('app.key'));
|
2020-11-28 18:21:29 +00:00
|
|
|
|
2024-10-25 20:40:52 +01:00
|
|
|
$config = Configuration::forSymmetricSigner(new Sha256, $key);
|
2020-11-28 18:21:29 +00:00
|
|
|
|
2024-10-25 20:40:52 +01:00
|
|
|
$config->setValidationConstraints(new SignedWith(new Sha256, $key));
|
2020-11-28 18:21:29 +00:00
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
|
});
|
2022-06-02 09:40:34 +01:00
|
|
|
|
|
|
|
|
// Configure HtmlSanitizer
|
|
|
|
|
$this->app->bind(HtmlSanitizer::class, function () {
|
|
|
|
|
return new HtmlSanitizer(
|
2024-10-25 20:40:52 +01:00
|
|
|
(new HtmlSanitizerConfig)
|
2022-06-02 09:40:34 +01:00
|
|
|
->allowSafeElements()
|
|
|
|
|
->forceAttribute('a', 'rel', 'noopener nofollow')
|
|
|
|
|
);
|
|
|
|
|
});
|
2022-11-24 21:44:57 +00:00
|
|
|
|
|
|
|
|
// Turn on Eloquent strict mode when developing
|
|
|
|
|
Model::shouldBeStrict(! $this->app->isProduction());
|
2026-07-28 19:20:18 +01:00
|
|
|
|
|
|
|
|
// Force HTTPS URL generation in production
|
|
|
|
|
URL::forceHttps($this->app->isProduction());
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
}
|