Serialize an entity.

@param AnDomainEntityAbstract $entity

@return array
965895
public function serialize($entity)
    {
        return array($this->getName().'.'.$this->_target_parent_key => $entity->get($this->_target_parent_key));
    }
1360687
public function objectToRequest(EntityInterface $entity)
    {
        $data = $entity->get();

        $properties = [];
        foreach ($data as $key => $value) {
            $exclude = in_array($key, $entity->excludedProperties());
            $meaning = (isset($entity->meanings()[$key]))
                ? $entity->meanings()[$key]
                : null;

            $properties[$key] = $this->valueObject(
                $value,
                $exclude,
                $meaning
            );
        }

        $key = $entity->key()
            ? $entity->key()->keyObject()
            : null;

        return array_filter([
            'key' => $key,
            'properties' => $properties
        ]);
    }
205296
private function getIndexableEntities($entity = null)
    {
        if ($entity) {
            return [$entity];
        }

        $entities = [];
        $namespaces = $this->getContainer()->get('solr.doctrine.classnameresolver.known_entity_namespaces');
        $metaInformationFactory = $this->getContainer()->get('solr.meta.information.factory');

        foreach ($namespaces->getEntityClassnames() as $classname) {
            try {
                $metaInformation = $metaInformationFactory->loadInformation($classname);
                if ($metaInformation->isNested()) {
                    continue;
                }

                array_push($entities, $metaInformation->getClassName());
            } catch (SolrMappingException $e) {
                continue;
            }
        }

        return $entities;
    }
610167
protected function generateExtensionsSerializedSize(Entity $entity)
    {
        $descriptor      = $entity->getDescriptor();
        $extensionsField = $this->getUniqueFieldName($descriptor, 'extensions');

        $body[] = 'if ($this->' . $extensionsField . ' !== null) {';
        $body[] = '    $size += $this->' . $extensionsField . '->serializedSize($context);';
        $body[] = '}';

        return $body;
    }
1035468
protected function generateBody(Entity $entity)
    {
        $lines      = [];
        $fields     = [];
        $extensions = [];
        $descriptor = $entity->getDescriptor();

        if ($descriptor->hasOptions()) {
            $lines   = $this->createOptionsBody($entity);
            $lines[] = null;
        }

        foreach (($descriptor->getFieldList() ?: []) as $field) {
            $values = $this->generateFieldBody($field);
            $fields = array_merge($fields, $this->addIndentation($values, 2));
        }

        foreach (($descriptor->getExtensionList() ?: []) as $field) {
            $values     = $this->generateFieldBody($field);
            $extensions = array_merge($extensions, $this->addIndentation($values, 2));
        }

        $lines[] = "return \google\protobuf\DescriptorProto::fromArray([";
        $lines[] = "    'name'      => " . var_export($descriptor->getName(), true) . ",";

        if ( ! empty($fields)) {
            $lines[] = "    'field'     => [";
            $lines   = array_merge($lines, $fields);
            $lines[] = "    ],";
        }

        if ( ! empty($extensions)) {
            $lines[] = "    'extension' => [";
            $lines   = array_merge($lines, $extensions);
            $lines[] = "    ],";
        }

        if ($descriptor->hasOptions()) {
            $lines[] = "    'options' => \$options";
        }

        $lines[] = "]);";

        return $lines;
    }
1331329
protected function wrapInEntities(array $entities)
    {
        $results = array();
        foreach ($entities as $entity) {
            $results[] = self::getEntity($entity);
        }

        return $results;
    }
940206
private function readClassProperties($entity)
    {
        $className = get_class($entity);
        if (isset($this->entityProperties[$className])) {
            return $this->entityProperties[$className];
        }

        $reflectionClass = new \ReflectionClass($entity);
        $inheritedProperties = array_merge($this->getParentProperties($reflectionClass), $reflectionClass->getProperties());

        $properties = [];
        foreach ($inheritedProperties as $property) {
            $properties[$property->getName()] = $property;
        }

        $this->entityProperties[$className] = $properties;

        return $properties;
    }
722791
public function getData(Entity $entity)
    {
        $column = $this->analyzer->listColumns();
        $data = array();

        foreach ($column as $key => $value) {
            $method = 'get' . Utils::capitalize($key);
            $data[$key] = $entity->$method();
            if (is_null($data[$key])) $data[$key] = array();
            if ($data[$key] instanceof ArrayCollection) $data[$key] = $data[$key]->toArray();
        }

        $data['objectclass'] = $entity->getObjectClass()->toArray();

        return $data;
    }
292253
protected function prepareInsertData($entity) : array
    {
        $data = parent::prepareInsertData($entity);

        // Populate the discriminator column
        $discColumn = $this->class->discriminatorColumn;
        $tableName  = $discColumn->getTableName();
        $columnName = $discColumn->getColumnName();

        $this->columns[$columnName] = $discColumn;

        $data[$tableName][$columnName] = $this->class->discriminatorValue;

        return $data;
    }
166444
public function entityByResult(string $entity): array
    {
        $result = array_get($this->response, "data.result", '');

        return array_get($this->response, "data.entities.$entity.$result", []);
    }
1336543
public function commit($entity)
    {
        switch ($entity->getEntityState()) {
            case AnDomain::STATE_NEW:
                $operation = AnDomain::OPERATION_INSERT;
                $command = 'insert';
                break;
            case AnDomain::STATE_MODIFIED :
                //get all the updated serializable property/value pairs
                $operation = AnDomain::OPERATION_UPDATE;
                $command = 'update';
                break;
            case  AnDomain::STATE_DELETED :
                $operation = AnDomain::OPERATION_DELETE;
                $command = 'delete';
                break;
            default :
                return;
        }

        $context = $this->getCommandContext();
        $context->operation = $operation;
        $context->entity = $entity;
        $context->data = array();
        $store = $this->getStore();

        if ($context->result = $this->getCommandChain()->run('before.'.$command, $context) !== false) {
            $context->data = $entity->getAffectedRowData();

            switch ($operation) {
                case(AnDomain::OPERATION_INSERT) :
                    if (!count($context->data)) {
                        throw new AnDomainRepositoryException('Attempting to store an entity with empty data');
                    }

                    $context->result = $store->insert($this, $context->data);
                    break;

                case(AnDomain::OPERATION_UPDATE) :
                case(AnDomain::OPERATION_DELETE) :

                    $keys = $this->_description->getIdentityProperty()->serialize($entity->getIdentityId());
                    $keys = array($this->_description->getIdentityProperty()->getName() => $entity->getIdentityId());

                    if ($operation & AnDomain::OPERATION_UPDATE) {
                        $context->result = count($context->data) ? $this->update($context->data, $keys) : true;
                    } else {
                        $context->result = $this->destroy($keys);
                    }
            }

            $this->getCommandChain()->run('after.'.$command, $context);
        }

        return    $context->result !== false;
    }
104292
public function getMetaData($entity)
    {
        $propertyAnnotations = [];
        $result = new \stdClass;
        $class = new \ReflectionClass($entity);
        $classAnnotations = $this->_reader->getClassAnnotations($class);
        foreach ($class->getProperties() as $key => $value) {
            $annotation = $this->_reader->getPropertyAnnotations(new \ReflectionProperty($entity, $value->name));
            if (count($annotation)) {
                $propertyAnnotations[$value->name] = array_pop($annotation);
            }
        }

        foreach ($classAnnotations as $annotation) {
            if ($annotation instanceof \MercadoPago\Annotation\RestMethod) {
                $result->methods[$annotation->method] = get_object_vars($annotation);
            }
            if ($annotation instanceof \MercadoPago\Annotation\RequestParam) {
                $result->params[] = $annotation->param;
            }
            if ($annotation instanceof \MercadoPago\Annotation\DenyDynamicAttribute) {
                $result->denyDynamicAttribute = true;
            }
        }

        foreach ($propertyAnnotations as $key => $annotation) {
            if ($annotation instanceof \MercadoPago\Annotation\Attribute) {
                $result->attributes[$key] = get_object_vars($annotation);
            }
        }

        return $result;
    }
1154030
protected function BuildRequestData($entity)
    {
        if (is_a($entity, 'MangoPay\UboDeclaration')) {
            $declaredUboIds = [];
            foreach ($entity->DeclaredUBOs as $declaredUBO) {
                if (is_string($declaredUBO)) {
                    array_push($declaredUboIds, $declaredUBO);
                } else {
                    array_push($declaredUboIds, $declaredUBO->UserId);
                }
            }
            $entity->DeclaredUBOs = $declaredUboIds;
        }
        $entityProperties = get_object_vars($entity);
        $blackList = $entity->GetReadOnlyProperties();
        $requestData = array();
        foreach ($entityProperties as $propertyName => $propertyValue) {
            if (in_array($propertyName, $blackList)) {
                continue;
            }

            if ($this->CanReadSubRequestData($entity, $propertyName)) {
                $subRequestData = $this->BuildRequestData($propertyValue);
                foreach ($subRequestData as $key => $value) {
                    $requestData[$key] = $value;
                }
            } else {
                if (isset($propertyValue)) {
                    $requestData[$propertyName] = $propertyValue;
                }
            }
        }

        if (count($requestData) == 0) {
            return new \stdClass();
        }

        return $requestData;
    }
281365
public function load($properties = array())
    {
        $keys = $this->getIdentifyingData();

        if (empty($keys)) {
            throw new AnDomainEntityException('Trying to load an entity without any identifying data');
        }

        //prevent from creating two differne entities
        if (!$this->_persisted) {
            //if found another entity
            $entity = $this->getRepository()->find($keys, false);

            if ($entity && $entity !== $this) {
                $this->reset();

                return $entity->load($properties);
            }
        }

        settype($properties, 'array');

        if (empty($properties)) {
            //only load serializbale properties (i.e. attributes, many to one relationships)
            $properties = array();

            foreach ($this->getEntityDescription()->getProperty() as $property) {
                if ($property->isSerializable()) {
                    $properties[] = $property->getName();
                }
            }

            $keys = array_keys($this->getEntityDescription()->getIdentifyingProperties());
            $properties = array_diff($properties, $keys);
        }

        if ($this->_data->load($properties)) {
            //enttiy has been fetched for the first time
            if (!$this->_persisted) {
                $keys = $this->getIdentifyingData();
                $this->_persisted = true;
                $this->getRepository()->getSpace()->insertEntity($this, $keys);
                $this->reset();
            } else {
                //the loaded properties are no longer modified
                foreach ($properties as $property) {
                    unset($this->_modified[$property]);
                }

                //reset the element if there are no modified
                if (count($this->_modified) === 0) {
                    $this->reset();
                }
            }
        } else {
            //if a persisted entity can not be loaded then
            //it must mean the data doesn't exists in the store
            //can we assume then the data has been somehow deleted ?
            //if that's the case then we need to set the state to destroyed
            if ($this->persisted()) {
                $this->getRepository()->getSpace()->setEntityState($this, AnDomain::STATE_DESTROYED);
            } else {
                $this->reset();
            }
        }

        return $this;
    }
813107
public function getOriginalEntityData($entity)
    {
        $oid = spl_object_hash($entity);

        if (isset($this->originalEntityData[$oid])) {
            return $this->originalEntityData[$oid];
        }

        return array();
    }
560281
public function saveAttendee(array $entity): array
    {
        $response = [
            'status' => false,
            'errors' => [],
            'entity' => null,
        ];

        if (empty($entity['id'])) {
            unset($entity['id']);
        }

        $query = $this->find()
            ->where([
                'source' => $entity['source'],
                'source_id' => $entity['source_id'],
                'contact_details' => $entity['contact_details'],
            ]);

        $query->execute();

        if (!$query->count()) {
            $item = $this->newEntity();
            $item = $this->patchEntity($item, $entity);
        } else {
            $item = $query->firstOrFail();
            if (!($item instanceof EntityInterface)) {
                throw new RuntimeException('Expected instance of EntityInterface');
            }
            $item = $this->patchEntity($item, $entity);
        }

        $saved = $this->save($item);

        if ($saved) {
            $response['status'] = true;
            $response['entity'] = $saved;
        } else {
            $response['errors'] = $item->getErrors();
        }

        return $response;
    }
795144
protected function getTableColumns($entity)
    {
        $columnClause = [];

        // Get all columns for insertion
        $allColumns = array_merge($this->requiredTableColumns($entity), $this->columns);

        // Set values for columns
        foreach ($allColumns as $col => $type) {
            $columnClause[$col] = isset($this->columns[$col]) ?
                $this->quoteOrNot($this->columns[$col]) :
                $this->sampleData($type);
        }

        $columnNames = implode(', ', array_keys($columnClause));
        $columnValues = implode(', ', $columnClause);

        return [$columnNames, $columnValues];
    }