achieffment / helpers
该软件包最新版本(1.0.18)没有可用的许可证信息。
我用于PHP开发的实用助手
1.0.18
2024-08-18 11:51 UTC
Requires
- hflabs/dadata: ^22.3
- wapmorgan/morphos: ^3.2
README
composer require achieffment/helpers
助手
use achieffment\helpers\Helper; Helper::print_r($array); // '<pre>printed array</pre>' Helper::var_dump($mixed); // '<pre>dumped data</pre>' echo Helper::makePhoneLink(''); // '' echo Helper::makePhoneLink('', false); // false echo Helper::makePhoneLink('7 (911) 911-91-91'); // +79119119191 echo Helper::makePhoneLink('7 (911) 911-91-91', true, true); // tel:+79119119191 echo Helper::makeMailLink(''); // '' echo Helper::makeMailLink('', false); // false echo Helper::makeMailLink('mail@mail.ru'); // mailto:mail@mail.ru Helper::sendFileLog('data'); // Save to $_SERVER['DOCUMENT_ROOT'] . '/log.log'; Helper::sendFileLog('data', $_SERVER['DOCUMENT_ROOT'] . '/log.log'); // Save to $_SERVER['DOCUMENT_ROOT'] . '/log.log'; Helper::sendFileLog('data', '', true); // Shows time in log Helper::sendFileLog('data', '', true, true); // Appends file
验证
use achieffment\helpers\ValidatorHelper; // make strip_tags, htmlspecialchars, trim and return false if value is empty else return sanitized string $string = '<br>'; $string = ValidatorHelper::validate($string); echo $string; // false $string = '<br>qwe'; $string = ValidatorHelper::validate($string); echo $string; // qwe $string = 'qwerty'; $string = ValidatorHelper::validate($string, 3); // check length echo $string; // false $string = 'qwerty'; $string = ValidatorHelper::validate($string, 0, true); // is number echo $string; // false // make strip_tags, htmlspecialchars, trim if value is not empty and return sanitized string $string = '<br>'; $string = ValidatorHelper::validateEmpty($string, 0, true); // is number echo $string; // '' $string = '<br>qwe'; $string = ValidatorHelper::validateEmpty($string, 0, true); // is number echo $string; // 'qwe' $string = 'qwerty'; $string = ValidatorHelper::validateEmpty($string, 3); // check length echo $string; // '' $string = 'qwerty'; $string = ValidatorHelper::validateEmpty($string, 0, true); // is number echo $string; // '' ValidatorHelper::validatePhone('+7 (111) 111-11-11', 11); // validates phone and check length ValidatorHelper::validateIp('255.255.255.255'); // (true) is ip ValidatorHelper::validateIp('255.255.255.255', false); // (true) is ip and can not be with port ValidatorHelper::validateIp('255.255.255.255:80', true, false); // (true) is ip and has port ValidatorHelper::validateIp('255.255.255.255', true, true); // (true) is ip and can be with port or not
编码
文本编码
use achieffment\helpers\SecurityHelper; $encoded = SecurityHelper::encode('Simple string', 'aes-256-ctr', 'passphrase'); echo $encoded; // 48Fme9BnBDR9DrBGRw== $decoded = SecurityHelper::decode($encoded, 'aes-256-ctr', 'passphrase'); echo $decoded; // Simple string
图像编码
use achieffment\helpers\SecurityHelper; $img = SecurityHelper::getImageContent($_SERVER['DOCUMENT_ROOT'] . '/image.jpg', false, true); if ($img) { // Get encoded data of image $encoded_image = SecurityHelper::encode( $img, 'aes-256-ctr', 'passphrase' ); // Save encoded data to file if ($encoded_image) { file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/image2.jpg', $encoded_image); } } // Get image element $decoded_image = SecurityHelper::getImageElement( $_SERVER['DOCUMENT_ROOT'] . '/image2.jpg', 'title', 'alt', 'lazy', true, 'aes-256-ctr', 'passphrase' ); if ($decoded_image) { echo $decoded_image; // <img src='...' title='title' alt='alt' loading='lazy'> }
城市
按IP
该助手使用DaData服务通过IP定位城市,更多关于https://dadata.ru 和 https://github.com/hflabs/dadata-php)的信息,它仅适用于俄罗斯联邦。
use achieffment\helpers\CityHelper; $cl = new CityHelper('Ухта', 'token', 'secret'); echo $cl->getCityByIp(false); // will not check robots like Yandex, Googlebot and etc. echo $cl->getCityByIp(false, true); // will return city in morph case, for example: Ухте echo $cl->getCityByIp(false, true, 'предложный'); // will return city in given case, for more information read code above
形态
有关案例的更多信息,请访问https://github.com/wapmorgan/Morphos/tree/master。
use achieffment\helpers\CityHelper; echo CityHelper::getCityMorph('Ухта', 'предложный'); // (Ухте) will return city in given case
ReCaptcha
use achieffment\helpers\RecaptchaHelper; echo RecaptchaHelper::reCAPTCHAV3JS('public', '#rcv_token'); // makes js for rcv3 and updates field with name rcv_token echo RecaptchaHelper::reCAPTCHAV3JSOnlyAPI('public'); // makes js for rcv3 echo RecaptchaHelper::reCAPTCHAV3JSOnlyScript('public', '#rcv_token'); // makes scripts for updating field with name rcv_token echo RecaptchaHelper::getRecaptchaLinks(); // get links for reCAPTCHA policy RecaptchaHelper::reCAPTCHAV3Validate('secret', 'token', 'ip'); // sends request with secret and given token and returns true or false
形态
有关案例的更多信息,请访问https://github.com/wapmorgan/Morphos/tree/master。
use achieffment\helpers\MorphHelper; echo getName('Иванов Петр', 'родительный') // Иванова Петра echo getCity('Москва', 'родительный') // Москвы echo getPluralize(10, 'новый дом') // 10 новых домов echo getCardinalNumber(567, 'именительный') // пятьсот шестьдесят семь echo getOrdinalNumber(961, 'именительный') // девятьсот шестьдесят первый echo getTime(time() + 3600) // через 1 час
Telegram
use achieffment\helpers\TelegramHelper; $cl = new TelegramHelper('token', 'chat_id'); $result = $cl->sendMessage($text);