diff --git a/src/PhoneServiceProvider.php b/src/PhoneServiceProvider.php index 71dbf50..f76fd15 100644 --- a/src/PhoneServiceProvider.php +++ b/src/PhoneServiceProvider.php @@ -1,29 +1,15 @@ registerValidator(); - - $this->registerRule(); - } - - /** - * Register the service provider. + * Register services. * * @return void */ @@ -35,38 +21,18 @@ public function register() $this->app->alias('libphonenumber', PhoneNumberUtil::class); } - - /** - * Register the "phone" validator. - */ - protected function registerValidator() - { - $extend = static::canUseDependentValidation() ? 'extendDependent' : 'extend'; - - $this->app['validator']->{$extend}('phone', Validation\Phone::class . '@validate'); - } - - /** - * Register the "phone" rule macro. - */ - protected function registerRule() - { - if (class_exists('Illuminate\Validation\Rule') && class_uses(Rule::class, Macroable::class)) { - Rule::macro('phone', function () { - return new Rules\Phone; - }); - } - } - + /** - * Determine whether we can register a dependent validator. + * Bootstrap services. * - * @return bool + * @return void */ - public static function canUseDependentValidation() + public function boot() { - $validator = new ReflectionClass('\Illuminate\Validation\Factory'); + $this->app['validator']->extendDependent('phone', Validation\Phone::class . '@validate'); - return $validator->hasMethod('extendDependent'); + Rule::macro('phone', function () { + return new Rules\Phone; + }); } }