<?php

namespace Simplyin\Simplyin_W_Plugin\Dto;

abstract class Abstract_Item_DTO {

	public function to_array(): array {
		$vars = get_object_vars( $this );

		foreach ( $vars as $key => $value ) {
			if ( null === $value ) {
				continue;
			}

			if ( $value instanceof self ) {
				$vars[ $key ] = $value->to_array();
			}

			if ( is_array( $value ) ) {
				foreach ( $value as $smallKey => $smallValue ) {
					if ( $smallValue instanceof self ) {
						$vars[ $key ][ $smallKey ] = $smallValue->to_array();
					}
				}
			}
		}

		return $vars;
	}

}
