You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Validate implements ParameterAnnotationInterface
23
26
{
24
27
/** @var string */
@@ -29,20 +32,27 @@ class Validate implements ParameterAnnotationInterface
29
32
/**
30
33
* @param array<string, mixed> $values
31
34
*/
32
-
publicfunction__construct(array$values)
35
+
publicfunction__construct($rule = [])
33
36
{
34
-
if (! isset($values['for'])) {
35
-
thrownewBadMethodCallException('The @Validate annotation must be passed a target. For instance: "@Validate(for="$email", rule="email")"');
37
+
$values = $rule;
38
+
if (is_string($values)) {
39
+
$this->rule = $values;
40
+
} else {
41
+
$this->rule = $values['rule'] ?? null;
42
+
if (isset($values['for'])) {
43
+
$this->for = ltrim($values['for'], '$');
44
+
}
36
45
}
37
46
if (! isset($values['rule'])) {
38
-
thrownewBadMethodCallException('The @Validate annotation must be passed a rule. For instance: "@Validate(for="$email", rule="email")"');
47
+
thrownewBadMethodCallException('The @Validate annotation must be passed a rule. For instance: "#Validate("email")" in PHP 8+ or "@Validate(for="$email", rule="email")" in PHP 7+');
39
48
}
40
-
$this->for = ltrim($values['for'], '$');
41
-
$this->rule = $values['rule'] ?? null;
42
49
}
43
50
44
51
publicfunctiongetTarget(): string
45
52
{
53
+
if ($this->for === null) {
54
+
thrownewBadMethodCallException('The @Validate annotation must be passed a target. For instance: "@Validate(for="$email", rule="email")"');
0 commit comments