/** * Execute an action. * * @param TableBuilder $builder * @param ActionInterface $action * @throws \Exception */ public function execute(TableBuilder $builder, ActionInterface $action) { $options = $builder->getTableOptions(); $handler = $action->getHandler(); // Self handling implies @handle if (is_string($handler) && !str_contains($handler, '@')) { $handler .= '@handle'; } /* * Authorize the action. */ if (!$this->authorizer->authorize($action->getPermission())) { $this->messages->error('streams::message.403'); return; } /* * Get the IDs of the selected rows. */ $selected = $this->request->get($options->get('prefix') . 'id', []); /* * If the handler is a callable string or Closure * then call it using the IoC container. */ if (is_string($handler) || $handler instanceof \Closure) { if (is_string($handler) && class_exists($handler)) { $handler .= '@handle'; } app()->call($handler, compact('builder', 'selected')); return; } /* * If the handle is an instance of ActionHandlerInterface * simply call the handle method on it. */ if ($handler instanceof ActionHandlerInterface) { $handler->handle($builder, $selected); return; } throw new \Exception('Action $handler must be a callable string, Closure or ActionHandlerInterface.'); }