123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php namespace System\Validation\Rules;
- use System\Validation\Nullable_Rule;
- class With_Callback extends Nullable_Rule {
-
- public $callback;
-
- public function check($attribute, $attributes)
- {
- if ( ! is_callable($this->callback))
- {
- throw new \Exception("The validation callback for the [$attribute] attribute is not callable.");
- }
- if ( ! is_null($nullable = parent::check($attribute, $attributes)))
- {
- return $nullable;
- }
- return call_user_func($this->callback, $attributes[$attribute]);
- }
-
- public function using($callback)
- {
- $this->callback = $callback;
- return $this;
- }
- }
|