| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Metricool\Support\Validation\Rules; |
| 6 |
|
| 7 |
class UrlRule extends AbstractRule |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Checks if the field contains a valid URL. |
| 11 |
* @inheritDoc |
| 12 |
*/ |
| 13 |
public function validate(string $field, $value, array $data): void |
| 14 |
{ |
| 15 |
if (!is_string($value) || filter_var($value, FILTER_VALIDATE_URL) === false) { |
| 16 |
$this->fail(sprintf( |
| 17 |
/* translators: %s is the field name */ |
| 18 |
__('%s must be a valid URL.', 'metricool'), |
| 19 |
$field |
| 20 |
)); |
| 21 |
} |
| 22 |
} |
| 23 |
} |
| 24 |
|