-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidationCodesProvider.php
More file actions
49 lines (38 loc) · 1.61 KB
/
ValidationCodesProvider.php
File metadata and controls
49 lines (38 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Kdabrow\ValidationCodes\Providers;
use Illuminate\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Support\ServiceProvider;
use Kdabrow\ValidationCodes\Factory;
use Kdabrow\ValidationCodes\Handler;
use Kdabrow\ValidationCodes\Validator;
class ValidationCodesProvider extends ServiceProvider
{
public function register()
{
$this->mergeConfigFrom($this->pathTo('config' . DIRECTORY_SEPARATOR . 'validation_codes.php'), 'validation_codes');
$this->app->extend('validator', function ($translator, Container|null $container = null) {
$factory = new Factory($translator->getTranslator(), $container);
if (isset($this->app['db'], $this->app['validation.presence'])) {
$factory->setPresenceVerifier($this->app['validation.presence']);
}
$factory->resolver(function ($translator, array $data, array $rules, array $messages, array $attributes) {
return new Validator($translator, $data, $rules, $messages, $attributes);
});
return $factory;
});
$this->app->singleton(ExceptionHandler::class, Handler::class);
}
public function boot()
{
$this->loadTranslationsFrom($this->pathTo('lang'), 'validation_codes');
$this->publishes([
$this->pathTo('config/validation_codes.php') => $this->app->configPath('validation_codes.php'),
$this->pathTo('lang') => $this->app->langPath('vendor/validation_codes'),
], "validation_codes");
}
private function pathTo(string $directory): string
{
return __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $directory;
}
}