/** * {@inheritdoc} */ public function applyDelete(ModelStubInterface $model) { /* @var $dataGatewayMongo \MongoCollection */ $dataGatewayMongo = $model->getDataGateway(); $result = $dataGatewayMongo->remove([]); return $this->handleResult($result); }
/** * {@inheritdoc} */ public function applyWrite(ModelStubInterface $model, array &$data) { unset($data['_id']); /* @var $dataGatewayMongo \MongoCollection */ $dataGatewayMongo = $model->getDataGateway(); $result = $dataGatewayMongo->save($data); return $this->handleResult($result); }
/** * {@inheritdoc} */ public function applyDelete(ModelStubInterface $model) { /* @var $client RestClient */ $client = $model->getDataGateway(); $client->delete($this->getId()); switch ($client->getLastResponse()->getStatusCode()) { case Response::STATUS_CODE_200: case Response::STATUS_CODE_204: return 1; } return null; }
/** * Extract a name in order to be used within datagateway context * * If an object's hydrator is avaliable, then $name will be converted to * a model name using the object's hydrator naming strategy. * Finally, $name will be extracted using the model's hydrator naming * strategy. * * @param ModelStubInterface $model * @param string $name * @throws Exception\RuntimeException * @return string */ protected function extractName(ModelStubInterface $model, $name) { if ($model->getObjectPrototype() instanceof HydratorAwareInterface) { $objectHydrator = $model->getObjectPrototype()->getHydrator(); if (!$objectHydrator || !method_exists($objectHydrator, 'hydrateName')) { throw new Exception\RuntimeException('Object hydrator must be set and must have hydrateName() ' . 'in order to convert a single field'); } $name = $objectHydrator->hydrateName($name); } $modelHydrator = $model->getHydrator(); if (!$modelHydrator || !method_exists($modelHydrator, 'extractName')) { throw new Exception\RuntimeException('Model hydrator must be set and must have extractName() method ' . 'in order to convert a single field'); } return $modelHydrator->extractName($name); }
/** * @param ModelStubInterface $model * @return mixed */ protected function extractId(ModelStubInterface $model) { $hydrator = $model->getHydrator(); if (!method_exists($hydrator, 'extractValue')) { throw new Exception\RuntimeException('Hydrator must have extractValue() method ' . 'in order to extract a single value'); } return $hydrator->extractValue('_id', $this->getId()); }
/** * {@inheritdoc} */ public function apply(ModelStubInterface $model) { /** @var $dataGateway \MongoCollection */ $dataGateway = $model->getDataGateway(); $cursor = $dataGateway->find($this->selectionCriteria, $this->projectionFields); if (!empty($this->sortParams)) { $cursor->sort($this->sortParams); } return $cursor->limit($this->limit)->skip($this->offset); }
/** * Apply * @param ModelStubInterface $model * @return mixed */ public function apply(ModelStubInterface $model) { /* @var $dataGatewayMongo \MongoCollection */ $dataGatewayMongo = $model->getDataGateway(); return $dataGatewayMongo->find()->limit($this->limit)->skip($this->offset); }
/** * {@inheritdoc} */ public function apply(ModelStubInterface $model) { /* @var $client RestClient */ $client = $model->getDataGateway(); $query = $this->getQuery(); if ($this->limit) { $query[$this->pageSizeParamName] = $this->limit; } if ($this->page) { $query[$this->pageParamName] = $this->page; } $result = $client->get(null, $query); $payloadData = $client->getLastResponseData(); if (isset($payloadData[$this->pageSizeParamName])) { $this->limit = (int) $payloadData[$this->pageSizeParamName]; } $this->updateOffset(); return $result; }
/** * {@inheritdoc} */ public function applyDelete(ModelStubInterface $model) { return $this->getDocumentStore()->isolatedRemove($model->getDataGateway(), $this->extractId($model), $this->getMongoOptions()); }