2023-06-28 17:29:56 +06:00
|
|
|
<?php declare(strict_types=1);
|
2023-03-05 20:14:04 +06:00
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2023-06-28 17:29:56 +06:00
|
|
|
use App\Captcha\Contracts\ImageBody;
|
|
|
|
use App\Captcha\Contracts\ImageHead;
|
|
|
|
use App\Captcha\Contracts\ImageLines;
|
|
|
|
use App\Captcha\Contracts\ImageManager as ImageManagerContract;
|
|
|
|
use App\Captcha\Images\Body;
|
|
|
|
use App\Captcha\Images\Head;
|
|
|
|
use App\Captcha\Images\ImageManager;
|
|
|
|
use App\Captcha\Images\Lines;
|
2023-09-19 14:29:01 +06:00
|
|
|
use App\Contracts\CryptographyContract;
|
2023-12-05 00:53:04 +06:00
|
|
|
use App\Helpers\Helpers;
|
2023-09-19 14:27:33 +06:00
|
|
|
use App\Services\Api\V1\CaptchaGenerateService;
|
2023-08-22 00:15:35 +06:00
|
|
|
use App\Services\CaptchaToken\CaptchaTokenHandler;
|
2023-09-19 14:29:01 +06:00
|
|
|
use App\Services\CryptographyString;
|
2023-08-22 00:15:35 +06:00
|
|
|
use App\Services\GenerateTokenCommand\GenerateTokenUlidCommand;
|
|
|
|
use App\Services\GenerateTokenCommand\GenerateTokenUuidCommand;
|
2023-07-16 19:21:09 +06:00
|
|
|
use App\Services\Search\CreateSearchInstanceCommand;
|
|
|
|
use App\Services\Search\Search;
|
2023-06-28 17:29:56 +06:00
|
|
|
use Illuminate\Contracts\Foundation\Application;
|
2023-07-16 19:21:09 +06:00
|
|
|
use Illuminate\Pagination\Paginator;
|
2023-12-05 00:53:04 +06:00
|
|
|
use Illuminate\Support\Facades\Blade;
|
2023-12-09 00:55:56 +06:00
|
|
|
use Illuminate\Support\Facades\URL;
|
2023-03-05 20:14:04 +06:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2023-07-02 15:21:01 +06:00
|
|
|
use Illuminate\Validation\Rules\Password;
|
2023-03-05 20:14:04 +06:00
|
|
|
|
2023-06-28 17:29:56 +06:00
|
|
|
final class AppServiceProvider extends ServiceProvider
|
2023-03-05 20:14:04 +06:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*/
|
|
|
|
public function register(): void
|
|
|
|
{
|
2023-06-28 17:29:56 +06:00
|
|
|
$this->app->bind(ImageManagerContract::class, function () {
|
|
|
|
return new ImageManager(imageClassName: config('captcha.imageClass'));
|
|
|
|
});
|
|
|
|
$this->app->bind(ImageHead::class, Head::class);
|
|
|
|
$this->app->bind(ImageBody::class, Body::class);
|
|
|
|
$this->app->bind(ImageLines::class, Lines::class);
|
|
|
|
|
2023-09-19 14:29:01 +06:00
|
|
|
$this->app->bind(CryptographyContract::class, CryptographyString::class);
|
|
|
|
|
2023-07-16 19:21:09 +06:00
|
|
|
$this->app->bind(CreateSearchInstanceCommand::class, function () {
|
|
|
|
return new CreateSearchInstanceCommand(Search::class);
|
|
|
|
});
|
|
|
|
|
2023-09-19 14:27:33 +06:00
|
|
|
$this->app->bind(CaptchaGenerateService::class, function (Application $app) {
|
|
|
|
return new CaptchaGenerateService(
|
2023-06-28 17:29:56 +06:00
|
|
|
config: config('captcha', []),
|
|
|
|
imageHead: $app->make(ImageHead::class),
|
|
|
|
imageBody: $app->make(ImageBody::class)
|
|
|
|
);
|
|
|
|
});
|
2023-08-22 00:15:35 +06:00
|
|
|
|
|
|
|
$this->app->bind(CaptchaTokenHandler::class, function (Application $app) {
|
|
|
|
return new CaptchaTokenHandler(
|
|
|
|
generatePublicTokenCommand: $app->make(GenerateTokenUlidCommand::class),
|
|
|
|
generatePrivateTokenCommand: $app->make(GenerateTokenUuidCommand::class)
|
|
|
|
);
|
|
|
|
});
|
2023-03-05 20:14:04 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bootstrap any application services.
|
|
|
|
*/
|
|
|
|
public function boot(): void
|
|
|
|
{
|
2023-12-05 00:53:04 +06:00
|
|
|
Blade::if('demo', function () {
|
|
|
|
return Helpers::isDemoMode();
|
|
|
|
});
|
|
|
|
|
2023-12-09 00:55:56 +06:00
|
|
|
if (config('app.force_https') === true) {
|
|
|
|
URL::forceScheme('https');
|
|
|
|
}
|
|
|
|
|
2023-07-02 15:21:01 +06:00
|
|
|
Password::defaults(function () {
|
|
|
|
$rule = Password::min(8);
|
|
|
|
|
|
|
|
return $this->app->isProduction()
|
|
|
|
? $rule->letters()
|
|
|
|
->mixedCase()
|
|
|
|
->numbers()
|
|
|
|
->symbols()
|
|
|
|
->uncompromised()
|
|
|
|
: $rule;
|
|
|
|
});
|
2023-07-16 19:21:09 +06:00
|
|
|
|
|
|
|
Paginator::useBootstrapFive();
|
2023-03-05 20:14:04 +06:00
|
|
|
}
|
|
|
|
}
|