/** * 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()); }
/** * @param ModelStubInterface $model * @param $name * @param $value * @param null $object * @return mixed */ protected function extractValue(ModelStubInterface $model, $name, $value, $object = null) { $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($name, $value, $object); }