Skip to content

Instantly share code, notes, and snippets.

@gadelkareem
Created November 28, 2016 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gadelkareem/65001169784dc8c72b0e1d6889c43d61 to your computer and use it in GitHub Desktop.
Save gadelkareem/65001169784dc8c72b0e1d6889c43d61 to your computer and use it in GitHub Desktop.
Easily convert Doctrine Entities into readable array for debugging
<?php
namespace App\Entity;
abstract class BaseEntity
{
public function toArray()
{
$properties['__type'] = get_class($this);
$properties += get_object_vars($this);
foreach ($properties as $key => $value) {
if ($value instanceof BaseEntity) {
$properties[$key] = $value->toArray();
} elseif ($value instanceof \DateTime) {
$properties[$key] = $value->format("Y-m-d H:i:s");
}
}
return $properties;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment