PluginProbe
Metricool – Social media and site statistics / trunk
Metricool – Social media and site statistics vtrunk
2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / app / Support / Validation / Rules / MatchesRule.php

MatchesRule.php in Metricool – Social media and site statistics trunk, at app/Support/Validation/Rules/MatchesRule.php

29 lines 826 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Metricool\Support\Validation\Rules;
6
7 class MatchesRule extends AbstractRule
8 {
9 /**
10 * Checks if the field matches the value of another field, e.g.
11 * "passwordConfirmation" => "matches:password". When no field is given it
12 * falls back to "{field}_confirmation".
13 * @inheritDoc
14 */
15 public function validate(string $field, $value, array $data): void
16 {
17 $otherField = $this->parameters[0] ?? $field . '_confirmation';
18
19 if (!array_key_exists($otherField, $data) || $data[$otherField] !== $value) {
20 $this->fail(sprintf(
21 /* translators: %1$s and %2$s are field names */
22 __('%1$s must match %2$s.', 'metricool'),
23 $field,
24 $otherField
25 ));
26 }
27 }
28 }
29