Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ValidationServiceProvider
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 register
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Http\Validation;
6
7use Engelsystem\Application;
8use Engelsystem\Container\ServiceProvider;
9use Engelsystem\Controllers\BaseController;
10
11class ValidationServiceProvider extends ServiceProvider
12{
13    public function register(): void
14    {
15        $validator = $this->app->make(Validator::class);
16        $this->app->instance(Validator::class, $validator);
17        $this->app->instance('validator', $validator);
18
19        $this->app->afterResolving(function ($object, Application $app): void {
20            if (!$object instanceof BaseController) {
21                return;
22            }
23
24            $object->setValidator($app->get(Validator::class));
25        });
26    }
27}