Пример #1
0
 /**
  * Converts document or (nested) object to an array.
  *
  * @param object $object
  * @param array  $propertiesMetadata
  *
  * @return array
  */
 public function convertToArray($object, $propertiesMetadata = [])
 {
     if (empty($propertiesMetadata)) {
         $propertiesMetadata = $this->documentMetadata->getPropertiesMetadata();
     }
     $array = [];
     // Special fields.
     if ($object instanceof DocumentInterface) {
         $this->setArrayFields($array, $object, ['_id', '_parent', '_ttl']);
     }
     // Variable $name defined in client.
     foreach ($propertiesMetadata as $name => $propertyMetadata) {
         $value = $this->getPropertyAccessor()->getValue($object, $propertyMetadata['propertyName']);
         if (isset($value)) {
             if (array_key_exists('propertiesMetadata', $propertyMetadata)) {
                 $new = [];
                 if ($propertyMetadata['multiple']) {
                     $this->isTraversable($value);
                     foreach ($value as $item) {
                         $this->checkVariableType($item, [$propertyMetadata['className']]);
                         $new[] = $this->convertToArray($item, $propertyMetadata['propertiesMetadata']);
                     }
                 } else {
                     $this->checkVariableType($value, [$propertyMetadata['className']]);
                     $new = $this->convertToArray($value, $propertyMetadata['propertiesMetadata']);
                 }
                 $value = $new;
             }
             if ($value instanceof \DateTime) {
                 $value = $value->format(isset($propertyMetadata['format']) ? $propertyMetadata['format'] : \DateTime::ISO8601);
             }
             if ($value instanceof MLProperty) {
                 foreach ($value->getValues() as $language => $langValue) {
                     $array[$name . $this->languageSeparator . $language] = $langValue;
                 }
             } else {
                 $array[$name] = $value;
             }
         }
     }
     return $array;
 }
Пример #2
0
 /**
  * Removes a single document data by ID.
  *
  * @param string $id Document ID to remove.
  *
  * @return array
  *
  * @throws \LogicException
  */
 public function remove($id)
 {
     $params = ['index' => $this->getManager()->getWriteAlias(), 'type' => $this->metadata->getType(), 'id' => $id];
     $response = $this->getManager()->getConnection()->getClient()->delete($params);
     return $response;
 }
 /**
  * Sets the metadata for a combination of a real/physical index name and a type
  *
  * @param DocumentMetadata $documentMetadata
  * @param string           $realIndex        The physical index name
  */
 public function setTypeMetadata(DocumentMetadata $documentMetadata, $realIndex = null)
 {
     $this->metadata[$realIndex ?: '*'][$documentMetadata->getType()] = $documentMetadata;
 }