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\Rules;
4
 
5
use Closure;
6
use InvalidArgumentException;
7
 
8
class ProhibitedIf
9
{
10
    /**
11
     * The condition that validates the attribute.
12
     *
13
     * @var \Closure|bool
14
     */
15
    public $condition;
16
 
17
    /**
18
     * Create a new prohibited validation rule based on a condition.
19
     *
20
     * @param  \Closure|bool  $condition
21
     * @return void
22
     *
23
     * @throws \InvalidArgumentException
24
     */
25
    public function __construct($condition)
26
    {
27
        if ($condition instanceof Closure || is_bool($condition)) {
28
            $this->condition = $condition;
29
        } else {
30
            throw new InvalidArgumentException('The provided condition must be a callable or boolean.');
31
        }
32
    }
33
 
34
    /**
35
     * Convert the rule to a validation string.
36
     *
37
     * @return string
38
     */
39
    public function __toString()
40
    {
41
        if (is_callable($this->condition)) {
42
            return call_user_func($this->condition) ? 'prohibited' : '';
43
        }
44
 
45
        return $this->condition ? 'prohibited' : '';
46
    }
47
}