Added methods \TgBotLib\Classes\Validate::url, \TgBotLib\Classes\Validate::length, & \TgBotLib\Classes\Validate::isHttps to \TgBotLib\Classes\Validate

This commit is contained in:
Netkas 2023-04-23 17:34:35 -04:00
parent f8c02bceb3
commit b2928875cd
2 changed files with 36 additions and 0 deletions

View file

@ -26,6 +26,7 @@ This update accompanies the release of the [Telegram Bot API 6.7](https://core.t
to `\TgBotLib\Objects\Telegram\InlineKeyboardButton`
* Added methods `\TgBotLib\Objects\Telegram\InlineKeyboardMarkup::removeRow` & `\TgBotLib\Objects\Telegram\InlineKeyboardMarkup::addRow` to `\TgBotLib\Objects\Telegram\InlineKeyboardMarkup`
* Added method `\TgBotLib\Objects\Telegram\WebAppInfo::setUrl` to `\TgBotLib\Objects\Telegram\WebAppInfo`
* Added methods `\TgBotLib\Classes\Validate::url`, `\TgBotLib\Classes\Validate::length`, & `\TgBotLib\Classes\Validate::isHttps` to `\TgBotLib\Classes\Validate`
## [6.6.0] - 2023-04-10

View file

@ -4,5 +4,40 @@
class Validate
{
/**
* Validates if a URL is valid or not
*
* @param string $url
* @return bool
*/
public static function url(string $url): bool
{
return filter_var($url, FILTER_VALIDATE_URL) !== false;
}
/**
* Returns true if the given input is within the specified length range
*
* @param string $input
* @param int $min_length
* @param int $max_length
* @return bool
*/
public static function length(string $input, int $min_length, int $max_length): bool
{
$length = strlen($input);
return $length >= $min_length && $length <= $max_length;
}
/**
* Determines if the given URL is an HTTPS URL
*
* @param string $url
* @return bool
*/
public static function isHttps(string $url): bool
{
return strpos($url, 'https://') === 0;
}
}