本文整理匯總了PHP中Doctrine\ODM\MongoDB\MongoDBException::findByRequiresParameter方法的典型用法代碼示例。如果您正苦於以下問題:PHP MongoDBException::findByRequiresParameter方法的具體用法?PHP MongoDBException::findByRequiresParameter怎麽用?PHP MongoDBException::findByRequiresParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ODM\MongoDB\MongoDBException
的用法示例。
在下文中一共展示了MongoDBException::findByRequiresParameter方法的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);
}
}