/** * @return bool|mixed * @throws \DreamFactory\Core\Events\Exceptions\ScriptException * @throws \DreamFactory\Core\Exceptions\BadRequestException * @throws \DreamFactory\Core\Exceptions\InternalServerErrorException */ protected function processRequest() { // Now all actions must be HTTP verbs if (!Verbs::contains($this->action)) { throw new BadRequestException('The action "' . $this->action . '" is not supported.'); } $logOutput = $this->request->getParameterAsBool('log_output', true); $data = ['request' => $this->request->toArray()]; $output = null; $result = ScriptEngineManager::runScript($this->content, 'script.' . $this->name, $this->engineConfig, $this->scriptConfig, $data, $output); if (!empty($output) && $logOutput) { \Log::info("Script '{$this->name}' output:" . PHP_EOL . $output . PHP_EOL); } // Bail on errors... if (is_array($result) && isset($result['script_result'], $result['script_result']['error'])) { throw new InternalServerErrorException($result['script_result']['error']); } if (is_array($result) && isset($result['exception'])) { throw new InternalServerErrorException(ArrayUtils::get($result, 'exception', '')); } // The script runner should return an array if (is_array($result) && isset($result['__tag__'])) { $scriptResult = ArrayUtils::get($result, 'script_result', []); return $scriptResult; } else { Log::error(' * Script did not return an array: ' . print_r($result, true)); } return $output; }
/** * @param string $name * @param array $event * * @return array|null * @throws InternalServerErrorException * @throws \DreamFactory\Core\Events\Exceptions\ScriptException */ protected function handleEventScript($name, &$event) { $model = EventScript::with('script_type_by_type')->whereName($name)->whereIsActive(true)->first(); if (!empty($model)) { $output = null; $result = ScriptEngineManager::runScript($model->content, $name, $model->script_type_by_type->toArray(), ArrayUtils::clean($model->config), $event, $output); // Bail on errors... if (is_array($result) && isset($result['script_result'], $result['script_result']['error'])) { throw new InternalServerErrorException($result['script_result']['error']); } if (is_array($result) && isset($result['exception'])) { throw new InternalServerErrorException(ArrayUtils::get($result, 'exception', '')); } // The script runner should return an array if (!is_array($result) || !isset($result['__tag__'])) { Log::error(' * Script did not return an array: ' . print_r($result, true)); } if (!empty($output)) { Log::info(' * Script "' . $name . '" output:' . PHP_EOL . $output . PHP_EOL); } return $result; } return null; }