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