added exception for wrong number of parameters to dynamic finders.

This commit is contained in:
Taylor Otwell 2011-06-22 21:30:48 -05:00
parent 319dcbe777
commit a97b8b7fda
1 changed files with 7 additions and 2 deletions

View File

@ -17,12 +17,12 @@ public static function build($method, $parameters, $query)
// ---------------------------------------------------------
// Strip the "where_" off of the method.
// ---------------------------------------------------------
$method = substr($method, 6);
$finder = substr($method, 6);
// ---------------------------------------------------------
// Split the column names from the connectors.
// ---------------------------------------------------------
$segments = preg_split('/(_and_|_or_)/i', $method, -1, PREG_SPLIT_DELIM_CAPTURE);
$segments = preg_split('/(_and_|_or_)/i', $finder, -1, PREG_SPLIT_DELIM_CAPTURE);
// ---------------------------------------------------------
// The connector variable will determine which connector
@ -44,6 +44,11 @@ public static function build($method, $parameters, $query)
{
if ($segment != '_and_' and $segment != '_or_')
{
if ( ! array_key_exists($index, $parameters))
{
throw new \Exception("Wrong number of parameters for dynamic finder [$method].");
}
$query->where($segment, '=', $parameters[$index], $connector);
$index++;