55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
namespace App\Domains\Captcha\Providers;
|
|
|
|
use Illuminate\Config\Repository;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use App\Domains\Captcha\Services\CaptchaService;
|
|
use App\Domains\Captcha\Providers\RouteServiceProvider;
|
|
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
|
|
|
|
class CaptchaServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* 引导启动任何应用程序服务
|
|
*
|
|
* php artisan make:migration --path=app/Domains/Captcha/Database/migrations
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
// $this->loadMigrationsFrom([realpath(__DIR__ . '/../Database/migrations')]);
|
|
// $this->app->make(EloquentFactory::class)->load(realpath(__DIR__ . '/../Database/factories'));
|
|
$this->mergeConfigFrom(realpath(__DIR__ . '/../config.php'), 'domain.captcha');
|
|
|
|
// Validator extensions
|
|
$this->app['validator']->extend('captcha', function ($attribute, $value, $parameters) {
|
|
return app(CaptchaService::class)->check($value, $parameters[0]);
|
|
});
|
|
|
|
// Bind captcha
|
|
$this->app->bind('captcha', function ($app) {
|
|
$config = new Repository($app['config']['domain']);
|
|
|
|
return new CaptchaService(
|
|
$app['Illuminate\Filesystem\Filesystem'],
|
|
$config,
|
|
$app['Intervention\Image\ImageManager'],
|
|
$app['Illuminate\Hashing\BcryptHasher'],
|
|
$app['Illuminate\Support\Str']
|
|
);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 注册一个服务提供者
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
$this->app->register(RouteServiceProvider::class);
|
|
$this->app->register(MiddlewareServiceProvider::class);
|
|
}
|
|
}
|