Skip to content
Browse files

Additional data to be passed with callback

  • Loading branch information...
1 parent 91a9d43 commit 12bea2b7563b30bf377c2f11ba474acd02606764 @zerkms zerkms committed with shadowhand Jul 11, 2010
Showing with 8 additions and 6 deletions.
  1. +8 −6 classes/kohana/validate.php
View
14 classes/kohana/validate.php
@@ -14,7 +14,7 @@ class Kohana_Validate extends ArrayObject {
* Creates a new Validation instance.
*
* @param array array to use for validation
- * @return object
+ * @return Validate
*/
public static function factory(array $array)
{
@@ -664,7 +664,7 @@ public function rules($field, array $rules)
* @param mixed callback to add
* @return $this
*/
- public function callback($field, $callback)
+ public function callback($field, $callback, array $params = array())
{
if ( ! isset($this->_callbacks[$field]))
{
@@ -681,7 +681,7 @@ public function callback($field, $callback)
if ( ! in_array($callback, $this->_callbacks[$field], TRUE))
{
// Store the callback
- $this->_callbacks[$field][] = $callback;
+ $this->_callbacks[$field][] = array($callback, $params);
}
return $this;
@@ -918,8 +918,10 @@ public function check($allow_empty = FALSE)
continue;
}
- foreach ($set as $callback)
+ foreach ($set as $callback_array)
{
+ list($callback, $params) = $callback_array;
+
if (is_string($callback) AND strpos($callback, '::') !== FALSE)
{
// Make the static callback into an array
@@ -941,15 +943,15 @@ public function check($allow_empty = FALSE)
}
// Call $object->$method($this, $field, $errors) with Reflection
- $method->invoke($object, $this, $field);
+ $method->invoke($object, $this, $field, $params);
}
else
{
// Use a function call
$function = new ReflectionFunction($callback);
// Call $function($this, $field, $errors) with Reflection
- $function->invoke($this, $field);
+ $function->invoke($this, $field, $params);
}
if (isset($this->_errors[$field]))

0 comments on commit 12bea2b

Please sign in to comment.
Something went wrong with that request. Please try again.