public function __call($method, $arguments)
{
if (strpos($method, 'findBy') === 0) {
$by = substr($method, 6, strlen($method));
$method = 'findBy';
} elseif (strpos($method, 'findOneBy') === 0) {
$by = substr($method, 9, strlen($method));
$method = 'findOneBy';
} else {
throw new \BadMethodCallException("Undefined method: '{$method}'. The method name must start with 'findBy' or 'findOneBy'!");
}
if (!isset($arguments[0])) {
throw MongoDBException::findByRequiresParameter($method . $by);
}
$fieldName = Inflector::camelize($by);
if ($this->class->hasField($fieldName)) {
return $this->{$method}(array($fieldName => $arguments[0]));
} else {
throw MongoDBException::invalidFindByCall($this->documentName, $fieldName, $method . $by);
}
}