Formats an entity's attributes to the SDK's native data structure.

@param \Cpliakas\DynamoDb\ODM\EntityInterface $entity
@param string $format

@return array
160353
protected function formatEntityAttributes(EntityInterface $entity, $format = Attribute::FORMAT_PUT)
    {
        return $this->formatAttributes(get_class($entity), $entity->getAttributes());
    }
631533
public function normalize($object, $format = null, array $context = [])
    {
        $normalized = (array) parent::normalize($object, $format, $context);

        $entityReferenceProperties = $this->getNestedObjectProperties($object);

        if (!empty($entityReferenceProperties)) {
            foreach ($entityReferenceProperties as $entityProperty => $normalizedProperty) {
                // Ensure we do not send the complete referenced entity object
                // only the referenced entity id.
                if (isset($normalized[$normalizedProperty]->id)) {
                    $normalized[$normalizedProperty] = [
                        'id' => $normalized[$normalizedProperty]->id,
                    ];
                }
            }
        }

        // Set missing ids of referenced entities passed by controllers.
        // Ex.: in case of entity create.
        // @see \Apigee\Edge\Api\Monetization\Controller\EntityCreateOperationControllerTrait::buildContextForEntityTransformerInCreate()
        if (!empty($context[self::MINT_ENTITY_REFERENCE_PROPERTY_VALUES])) {
            foreach ($context[self::MINT_ENTITY_REFERENCE_PROPERTY_VALUES] as $entityProperty => $value) {
                if (!isset($normalized[$entityProperty]['id'])) {
                    $normalized[$entityProperty] = [
                        'id' => $value,
                    ];
                }
            }
        }

        return (object) $normalized;
    }
783102
public function set(EntityInterface $entity): string
    {
        $hash = $entity->calculateHash();
        $content = $this->encodeContent($entity->writeData());
        $this->saveContent($hash, $content);
        return $hash;
    }
991110
public function getAttributes($entity)
    {
        if ($entity->has($this->idField)) {
            $hidden = array_merge($entity->getHidden(), [$this->idField]);
            $entity->setHidden($hidden);
        }

        $attributes = $entity->toArray();

        // remove associated data so it won't appear inside jsonapi `attributes`
        foreach ($this->_repository->associations() as $association) {
            $propertyName = $association->getProperty();

            if ($association->type() === Association::MANY_TO_ONE) {
                $foreignKey = $association->getForeignKey();
                unset($attributes[$foreignKey]);
            }

            unset($attributes[$propertyName]);
        }

        // dasherize attribute keys (like `created_by`) if need be
        if ($this->_view->viewVars['_inflect'] === 'dasherize') {
            foreach ($attributes as $key => $value) {
                $dasherizedKey = Inflector::dasherize($key);

                if (!array_key_exists($dasherizedKey, $attributes)) {
                    $attributes[$dasherizedKey] = $value;
                    unset($attributes[$key]);
                }
            }
        }

        return $attributes;
    }
731954
protected function _formatAttributes(array $attributes, ItemInterface $item)
    {
        if (!empty($attributes)) {
            return $this->templater()->formatAttributes(
                $attributes + ['escape' => $item->getExtra('escape', true)]
            );
        }

        return '';
    }
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;
    }
491575
public function fields(EntityInterface $entity)
    {
        $fields = [];
        foreach ((array)$this->getConfig('fields') as $field) {
            if (!$entity->isDirty($field)) {
                continue;
            }
            $fields[$field] = $entity->$field;
            $entity->setDirty($field, false);
        }

        return $fields;
    }
257273
public function generateMethods(Entity $entity)
    {
        $methods    = [];
        $descriptor = $entity->getDescriptor();
        $values     = $descriptor->getValueList() ?: [];

        foreach ($values as $value) {
            $methods[] = $this->generateMethod($entity, $value);
        }

        $methods[] = $this->generateValueOfMethod($entity);

        return $methods;
    }
225733
public function getAttributes($objectOrClass, $format = null, array $context)
    {
        $class = is_object($objectOrClass) ? get_class($objectOrClass) : $objectOrClass;

        /** @var ClassMetadata $meta */
        $meta = $this->entityMetadataFactory->getMetadataFor($class);

        $fields = array_keys($meta->fieldMappings);
        $fields = array_filter($fields, function ($name) { return strpos($name, '.') === false; });
        $embedded = array_keys($meta->embeddedClasses);
        $associations = array_keys($meta->associationMappings);

        return array_merge($fields, $embedded, $associations);
    }
177492
protected function _validation(EntityInterface $entity)
    {
        $validator = new Validator();
        $hasErrors = false;

        foreach ($this->_attributesForEntity($entity) as $attr) {
            $field = $this->_prepareMockField($entity, $attr);
            $result = $field->validate($validator);

            if ($result === false) {
                $this->attachEntityFields($entity);

                return false;
            }

            $errors = $validator->errors($entity->toArray(), $entity->isNew());
            $entity->errors($errors);

            if (!empty($errors)) {
                $hasErrors = true;
                if ($entity->has('_fields')) {
                    $entityErrors = $entity->errors();
                    foreach ($entity->get('_fields') as $field) {
                        $postData = $entity->get($field->name);
                        if (!empty($entityErrors[$field->name])) {
                            $field->set('value', $postData);
                            $field->metadata->set('errors', (array)$entityErrors[$field->name]);
                        }
                    }
                }
            }
        }

        return !$hasErrors;
    }
756872
private function getComponents($object, ?string $format, array $context): array
    {
        $cacheKey = $this->getObjectClass($object).'-'.$context['cache_key'];

        if (isset($this->componentsCache[$cacheKey])) {
            return $this->componentsCache[$cacheKey];
        }

        $attributes = parent::getAttributes($object, $format, $context);
        $options = $this->getFactoryOptions($context);

        $components = [
            'states' => [],
            'links' => [],
            'embedded' => [],
        ];

        foreach ($attributes as $attribute) {
            $propertyMetadata = $this->propertyMetadataFactory->create($context['resource_class'], $attribute, $options);

            $type = $propertyMetadata->getType();
            $isOne = $isMany = false;

            if (null !== $type) {
                if ($type->isCollection()) {
                    $valueType = $type->getCollectionValueType();
                    $isMany = null !== $valueType && ($className = $valueType->getClassName()) && $this->resourceClassResolver->isResourceClass($className);
                } else {
                    $className = $type->getClassName();
                    $isOne = $className && $this->resourceClassResolver->isResourceClass($className);
                }
            }

            if (!$isOne && !$isMany) {
                $components['states'][] = $attribute;
                continue;
            }

            $relation = ['name' => $attribute, 'cardinality' => $isOne ? 'one' : 'many'];
            if ($propertyMetadata->isReadableLink()) {
                $components['embedded'][] = $relation;
            }

            $components['links'][] = $relation;
        }

        if (false !== $context['cache_key']) {
            $this->componentsCache[$cacheKey] = $components;
        }

        return $components;
    }
466522
protected function applyCustomFormat($format, $data)
    {
        $aClassFunc = $this->getFuncParams($format);

        $params = array_key_exists(
            'params',
            $format
        ) ? $format['params'] : [];

        array_unshift($params, $data);

        $object = (new \ReflectionClass($aClassFunc['class']))->newInstance();

        $data = call_user_func_array([$object, $aClassFunc['method']], $params);

        return $data;
    }
1060399
public function format($entities) {
		$data = array(
			'models' => array(),
			'images' => array(),
			'links' => array()
		);

		if(! is_array($entities)) {
			$entities = array($entities->getId() => $entities);
		}

		foreach ($entities as $entity) {
			if($entity instanceof \Application\Togu\ApplicationModelsBundle\Document\Page) {
				foreach ($entity->getAllSections() as $section) {
					$entities[$section->getId()] = $section;
				}
			}
		}

		foreach ($entities as $entity) {
			$this->processor->getAllObjects($entity, $data['models']);
			$this->processor->getFieldValuesOfType($entity, 'image', $data['images']);
			$this->processor->getFieldValuesOfType($entity, 'link', $data['links']);
		}

		$this->convertLinks($data['links']);

		return $data;
	}
372598
public function transform(FieldTypeInterface $form)
    {
        return [
            'attributes' => $form->getAttributes(),
            'flush' => $form->getOption('flush', true),
            'locale' => $form->getLocale(),
            'nonce' => $form->getOption('nonce', '_themosisnonce'),
            'referer' => $form->getOption('referer', true),
            'tags' => $form->getOption('tags', true),
            'theme' => $form->getOption('theme', 'themosis'),
            'type' => $form->getType(),
            'validation' => [
                'errors' => $form->getOption('errors', true),
                'isValid' => $form->isValid()
            ]
        ];
    }
166444
public function entityByResult(string $entity): array
    {
        $result = array_get($this->response, "data.result", '');

        return array_get($this->response, "data.entities.$entity.$result", []);
    }
70221
protected function generateDefaultValues(Entity $entity)
    {
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];
        $size       = count($fields);
        $lines      = [];

        foreach ($fields as $i => $field) {
            $name  = $field->getName();
            $comma = ($i +1 < $size) ? ',' : '';
            $value = $this->getDefaultFieldValue($field);

            // required field throw InvalidArgumentException
            if ($field->getLabel() === Label::LABEL_REQUIRED()) {
                continue;
            }

            if ($field->getLabel() === Label::LABEL_REPEATED()) {
                $value = '[]';
            }

            $lines[] = "'$name' => $value" . $comma;
        }

        return $lines;
    }
1221424
protected function dehydrate($entity): array
    {
        $properties = $this->hydrator->extract($entity);

        $attributesName = $this->entityMap->getAttributesArrayName();

        if (isset($properties[$attributesName])) {
            $properties[$attributesName] = $this->entityMap->getColumnNamesFromAttributes($properties[$attributesName]);
        } else {
            $properties[$attributesName] = $this->entityMap->getColumnNamesFromAttributes($properties);
        }

        $this->properties = $properties;

        $this->unmanagedProperties = array_except($properties, $this->getManagedProperties());

        return $this->attributesFromProperties($properties);
    }