From b9ae473f55ef31b47bbe420b36d735b0e9abcab6 Mon Sep 17 00:00:00 2001 From: Paul Klimov Date: Tue, 10 Sep 2019 16:54:02 +0300 Subject: [PATCH] make data provider deferrable, add DI support --- .../PushNotificationServiceProvider.php | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Providers/PushNotificationServiceProvider.php b/src/Providers/PushNotificationServiceProvider.php index 41cd0d2..37dd0e4 100644 --- a/src/Providers/PushNotificationServiceProvider.php +++ b/src/Providers/PushNotificationServiceProvider.php @@ -3,9 +3,10 @@ namespace Edujugon\PushNotification\Providers; use Edujugon\PushNotification\PushNotification; +use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Support\ServiceProvider; -class PushNotificationServiceProvider extends ServiceProvider +class PushNotificationServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Bootstrap the application services. @@ -14,23 +15,38 @@ class PushNotificationServiceProvider extends ServiceProvider */ public function boot() { - $config_path = function_exists('config_path') ? config_path('pushnotification.php') : 'pushnotification.php'; + if (! $this->app->runningInConsole()) { + return; + } + + $configPath = $this->app->make('path.config'); $this->publishes([ - __DIR__.'/../Config/config.php' => $config_path, - __DIR__.'/../Config/iosCertificates' => config_path('iosCertificates/') + __DIR__.'/../Config/config.php' => $configPath.'/pushnotification.php', + __DIR__.'/../Config/iosCertificates' => $configPath.'/iosCertificates/', ], 'config'); } /** - * Register the application services. - * - * @return void + * {@inheritdoc} */ public function register() { $this->app->singleton('edujugonPushNotification', function ($app) { return new PushNotification(); }); + + $this->app->bind(PushNotification::class, 'edujugonPushNotification'); + } + + /** + * {@inheritdoc} + */ + public function provides() + { + return [ + PushNotification::class, + 'edujugonPushNotification', + ]; } }