public static function toArray(IEntity $entity, int $type = self::RELATIONSHIP_AS_IS, int $recursionLevel = 0): array
	{
		$return = [];
		$metadata = $entity->getMetadata();

		foreach ($metadata->getProperties() as $name => $metadataProperty) {
			if (!$entity->hasValue($name)) {
				$value = null;
			} else {
				$value = $entity->getValue($name);
			}

			if ($value instanceof IEntity) {
				if ($type === self::RELATIONSHIP_AS_ID) {
					$value = $value->getValue('id');
				} elseif ($type === self::RELATIONSHIP_AS_ARRAY) {
					if ($recursionLevel + 1 >= static::$maxRecursionLevel) {
						$value = null;
					} else {
						$value = static::toArray($value, $type, $recursionLevel + 1);
					}
				}

			} elseif ($value instanceof IRelationshipCollection) {
				if ($type === self::RELATIONSHIP_AS_ID) {
					$collection = [];
					foreach ($value as $collectionEntity) {
						$collection[] = $collectionEntity->getValue('id');
					}
					$value = $collection;

				} elseif ($type === self::RELATIONSHIP_AS_ARRAY) {
					$collection = [];
					if ($recursionLevel + 1 < static::$maxRecursionLevel) {
						foreach ($value as $collectionEntity) {
							$collection[] = static::toArray($collectionEntity, $type, $recursionLevel + 1);
						}
					}
					$value = $collection;
				}
			}

			$return[$name] = $value;
		}

		return $return;
	}
public static function toArray(IEntity $entity, int $type = self::RELATIONSHIP_AS_IS, int $recursionLevel = 0): array
	{
		$return = [];
		$metadata = $entity->getMetadata();

		foreach ($metadata->getProperties() as $name => $metadataProperty) {
			if (!$entity->hasValue($name)) {
				$value = null;
			} else {
				$value = $entity->getValue($name);
			}

			if ($value instanceof IEntity) {
				if ($type === self::RELATIONSHIP_AS_ID) {
					$value = $value->getValue('id');
				} elseif ($type === self::RELATIONSHIP_AS_ARRAY) {
					if ($recursionLevel + 1 >= static::$maxRecursionLevel) {
						$value = null;
					} else {
						$value = static::toArray($value, $type, $recursionLevel + 1);
					}
				}

			} elseif ($value instanceof IRelationshipCollection) {
				if ($type === self::RELATIONSHIP_AS_ID) {
					$collection = [];
					foreach ($value as $collectionEntity) {
						$collection[] = $collectionEntity->getValue('id');
					}
					$value = $collection;

				} elseif ($type === self::RELATIONSHIP_AS_ARRAY) {
					$collection = [];
					if ($recursionLevel + 1 < static::$maxRecursionLevel) {
						foreach ($value as $collectionEntity) {
							$collection[] = static::toArray($collectionEntity, $type, $recursionLevel + 1);
						}
					}
					$value = $collection;
				}
			}

			$return[$name] = $value;
		}

		return $return;
	}
public static function toArray ( IEntity $ entity , int $ type = self :: RELATIONSHIP_AS_IS , int $ recursionLevel = 0 ) : array { $ return = [ ] ; $ metadata = $ entity -> getMetadata ( ) ; foreach ( $ metadata -> getProperties ( ) as $ name => $ metadataProperty ) { if ( ! $ entity -> hasValue ( $ name ) ) { $ value = null ; } else { $ value = $ entity -> getValue ( $ name ) ; } if ( $ value instanceof IEntity ) { if ( $ type === self :: RELATIONSHIP_AS_ID ) { $ value = $ value -> getValue ( 'id' ) ; } elseif ( $ type === self :: RELATIONSHIP_AS_ARRAY ) { if ( $ recursionLevel + 1 >= static :: $ maxRecursionLevel ) { $ value = null ; } else { $ value = static :: toArray ( $ value , $ type , $ recursionLevel + 1 ) ; } } } elseif ( $ value instanceof IRelationshipCollection ) { if ( $ type === self :: RELATIONSHIP_AS_ID ) { $ collection = [ ] ; foreach ( $ value as $ collectionEntity ) { $ collection [ ] = $ collectionEntity -> getValue ( 'id' ) ; } $ value = $ collection ; } elseif ( $ type === self :: RELATIONSHIP_AS_ARRAY ) { $ collection = [ ] ; if ( $ recursionLevel + 1 < static :: $ maxRecursionLevel ) { foreach ( $ value as $ collectionEntity ) { $ collection [ ] = static :: toArray ( $ collectionEntity , $ type , $ recursionLevel + 1 ) ; } } $ value = $ collection ; } } $ return [ $ name ] = $ value ; } return $ return ; }
Converts IEntity to an array.
Converts IEntity to an array .