public function __call($method, $arguments)
{
if (strpos($method, 'findOneBy') === 0) {
$property = substr($method, 9);
$method = 'findOneBy';
} elseif (strpos($method, 'findBy') === 0) {
$property = substr($method, 6);
$method = 'findBy';
} else {
throw new RuntimeException(sprintf("The %s repository class does not have a method %s", get_called_class(), $method));
}
$property = Inflector::tableize($property);
foreach ($arguments as $position => $argument) {
if (is_object($argument)) {
if (!method_exists($argument, 'getRid')) {
throw new RuntimeException("When calling \$repository->find*By*(), you can only pass, as arguments, objects that have the getRid() method (shortly, entitites)");
}
$arguments[$position] = $argument->getRid();
}
}
return $this->{$method}(array($property => $arguments[0]));
}