コード例 #1
0
ファイル: Pipe.php プロジェクト: virusvn/fusio
 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);
 }
コード例 #2
0
ファイル: MongoDB.php プロジェクト: virusvn/fusio
 /**
  * @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'));
 }
コード例 #3
0
ファイル: Condition.php プロジェクト: virusvn/fusio
 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);
     }
 }
コード例 #4
0
ファイル: SqlExecute.php プロジェクト: virusvn/fusio
 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');
     }
 }
コード例 #5
0
ファイル: BeanstalkPush.php プロジェクト: virusvn/fusio
 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');
     }
 }
コード例 #6
0
ファイル: Processor.php プロジェクト: virusvn/fusio
 /**
  * @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);
 }
コード例 #7
0
ファイル: SqlFetchAll.php プロジェクト: saakaifoundry/fusio
 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');
     }
 }
コード例 #8
0
ファイル: CacheResponse.php プロジェクト: virusvn/fusio
 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;
 }
コード例 #9
0
ファイル: RabbitMqPush.php プロジェクト: virusvn/fusio
 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');
     }
 }
コード例 #10
0
ファイル: SqlFetchRow.php プロジェクト: saakaifoundry/fusio
 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');
     }
 }
コード例 #11
0
ファイル: Parser.php プロジェクト: virusvn/fusio
 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;
         }
     }
 }
コード例 #12
0
ファイル: Beanstalk.php プロジェクト: virusvn/fusio
 /**
  * @param \Fusio\Parameters $config
  * @return \MongoDB
  */
 public function getConnection(Parameters $config)
 {
     return new Pheanstalk($config->get('host'));
 }
コード例 #13
0
ファイル: DBALAdvanced.php プロジェクト: virusvn/fusio
 /**
  * @param \Fusio\Parameters $config
  * @return \Doctrine\DBAL\Connection
  */
 public function getConnection(Parameters $config)
 {
     return DriverManager::getConnection(array('url' => $config->get('url')));
 }
コード例 #14
0
ファイル: DBAL.php プロジェクト: virusvn/fusio
 /**
  * @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);
 }
コード例 #15
0
ファイル: Composite.php プロジェクト: virusvn/fusio
 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);
 }
コード例 #16
0
ファイル: RabbitMQ.php プロジェクト: virusvn/fusio
 /**
  * @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'));
 }