Nextras\Orm\Mapper\Dbal\DbalMapper::entityToArray PHP Method

entityToArray() protected method

protected entityToArray ( Nextras\Orm\Entity\IEntity $entity )
$entity Nextras\Orm\Entity\IEntity
    protected function entityToArray(IEntity $entity)
    {
        $return = [];
        $metadata = $entity->getMetadata();
        foreach ($metadata->getProperties() as $name => $metadataProperty) {
            if ($metadataProperty->isVirtual) {
                continue;
            } elseif ($metadataProperty->isPrimary && ($entity->isPersisted() || !$entity->hasValue($name))) {
                continue;
            } elseif ($entity->isPersisted() && !$entity->isModified($name)) {
                continue;
            }
            if ($metadataProperty->relationship !== null) {
                $rel = $metadataProperty->relationship;
                $canSkip = $rel->type === Relationship::ONE_HAS_MANY || $rel->type === Relationship::MANY_HAS_MANY || $rel->type === Relationship::ONE_HAS_ONE && !$rel->isMain;
                if ($canSkip) {
                    continue;
                }
            }
            $property = $entity->getProperty($name);
            if ($property instanceof IProperty) {
                $value = $property->getRawValue();
            } else {
                $value = $entity->getValue($name);
            }
            $return[$name] = $value;
        }
        return $return;
    }