Created
November 28, 2016 21:12
-
-
Save gadelkareem/65001169784dc8c72b0e1d6889c43d61 to your computer and use it in GitHub Desktop.
Easily convert Doctrine Entities into readable array for debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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