示例#1
0
 public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
 {
     $connection = $this->connector->getConnection($configuration->get('connection'));
     if ($connection instanceof MongoDB) {
         $collection = $configuration->get('collection');
         $collection = $connection->{$collection};
         if ($collection instanceof MongoCollection) {
             // parse json
             $parser = $this->templateFactory->newTextParser();
             $query = $parser->parse($request, $context, $configuration->get('criteria'));
             $query = !empty($query) ? json_decode($query) : array();
             $fields = $configuration->get('projection');
             $fields = !empty($fields) ? json_decode($fields) : array();
             $result = $collection->findOne($query, $fields);
             if (empty($result)) {
                 throw new NotFoundException('Entry not available');
             }
             return $this->response->build(200, [], $result);
         } else {
             throw new ConfigurationException('Invalid collection');
         }
     } else {
         throw new ConfigurationException('Given connection must be an MongoDB connection');
     }
 }
示例#2
0
 public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $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 $this->response->build(200, [], ['success' => true, 'message' => 'Push was successful']);
     } else {
         throw new ConfigurationException('Given connection must be an Beanstalk connection');
     }
 }
示例#3
0
 public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
 {
     $connection = $this->connector->getConnection($configuration->get('connection'));
     if ($connection instanceof Connection) {
         // parse sql
         $parser = $this->templateFactory->newSqlParser();
         $sql = $parser->parse($request, $context->withConnection($connection), $configuration->get('sql'));
         $connection->executeUpdate($sql, $parser->getSqlParameters());
         return $this->response->build(200, [], array('success' => true, 'message' => 'Execution was successful'));
     } else {
         throw new ConfigurationException('Given connection must be an DBAL connection');
     }
 }
示例#4
0
 public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
 {
     $connection = $this->connector->getConnection($configuration->get('connection'));
     if ($connection instanceof Connection) {
         // parse sql
         $parser = $this->templateFactory->newSqlParser();
         $sql = $parser->parse($request, $context->withConnection($connection), $configuration->get('sql'));
         $result = $connection->fetchAll($sql, $parser->getSqlParameters());
         $key = $configuration->get('propertyName') ?: 'entry';
         return $this->response->build(200, [], [$key => CurveArray::nest($result)]);
     } else {
         throw new ConfigurationException('Given connection must be a DBAL connection');
     }
 }
示例#5
0
文件: MqAmqp.php 项目: uqiauto/fusio
 public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $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 $this->response->build(200, [], array('success' => true, 'message' => 'Push was successful'));
     } else {
         throw new ConfigurationException('Given connection must be an AMQP connection');
     }
 }
示例#6
0
 public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
 {
     $connection = $this->connector->getConnection($configuration->get('connection'));
     if ($connection instanceof Connection) {
         // parse sql
         $parser = $this->templateFactory->newSqlParser();
         $sql = $parser->parse($request, $context->withConnection($connection), $configuration->get('sql'));
         $result = $connection->fetchAssoc($sql, $parser->getSqlParameters());
         if (empty($result)) {
             throw new StatusCode\NotFoundException('Entry not available');
         }
         return $this->response->build(200, [], CurveArray::nest($result));
     } else {
         throw new ConfigurationException('Given connection must be an DBAL connection');
     }
 }
示例#7
0
 public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
 {
     $connection = $this->connector->getConnection($configuration->get('connection'));
     if ($connection instanceof MongoDB) {
         $collection = $connection->selectCollection($configuration->get('collection'));
         if ($collection instanceof MongoCollection) {
             // parse json
             $parser = $this->templateFactory->newTextParser();
             $document = $parser->parse($request, $context, $configuration->get('document'));
             $document = !empty($document) ? json_decode($document) : array();
             $collection->insert($document);
             return $this->response->build(200, [], ['success' => true, 'message' => 'Execution was successful']);
         } else {
             throw new ConfigurationException('Invalid collection');
         }
     } else {
         throw new ConfigurationException('Given connection must be an MongoDB connection');
     }
 }
示例#8
0
 public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
 {
     $connection = $this->connector->getConnection($configuration->get('connection'));
     if ($connection instanceof MongoDB) {
         $collection = $connection->selectCollection($configuration->get('collection'));
         if ($collection instanceof MongoCollection) {
             // parse json
             $parser = $this->templateFactory->newTextParser();
             $query = $parser->parse($request, $context, $configuration->get('criteria'));
             $query = !empty($query) ? json_decode($query) : array();
             $fields = $configuration->get('projection');
             $fields = !empty($fields) ? json_decode($fields) : array();
             $cursor = $collection->find($query, $fields);
             $key = $configuration->get('propertyName') ?: 'entry';
             $sort = $configuration->get('sort');
             if (!empty($sort)) {
                 parse_str($sort, $sortParameters);
                 $sortParameters = array_map(function ($value) {
                     $value = (int) $value;
                     return $value == 1 || $value == -1 ? $value : 1;
                 }, $sortParameters);
                 $cursor->sort($sortParameters);
             }
             $limit = (int) $configuration->get('limit');
             if ($limit > 0) {
                 $cursor->limit($limit);
             }
             $data = array();
             foreach ($cursor as $row) {
                 $data[] = $row;
             }
             return $this->response->build(200, [], [$key => $data]);
         } else {
             throw new ConfigurationException('Invalid collection');
         }
     } else {
         throw new ConfigurationException('Given connection must be an MongoDB connection');
     }
 }