Example #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');
     }
 }
Example #2
0
 public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context)
 {
     // parse json
     $parser = $this->templateFactory->newTextParser();
     $response = $parser->parse($request, $context, $configuration->get('patch'));
     // patch
     $patch = new Patch(Json::decode($response, false));
     $body = $patch->patch(Transformer::toStdClass($request->getBody()));
     $body = Transformer::toRecord($body);
     return $this->processor->execute($configuration->get('action'), $request->withBody($body), $context);
 }
Example #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');
     }
 }
Example #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');
     }
 }
Example #5
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');
     }
 }
Example #6
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');
     }
 }
Example #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();
             $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');
     }
 }