public function handle(Request $request, Parameters $configuration, Context $context) { $response = $this->processor->execute($configuration->get('source'), $request, $context); $visitor = new StdClassSerializeVisitor(); $traverser = new GraphTraverser(); $traverser->traverse($response->getBody(), $visitor); $importer = $this->importerManager->getImporterByInstance('PSX\\Data\\Record\\Importer\\Record'); $body = $importer->import(new Record(), $visitor->getObject()); return $this->processor->execute($configuration->get('destination'), $request->withBody($body), $context); }
/** * @param \Fusio\Parameters $config * @return \MongoDB */ public function getConnection(Parameters $config) { $rawOptions = $config->get('options'); if (!empty($rawOptions)) { parse_str($rawOptions, $options); $client = new MongoClient($config->get('url'), $options); } else { $client = new MongoClient($config->get('url')); } return $client->selectDB($config->get('database')); }
public function handle(Request $request, Parameters $configuration, Context $context) { $condition = $configuration->get('condition'); $language = new ExpressionLanguage($this); $values = array('rateLimit' => new RateLimit($this->connection, $context), 'app' => $context->getApp(), 'routeId' => $context->getRouteId(), 'uriFragments' => $request->getUriFragments(), 'parameters' => $request->getParameters(), 'body' => new Accessor(new Validate(), $request->getBody())); if (!empty($condition) && $language->evaluate($condition, $values)) { return $this->processor->execute($configuration->get('true'), $request, $context); } else { return $this->processor->execute($configuration->get('false'), $request, $context); } }
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 Pheanstalk) { $writer = new Writer\Json(); $body = $writer->write($request->getBody()); $connection->useTube($configuration->get('queue'))->put($body); return new Response(200, [], array('success' => true, 'message' => 'Push was successful')); } else { throw new ConfigurationException('Given connection must be an Beanstalk connection'); } }
/** * @param integer $actionId * @param \Fusio\Request $request * @param \Fusio\Context $context * @return \Fusio\Response */ public function execute($actionId, Request $request, Context $context) { $action = $this->connection->fetchAssoc('SELECT id, name, class, config, date FROM fusio_action WHERE id = :id', array('id' => $actionId)); if (empty($action)) { throw new ConfigurationException('Invalid action'); } $config = !empty($action['config']) ? unserialize($action['config']) : array(); $parameters = new Parameters($config); $parameters->set(Parameters::ACTION_ID, $action['id']); $parameters->set(Parameters::ACTION_NAME, $action['name']); $parameters->set(Parameters::ACTION_LAST_MODIFIED, $action['date']); return $this->factory->factory($action['class'])->handle($request, $parameters, $context); }
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) { $key = md5($configuration->get('action')); $item = $this->cache->getItem($key); if (!$item->isHit()) { $response = $this->processor->execute($configuration->get('action'), $request, $context); $item->set($response, $configuration->get('expire')); $this->cache->save($item); } else { $response = $item->get(); } return $response; }
public function handle(Request $request, Parameters $configuration, Context $context) { $connection = $this->connector->getConnection($configuration->get('connection')); if ($connection instanceof AMQPStreamConnection) { $writer = new Writer\Json(); $body = $writer->write($request->getBody()); $message = new AMQPMessage($body, array('content_type' => $writer->getContentType(), 'delivery_mode' => 2)); $channel = $connection->channel(); $channel->basic_publish($message, '', $configuration->get('queue')); return new Response(200, [], array('success' => true, 'message' => 'Push was successful')); } else { throw new ConfigurationException('Given connection must be an AMQP 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->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'); } }
public function parse(Request $request, Parameters $configuration, Context $context, $data) { $cacheKey = $configuration->get(Parameters::ACTION_ID); $lastModified = $configuration->get(Parameters::ACTION_LAST_MODIFIED); $this->loader->set($data, $cacheKey, $lastModified); $this->twig->getFilter(Prepare::FILTER_NAME)->getCallable()->clear(); try { return $this->twig->render($configuration->get(Parameters::ACTION_ID), ['request' => $request, 'context' => $context, 'body' => new Accessor(new Validate(), $request->getBody())]); } catch (\Twig_Error_Runtime $e) { // if we have an display exception throw the original exception if ($e->getPrevious() instanceof DisplayException) { throw $e->getPrevious(); } else { throw $e; } } }
/** * @param \Fusio\Parameters $config * @return \MongoDB */ public function getConnection(Parameters $config) { return new Pheanstalk($config->get('host')); }
/** * @param \Fusio\Parameters $config * @return \Doctrine\DBAL\Connection */ public function getConnection(Parameters $config) { return DriverManager::getConnection(array('url' => $config->get('url'))); }
/** * @param \Fusio\Parameters $config * @return \Doctrine\DBAL\Connection */ public function getConnection(Parameters $config) { $params = array('dbname' => $config->get('database'), 'user' => $config->get('username'), 'password' => $config->get('password'), 'host' => $config->get('host'), 'driver' => $config->get('type')); return DriverManager::getConnection($params); }
public function handle(Request $request, Parameters $configuration, Context $context) { $this->processor->execute($configuration->get('in'), $request, $context); return $this->processor->execute($configuration->get('out'), $request, $context); }
/** * @param \Fusio\Parameters $config * @return \MongoDB */ public function getConnection(Parameters $config) { return new AMQPStreamConnection($config->get('host'), $config->get('port'), $config->get('user'), $config->get('password'), $config->get('vhost')); }