public function handle(Request $request, Parameters $configuration, Context $context) { // parse json $response = $this->templateParser->parse($request, $configuration, $context, $configuration->get('response')); if (!empty($response)) { $statusCode = $configuration->get('statusCode') ?: 200; return new Response($statusCode, [], Json::decode($response, false)); } else { throw new ConfigurationException('No response defined'); } }
public function handle(Request $request, Parameters $configuration, Context $context) { $connection = $this->connector->getConnection($configuration->get('connection')); if ($connection instanceof Connection) { // parse sql $sql = $this->templateParser->parse($request, $configuration, $context, $configuration->get('sql')); $connection->executeUpdate($sql, $this->templateParser->getSqlParameters()); return new Response(200, [], array('success' => true, 'message' => 'Execution was successful')); } else { throw new ConfigurationException('Given connection must be an DBAL connection'); } }
public function handle(Request $request, Parameters $configuration, Context $context) { $connection = $this->connector->getConnection($configuration->get('connection')); if ($connection instanceof Connection) { // parse sql $sql = $this->templateParser->parse($request, $configuration, $context->withConnection($connection), $configuration->get('sql')); $result = $connection->fetchAll($sql, $this->templateParser->getSqlParameters()); $key = $configuration->get('propertyName') ?: 'entry'; return new Response(200, [], [$key => CurveArray::nest($result)]); } else { throw new ConfigurationException('Given connection must be a DBAL connection'); } }
public function handle(Request $request, Parameters $configuration, Context $context) { // parse json $headers = array('User-Agent' => 'Fusio'); $body = $this->templateParser->parse($request, $configuration, $context, $configuration->get('body')); $request = new PostRequest($configuration->get('url'), $headers, $body); $response = $this->http->request($request); if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) { return new Response(200, [], ['success' => true, 'message' => 'Request successful']); } else { return new Response(500, [], ['success' => false, 'message' => 'Request failed']); } }
public function handle(Request $request, Parameters $configuration, Context $context) { $connection = $this->connector->getConnection($configuration->get('connection')); if ($connection instanceof Connection) { // parse sql $sql = $this->templateParser->parse($request, $configuration, $context->withConnection($connection), $configuration->get('sql')); $result = $connection->fetchAssoc($sql, $this->templateParser->getSqlParameters()); if (empty($result)) { throw new StatusCode\NotFoundException('Entry not available'); } return new Response(200, [], CurveArray::nest($result)); } else { throw new ConfigurationException('Given connection must be an DBAL connection'); } }