-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathNestedRules.php
More file actions
41 lines (35 loc) · 906 Bytes
/
NestedRules.php
File metadata and controls
41 lines (35 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace Illuminate\Validation;
use Illuminate\Contracts\Validation\CompilableRules;
class NestedRules implements CompilableRules
{
/**
* The callback to execute.
*
* @var callable
*/
protected $callback;
/**
* Create a new nested rule instance.
*
* @param callable $callback
*/
public function __construct(callable $callback)
{
$this->callback = $callback;
}
/**
* Compile the callback into an array of rules.
*
* @param string $attribute
* @param mixed $value
* @param mixed $data
* @param mixed $context
* @return \stdClass
*/
public function compile($attribute, $value, $data = null, $context = null)
{
$rules = call_user_func($this->callback, $value, $attribute, $data, $context);
return Rule::compile($attribute, $rules, $data);
}
}