1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of persian validation package |
||
5 | * |
||
6 | * (c) Farhad Zand <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Iamfarhad\Validation; |
||
13 | |||
14 | use Iamfarhad\Validation\Contracts\AbstractValidationRule; |
||
15 | use Illuminate\Support\Facades\App; |
||
16 | use Illuminate\Support\ServiceProvider; |
||
17 | |||
18 | class ValidationServiceProvider extends ServiceProvider |
||
19 | { |
||
20 | /** |
||
21 | * Register services. |
||
22 | * |
||
23 | * @return void |
||
24 | */ |
||
25 | public function register() |
||
26 | { |
||
27 | $this->app->bind('ValidationMessages', 'Iamfarhad\Validation\ValidationMessages'); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Bootstrap services. |
||
32 | * |
||
33 | * @return void |
||
34 | * |
||
35 | * @throws \Exception |
||
36 | * @throws \ReflectionException |
||
37 | */ |
||
38 | public function boot() |
||
39 | { |
||
40 | $this->publishes([ |
||
41 | __DIR__.'/lang/validation/'.App::getLocale().'.php' => resource_path('lang/validation/'.App::getLocale().'.php'), |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
42 | ]); |
||
43 | |||
44 | foreach (glob(__DIR__.'/Rules/*.php') as $file) { |
||
45 | require_once $file; |
||
46 | |||
47 | // get the file name of the current file without the extension |
||
48 | // which is essentially the class name |
||
49 | $class = basename($file, '.php'); |
||
50 | |||
51 | $Rule = 'Iamfarhad\Validation\Rules'; |
||
52 | if (class_exists($Rule.'\\'.$class)) { |
||
53 | $reflectionClass = new \ReflectionClass($Rule.'\\'.$class); |
||
54 | if (! $reflectionClass->isSubclassOf(AbstractValidationRule::class)) { |
||
55 | throw new \Exception('this extension ('.$class.') is not instance of AbstractValidationRule'); |
||
56 | } |
||
57 | // Register extension |
||
58 | $module = $reflectionClass->newInstanceArgs([]); |
||
59 | $module->register(); |
||
60 | } |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 |