script = $script; $this->current_user = $current_user; $this->code = $code; $this->data = $data; $this->configuration = $configuration; $this->nonce = $nonce; } /** * Execute the script task. * * @return void */ public function handle() { try { // Just set the code but do not save the object (preview only) $this->script->code = $this->code; $response = $this->script->runScript($this->data, $this->configuration); $this->sendResponse(200, $response); } catch (Throwable $exception) { $this->sendResponse(500, [ 'exception' => get_class($exception), 'message' => $exception->getMessage(), ]); } } /** * Send a response to the user interface * * @param int $status * @param array $response */ private function sendResponse($status, array $response) { event(new ScriptResponseEvent($this->current_user, $status, $response, null, $this->nonce)); } }