Transform the entity value, which is described by the given attributespec,
to it's output representation.

@param EntityInterface $entity
@param SpecificationInterface $specification

@return mixed
517605
public function apply(EntityInterface $entity, SpecificationInterface $specification)
    {
        $attribute_name = $specification->getOption('attribute', $specification->getName());
        $entity_value = $entity->getValue($attribute_name);

        return $entity_value;
    }
871107
public function transform($entity)
    {
        $data = [];

        if (null === $entity) {
            return $data;
        }

        $accessor = PropertyAccess::createPropertyAccessor();
        $text = is_null($this->textProperty)
            ? (string)$entity
            : $accessor->getValue($entity, $this->textProperty);

        $attr = [];
        foreach ( $this->data as $d ) {
            $value = $accessor->getValue($entity, $d);
            if ( $value instanceof PersistentCollection || $value instanceof ArrayCollection ) {
                $value = $value->first();
            }

            $attr[$d] = $value;
        }

        $data[$accessor->getValue($entity, $this->primaryKey)] = [
            'text' => $text,
            'attr' => $attr
        ];
        return $data;
    }
441651
public function getVersionId(EntityInterface $entity)
    {
        $table = TableRegistry::get($this->_config['versionTable']);
        $preexistent = $table->find()
            ->select(['version_id'])
            ->where([
                    'model' => $this->_config['referenceName']
                ] + $this->_extractForeignKey($entity))
            ->order(['id desc'])
            ->limit(1)
            ->enableHydration(false)
            ->toArray();

        return Hash::get($preexistent, '0.version_id', 0);
    }
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
        ]);
    }
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;
    }
975938
protected function _getTableAlias(EntityInterface $entity)
    {
        $alias = $entity->source();
        if (mb_strpos($alias, '.') !== false) {
            $parts = explode('.', $alias);
            $alias = array_pop($parts);
        }

        return strtolower($alias);
    }
878442
public function encryptEntity(EntityInterface $entity): EntityInterface
    {
        if (!$this->isEncryptable($entity)) {
            return $entity;
        }

        $fields = $this->getFields();
        $encryptionKey = $this->getConfig('encryptionKey');
        $base64 = $this->getConfig('base64');
        $table = $this->getTable();

        $patch = [];
        foreach ($fields as $name => $field) {
            if (!$table->hasField($name)) {
                continue;
            }
            $value = $entity->get($name);
            if ($value === null || is_resource($value)) {
                continue;
            }
            $encrypted = Security::encrypt($value, $encryptionKey);
            if ($base64 === true) {
                $encrypted = base64_encode($encrypted);
            }
            $patch[$name] = $encrypted;
        }

        if (!empty($patch)) {
            $accessible = array_fill_keys(array_keys($patch), true);
            $entity = $table->patchEntity($entity, $patch, [
                'accessibleFields' => $accessible,
            ]);
        }

        return $entity;
    }
632851
public function delete(EntityInterface $entity)
    {
        $this->entity = $entity;
        $primaryKey = $this->getDescriptor()->getPrimaryKey()->getName();
        $table = $this->getDescriptor()->getTableName();
        $sql = Sql::createSql($this->getAdapter());

        $this->triggerBeforeDelete($entity);

        $this->setUpdateCriteria(
            $sql->delete($table),
            $primaryKey,
            $table
        )->execute();

        $this->triggerAfterDelete($entity);
        $this->removeEntity($entity);
        return $this;
    }
1316052
public function transform($entity)
    {
        if (null === $entity || '' === $entity) {
            return null;
        }

        if (!is_object($entity)) {
            throw new UnexpectedTypeException($entity, 'object');
        }

        //Here, do not put the result in the cache because we must check the value in
        //reverseTransform (by QueryBuilder)

        return $this->accessor->getValue($entity, $this->identifier);
    }
1277001
protected function _save(EntityInterface $entity)
    {
        $entity = $this->_table()->patchEntity(
            $entity,
            ['verified' => true],
            $this->saveOptions()
        );
        $subject = $this->_subject(['entity' => $entity]);

        $this->_trigger('beforeSave', $subject);

        $success = call_user_func(
            [$this->_table(), $this->saveMethod()],
            $entity,
            $this->saveOptions()
        );

        $this->_trigger('afterSave', $subject);

        return $success;
    }
730328
protected function getSlugForEntity(EntityInterface $entity, ParametersCollection $configuration)
    {
        $parts = [];
        
        foreach ($configuration->offsetGet('properties') as $property) {
            if ($entity->hasProperty($property)) {
                $parts[] = Transliterator::urlize(Transliterator::transliterate($entity->getByProperty($property)));
            }
        }
        
        $string = implode($configuration->offsetGet('separator'), $parts);
        
        return sprintf('%s%s%s', $configuration->get('prefix'), $string, $configuration->get('suffix'));
    }
644778
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof Role) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', Role::class)
            );
        }

        $this->validateRole($entity->getRole());
        $this->validateLabel($entity->getLabel());
        $this->validateUserCreated($entity->getUserCreated());
        $errors = $this->getErrors();

        return empty($errors);
    }
1372583
protected function generateBody(Entity $entity)
    {
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];
        $extLines   = $this->generateExtensionsSerializedSize($entity);

        $body[] = '$calculator = $context->getSizeCalculator();';
        $body[] = '$size       = 0;';
        $body[] = null;

        foreach ($fields as $field) {
            $lines = $this->generateFieldCondition($entity, $field);
            $body  = array_merge($body, $lines, [null]);
        }

        $body   = array_merge($body, $extLines);
        $body[] = null;
        $body[] = 'return $size;';

        return $body;
    }
427174
private function getFieldValue($entity, \ReflectionProperty $reflectionProperty)
    {
        $value = null;
        if ($reflectionProperty) {
            $reflectionProperty->setAccessible(true);
            $value = $reflectionProperty->getValue($entity);
        }

        return $value;
    }
1042039
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof ApplicationGroup) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', Role::class)
            );
        }

        $this->validateName($entity->getName());
        $errors = $this->getErrors();

        return empty($errors);
    }
355179
protected function getConditions(EntityInterface $entity)
    {
        $field = "{$this->getParentTableName()}.{$this->getForeignKey()}";
        $property = $this->getPropertyName();
        $conditions = [
            "{$field} = :{$property}" => [
                ":{$property}" => $entity->getId()
            ]
        ];
        return $conditions;
    }
358298
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof UserGroup) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', Role::class)
            );
        }

        $this->validateName($entity->getName());
        $this->validateDefaultRole($entity->getDefaultRole());
        $errors = $this->getErrors();

        return empty($errors);
    }