public function getData(array $whitelist = null)
{
$data = [];
if ($whitelist !== null) {
$whitelist = array_flip($whitelist);
}
$reflection = $this->getCurrentReflection();
$usedGetters = [];
foreach ($reflection->getEntityProperties() as $property) {
$field = $property->getName();
if ($whitelist !== null and !isset($whitelist[$field])) {
continue;
}
$data[$field] = $this->__get($property->getName());
$getter = $property->getGetter();
if ($getter !== null) {
$usedGetters[$getter] = true;
}
}
foreach ($reflection->getGetters() as $name => $getter) {
if (isset($usedGetters[$getter->getName()])) {
continue;
}
$field = lcfirst(substr($name, 3));
if ($whitelist !== null and !isset($whitelist[$field])) {
continue;
}
if ($getter->getNumberOfRequiredParameters() === 0) {
$data[$field] = $getter->invoke($this);
}
}
return $data;
}