Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Validation;
4
 
5
use Illuminate\Contracts\Validation\Rule as RuleContract;
6
 
7
class ClosureValidationRule implements RuleContract
8
{
9
    /**
10
     * The callback that validates the attribute.
11
     *
12
     * @var \Closure
13
     */
14
    public $callback;
15
 
16
    /**
17
     * Indicates if the validation callback failed.
18
     *
19
     * @var bool
20
     */
21
    public $failed = false;
22
 
23
    /**
24
     * The validation error message.
25
     *
26
     * @var string|null
27
     */
28
    public $message;
29
 
30
    /**
31
     * Create a new Closure based validation rule.
32
     *
33
     * @param  \Closure  $callback
34
     * @return void
35
     */
36
    public function __construct($callback)
37
    {
38
        $this->callback = $callback;
39
    }
40
 
41
    /**
42
     * Determine if the validation rule passes.
43
     *
44
     * @param  string  $attribute
45
     * @param  mixed  $value
46
     * @return bool
47
     */
48
    public function passes($attribute, $value)
49
    {
50
        $this->failed = false;
51
 
52
        $this->callback->__invoke($attribute, $value, function ($message) {
53
            $this->failed = true;
54
 
55
            $this->message = $message;
56
        });
57
 
58
        return ! $this->failed;
59
    }
60
 
61
    /**
62
     * Get the validation error message.
63
     *
64
     * @return string
65
     */
66
    public function message()
67
    {
68
        return $this->message;
69
    }
70
}