2018-02-28 01:27:35 +03:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace common\validators;
|
|
|
|
|
|
|
|
use yii\validators\Validator;
|
|
|
|
|
|
|
|
class MinecraftServerAddressValidator extends Validator {
|
|
|
|
|
2024-12-02 15:10:55 +05:00
|
|
|
protected function validateValue($value): ?array {
|
2018-02-28 01:27:35 +03:00
|
|
|
// we will add minecraft protocol to help parse_url understand all another parts
|
|
|
|
$urlParts = parse_url('minecraft://' . $value);
|
|
|
|
$cnt = count($urlParts);
|
|
|
|
// scheme will be always presented, so we need to increase expected $cnt by 1
|
|
|
|
if (($cnt === 3 && isset($urlParts['host'], $urlParts['port']))
|
|
|
|
|| ($cnt === 2 && isset($urlParts['host']))
|
|
|
|
) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [$this->message, []];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|