| Conditions | 4 |
| Paths | 1 |
| Total Lines | 36 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 14 | public function boot() |
||
| 15 | { |
||
| 16 | $this->publishes([ |
||
| 17 | __DIR__.'/../config/laravel-slack-slash-command.php' => config_path('laravel-slack-slash-command.php'), |
||
| 18 | ], 'config'); |
||
| 19 | |||
| 20 | collect(config('laravel-slack-slash-command.commands'))->each(function (array $commandConfig) { |
||
| 21 | |||
| 22 | $this->app['router']->post($commandConfig['url'], function () use ($commandConfig) { |
||
| 23 | |||
| 24 | if (!request()->has('token')) { |
||
| 25 | throw InvalidSlashCommandRequest::tokenNotFound(); |
||
| 26 | } |
||
| 27 | |||
| 28 | if (request()->get('token') != $commandConfig['verification_token']) { |
||
| 29 | throw InvalidSlashCommandRequest::invalidToken(request()->get('token')); |
||
| 30 | } |
||
| 31 | |||
| 32 | $handler = collect($commandConfig['handlers']) |
||
| 33 | ->map(function(string $handlerClassName) { |
||
| 34 | return new $handlerClassName(request()); |
||
| 35 | }) |
||
| 36 | ->filter(function(BaseHandler $handler) { |
||
| 37 | return $handler->canHandleCurrentRequest(); |
||
| 38 | })->first(); |
||
| 39 | |||
| 40 | if (!$handler) { |
||
| 41 | throw RequestCouldNotBeProcessed::noHandlerFound(request()); |
||
| 42 | } |
||
| 43 | |||
| 44 | $response = $handler->handleCurrentRequest(); |
||
| 45 | |||
| 46 | return $response->finalize(); |
||
| 47 | }); |
||
| 48 | }); |
||
| 49 | } |
||
| 50 | |||
| 59 |