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

152 lines
4.4 KiB
PHP
Raw Permalink Normal View History

2020-10-30 17:26:00 +01:00
<?php
2026-06-14 21:32:07 +02:00
declare(strict_types=1);
2020-10-30 17:26:00 +01:00
namespace App\Providers;
2026-06-14 21:32:07 +02:00
use App\Contracts\Directories\CustomerDirectory;
use App\Contracts\Directories\EmployeeDirectory;
use App\Contracts\Directories\OrderDirectory;
feat: implement pagination using Pagination value object - Updated DataTableService to accept a Pagination object for pagination parameters. - Refactored paginateQuery method to utilize pageSize and pageNumber from Pagination. refactor: replace ActionExecutor with Executor in controller traits - Updated ChangesModelOrder, TogglesModelStar, and TogglesModelStatus traits to use Executor interface instead of ActionExecutor. feat: add PictureMetadata and Slug value objects - Introduced PictureMetadata for managing image metadata with validation. - Added Slug value object for slug generation and validation. feat: update breadcrumbs to support RangeDto - Modified breadcrumbs-bo.php to accept RangeDto in the edit route. test: add tests for RangesController - Added tests for accessing, creating, updating, and deleting ranges. - Included tests for toggling range status. test: add integration tests for range actions - Created tests for CreateRange, DeleteRange, and UpdateRange actions. - Validated input handling and database interactions. test: add unit tests for range input classes - Implemented tests for CreateRangeInput and UpdateRangeInput to validate input constraints. test: add unit tests for value objects - Added tests for PictureMetadata and Slug to ensure proper validation and instantiation. test: add unit tests for RangeDto - Created tests to verify RangeDto mapping from Range model. test: add unit tests for RangePolicy - Implemented tests for RangePolicy to validate permissions based on user roles.
2026-09-29 16:59:07 +02:00
use App\Contracts\Executor;
2026-06-14 21:32:07 +02:00
use App\Contracts\Repositories\EmployeeRepository;
use App\Contracts\Repositories\OrderRepository;
use App\Contracts\Repositories\UserRepository;
use App\Directories\EloquentCustomerDirectory;
use App\Directories\EloquentEmployeeDirectory;
use App\Directories\EloquentOrderDirectory;
use App\Repositories\EloquentEmployeeRepository;
use App\Repositories\EloquentOrderRepository;
use App\Repositories\EloquentUserRepository;
use App\Services\ActionExecutorService;
2026-06-14 21:32:07 +02:00
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Date;
2022-09-08 13:02:16 +02:00
use Illuminate\Support\Facades\URL;
2026-06-14 21:32:07 +02:00
use Illuminate\Support\Facades\Vite;
use Illuminate\Support\ServiceProvider;
use Mews\Purifier\Purifier;
use Shared\DDD\Equatable;
2020-10-30 17:26:00 +01:00
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
2026-06-14 21:32:07 +02:00
#[\Override]
2020-10-30 17:26:00 +01:00
public function register()
{
2026-06-14 21:32:07 +02:00
$this->app->singleton(
Purifier::class,
fn () => resolve('purifier')
);
$this->app->singleton('clientIp', function () {
return request()->ip() ?? request()->getClientIp();
2026-06-14 21:32:07 +02:00
});
$this->app->bind(EmployeeRepository::class, EloquentEmployeeRepository::class);
$this->app->bind(OrderRepository::class, EloquentOrderRepository::class);
$this->app->bind(UserRepository::class, EloquentUserRepository::class);
$this->app->bind(CustomerDirectory::class, EloquentCustomerDirectory::class);
$this->app->bind(EmployeeDirectory::class, EloquentEmployeeDirectory::class);
$this->app->bind(OrderDirectory::class, EloquentOrderDirectory::class);
feat: implement pagination using Pagination value object - Updated DataTableService to accept a Pagination object for pagination parameters. - Refactored paginateQuery method to utilize pageSize and pageNumber from Pagination. refactor: replace ActionExecutor with Executor in controller traits - Updated ChangesModelOrder, TogglesModelStar, and TogglesModelStatus traits to use Executor interface instead of ActionExecutor. feat: add PictureMetadata and Slug value objects - Introduced PictureMetadata for managing image metadata with validation. - Added Slug value object for slug generation and validation. feat: update breadcrumbs to support RangeDto - Modified breadcrumbs-bo.php to accept RangeDto in the edit route. test: add tests for RangesController - Added tests for accessing, creating, updating, and deleting ranges. - Included tests for toggling range status. test: add integration tests for range actions - Created tests for CreateRange, DeleteRange, and UpdateRange actions. - Validated input handling and database interactions. test: add unit tests for range input classes - Implemented tests for CreateRangeInput and UpdateRangeInput to validate input constraints. test: add unit tests for value objects - Added tests for PictureMetadata and Slug to ensure proper validation and instantiation. test: add unit tests for RangeDto - Created tests to verify RangeDto mapping from Range model. test: add unit tests for RangePolicy - Implemented tests for RangePolicy to validate permissions based on user roles.
2026-09-29 16:59:07 +02:00
$this->app->bind(Executor::class, ActionExecutorService::class);
2020-10-30 17:26:00 +01:00
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2026-06-14 21:32:07 +02:00
$this->laravelGlobalSetup();
$this->dateSetup();
$this->dateMacro();
$this->collectionMacro();
}
2021-06-07 16:12:13 +02:00
2026-06-14 21:32:07 +02:00
private function laravelGlobalSetup(): void
{
Model::shouldBeStrict(app()->environment('local'));
2021-03-18 08:40:20 +01:00
2026-06-14 21:32:07 +02:00
Vite::useCspNonce();
2026-06-14 21:32:07 +02:00
URL::forceScheme('https');
}
2026-06-14 21:32:07 +02:00
private function dateSetup(): void
{
foreach ([\LC_TIME, \LC_MESSAGES, \LC_COLLATE, \LC_CTYPE, \LC_MONETARY] as $constant) {
setlocale(
$constant,
sprintf(
'%s_%s.UTF-8',
config()->string('app.locale'),
strtoupper(config()->string('app.locale'))
)
);
2022-09-12 14:26:42 +02:00
}
2026-06-14 21:32:07 +02:00
Date::setLocale(config()->string('app.locale'));
Date::setFallbackLocale(config()->string('app.fallback_locale'));
}
2021-05-06 17:18:25 +02:00
2026-06-14 21:32:07 +02:00
private function dateMacro(): void
{
Date::macro('toLocalInput', function ($date) {
if (! $date) {
return null;
}
$timezone = request()->string(
'client_timezone',
request()->string(
'client_timezone',
'Europe/Paris'
)->value()
)->value();
return Date::parse($date)
->setTimezone($timezone)
->format('Y-m-d\TH:i');
2022-10-14 14:52:56 +02:00
});
2026-06-14 21:32:07 +02:00
Date::macro('forHumans', function ($date) {
if (! $date) {
return null;
}
$timezone = request()->string(
'client_timezone',
request()->string(
'client_timezone',
'Europe/Paris'
)->value()
)->value();
return Date::parse($date)
->setTimezone($timezone)
->isoFormat('ddd DD/MM/Y \à HH:mm');
});
2026-06-14 21:32:07 +02:00
}
private function collectionMacro(): void
{
Collection::macro('uniqueValues', function () {
return $this->unique(function ($item) {
if ($item instanceof Equatable) {
return $item instanceof \Stringable ? (string) $item : json_encode($item);
}
if ($item instanceof \Stringable) {
return (string) $item;
}
2026-06-14 21:32:07 +02:00
return $item;
});
});
2020-10-30 17:26:00 +01:00
}
}