is_callable instead of method_exists

This commit is contained in:
matteosister 2012-04-09 18:14:45 +02:00
parent c30bbd0c34
commit bd127e6991

View file

@ -42,12 +42,11 @@ class ModelToElasticaAutoTransformer implements ModelToElasticaTransformerInterf
**/
public function transform($object, array $fields)
{
$class = get_class($object);
$array = array();
foreach ($fields as $key) {
$getter = 'get'.ucfirst($key);
if (!method_exists($class, $getter)) {
throw new RuntimeException(sprintf('The getter %s::%s does not exist', $class, $getter));
if (!is_callable(array($object, $getter))) {
throw new RuntimeException(sprintf('The method %s::%s is not callable', get_class($object), $getter));
}
$array[$key] = $this->normalizeValue($object->$getter());
}