1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BrunoFernandes\LaravelTwitterHandleValidation; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Validator; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
|
8
|
|
|
class LaravelTwitterHandleValidationServiceProvider extends ServiceProvider |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Bootstrap the application services. |
12
|
|
|
*/ |
13
|
|
|
public function boot() |
14
|
|
|
{ |
15
|
|
|
Validator::extend('twitter_handle', '\BrunoFernandes\LaravelTwitterHandleValidation\TwitterHandleValidator@validate'); |
16
|
|
|
Validator::replacer( 'twitter_handle', function ($message, $attribute, $rule, $parameters) { |
|
|
|
|
17
|
|
|
if ($message == 'validation.twitter_handle') { |
18
|
|
|
return str_replace(':attribute', $attribute, config('laravel-twitter-handle-validation.validation')); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
return $message; |
22
|
|
|
}); |
23
|
|
|
|
24
|
|
|
/* |
25
|
|
|
* Optional methods to load your package assets |
26
|
|
|
*/ |
27
|
|
|
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-twitter-handle-validation'); |
28
|
|
|
|
29
|
|
|
if ($this->app->runningInConsole()) { |
30
|
|
|
$this->publishes([ |
31
|
|
|
__DIR__.'/../config/laravel-twitter-handle-validation.php' => config_path('laravel-twitter-handle-validation.php'), |
32
|
|
|
], 'config'); |
33
|
|
|
|
34
|
|
|
// Publishing the translation files. |
35
|
|
|
/*$this->publishes([ |
36
|
|
|
__DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-twitter-handle-validation'), |
37
|
|
|
], 'lang');*/ |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Register the application services. |
43
|
|
|
*/ |
44
|
|
|
public function register() |
45
|
|
|
{ |
46
|
|
|
// Automatically apply the package configuration |
47
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/laravel-twitter-handle-validation.php', 'laravel-twitter-handle-validation'); |
48
|
|
|
|
49
|
|
|
// Register the main class to use with the facade |
50
|
|
|
$this->app->singleton('laravel-twitter-handle-validation', function () { |
51
|
|
|
return resolve(LaravelTwitterHandleValidation::class); |
52
|
|
|
}); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.