| 1 | <?php |
||
| 8 | class GoogleCalendarServiceProvider extends ServiceProvider |
||
| 9 | { |
||
| 10 | public function boot() |
||
| 11 | { |
||
| 12 | $this->publishes([ |
||
| 13 | __DIR__.'/../config/google-calendar.php' => config_path('google-calendar.php'), |
||
| 14 | ], 'config'); |
||
| 15 | } |
||
| 16 | |||
| 17 | public function register() |
||
| 18 | { |
||
| 19 | $this->mergeConfigFrom(__DIR__.'/../config/google-calendar.php', 'google-calendar'); |
||
| 20 | |||
| 21 | $this->app->bind(GoogleCalendar::class, function () { |
||
| 22 | $config = config('google-calendar'); |
||
| 23 | |||
| 24 | $this->guardAgainstInvalidConfiguration($config); |
||
| 25 | |||
| 26 | return GoogleCalendarFactory::createForCalendarId($config['calendar_id']); |
||
| 27 | }); |
||
| 28 | |||
| 29 | $this->app->alias(GoogleCalendar::class, 'laravel-google-calendar'); |
||
| 30 | } |
||
| 31 | |||
| 32 | protected function guardAgainstInvalidConfiguration(array $config = null) |
||
| 33 | { |
||
| 34 | if (empty($config['calendar_id'])) { |
||
| 35 | throw InvalidConfiguration::calendarIdNotSpecified(); |
||
| 36 | } |
||
| 37 | |||
| 38 | $credentials = $config['service_account_credentials_json']; |
||
| 39 | |||
| 40 | if (!is_array($credentials) && !is_string($credentials)) { |
||
| 41 | throw InvalidConfiguration::credentialsTypeWrong($credentials) |
||
| 42 | } |
||
|
|
|||
| 43 | |||
| 50 |