[2.0] Refactor Exceptions from Query and AST\InputParameter into QueryException class.
This commit is contained in:
parent
26a2ec2e63
commit
a9d739a743
@ -209,12 +209,12 @@ final class Query extends AbstractQuery
|
||||
$paramMappings = $this->_parserResult->getParameterMappings();
|
||||
|
||||
if(count($paramMappings) != count($params)) {
|
||||
throw new QueryException("Invalid parameter number: number of bound variables does not match number of tokens");
|
||||
throw QueryException::invalidParameterNumber();
|
||||
}
|
||||
|
||||
foreach ($params as $key => $value) {
|
||||
if(!isset($paramMappings[$key])) {
|
||||
throw new QueryException("Invalid parameter: token ".$key." is not defined in the query.");
|
||||
throw QueryException::unknownParameter($key);
|
||||
}
|
||||
|
||||
if (is_object($value)) {
|
||||
|
@ -43,10 +43,7 @@ class InputParameter extends Node
|
||||
public function __construct($value)
|
||||
{
|
||||
if (strlen($value) == 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
"Invalid parameter format, '".$value."' given, ".
|
||||
"but :<name> or ?<num> expected."
|
||||
);
|
||||
throw \Doctrine\ORM\Query\QueryException::invalidParameterFormat($value);
|
||||
}
|
||||
|
||||
$param = substr($value, 1);
|
||||
|
@ -34,12 +34,11 @@ namespace Doctrine\ORM\Query;
|
||||
*/
|
||||
class QueryException extends \Doctrine\Common\DoctrineException
|
||||
{
|
||||
public static function syntaxError($message)
|
||||
public static function syntaxError($message)
|
||||
{
|
||||
return new self('[Syntax Error] ' . $message);
|
||||
}
|
||||
|
||||
|
||||
public static function semanticalError($message)
|
||||
{
|
||||
return new self('[Semantical Error] ' . $message);
|
||||
@ -49,4 +48,19 @@ class QueryException extends \Doctrine\Common\DoctrineException
|
||||
{
|
||||
return new self('Invalid parameter position: ' . $pos);
|
||||
}
|
||||
|
||||
public static function invalidParameterNumber()
|
||||
{
|
||||
return new self("Invalid parameter number: number of bound variables does not match number of tokens");
|
||||
}
|
||||
|
||||
public static function invalidParameterFormat($value)
|
||||
{
|
||||
return new self('Invalid parameter format, '.$value.' given, but :<name> or ?<num> expected.');
|
||||
}
|
||||
|
||||
public static function unknownParameter($key)
|
||||
{
|
||||
return new self("Invalid parameter: token ".$key." is not defined in the query.");
|
||||
}
|
||||
}
|
@ -130,7 +130,7 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
public function testInvalidInputParameterThrowsException()
|
||||
{
|
||||
$this->setExpectedException("InvalidArgumentException");
|
||||
$this->setExpectedException("Doctrine\ORM\Query\QueryException");
|
||||
|
||||
$q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?');
|
||||
$q->setParameter(1, 'jwage');
|
||||
|
Loading…
x
Reference in New Issue
Block a user