本文整理汇总了PHP中Doctrine\ODM\MongoDB\MongoDBException::invalidFindByCall方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoDBException::invalidFindByCall方法的具体用法?PHP MongoDBException::invalidFindByCall怎么用?PHP MongoDBException::invalidFindByCall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\MongoDBException
的用法示例。
在下文中一共展示了MongoDBException::invalidFindByCall方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __call
/**
* Adds support for magic finders.
*
* @param string $method
* @param array $arguments
* @throws MongoDBException
* @throws \BadMethodCallException If the method called is an invalid find* method
* or no find* method at all and therefore an invalid
* method call.
* @return array|object The found document/documents.
*/
public function __call($method, $arguments)
{
if (substr($method, 0, 6) == 'findBy') {
$by = substr($method, 6, strlen($method));
$method = 'findBy';
} elseif (substr($method, 0, 9) == 'findOneBy') {
$by = substr($method, 9, strlen($method));
$method = 'findOneBy';
} else {
throw new \BadMethodCallException("Undefined method '{$method}'. The method name must start with " . "either findBy or findOneBy!");
}
if (!isset($arguments[0])) {
throw MongoDBException::findByRequiresParameter($method . $by);
}
$fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
if ($this->class->hasField($fieldName)) {
return $this->{$method}(array($fieldName => $arguments[0]));
} else {
throw MongoDBException::invalidFindByCall($this->documentName, $fieldName, $method . $by);
}
}
示例2: __call
/**
* Adds support for magic finders.
*
* @param string $method
* @param array $arguments
* @throws MongoDBException
* @throws \BadMethodCallException If the method called is an invalid find* method
* or no find* method at all and therefore an invalid
* method call.
* @return array|object The found document/documents.
*/
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);
}
}