Добавлена кастомная trim функция для обрезания всех UTF-8 пробелов

This commit is contained in:
ErickSkrauch
2018-01-07 19:08:40 +03:00
parent 27983ef730
commit fb5baa1866
6 changed files with 75 additions and 4 deletions

View File

@@ -1,11 +1,12 @@
<?php
declare(strict_types=1);
namespace common\helpers;
use Ramsey\Uuid\Uuid;
class StringHelper {
public static function getEmailMask(string $email) : string {
public static function getEmailMask(string $email): string {
$username = explode('@', $email)[0];
$usernameLength = mb_strlen($username);
$maskChars = '**';
@@ -29,7 +30,7 @@ class StringHelper {
* @param string $uuid
* @return bool
*/
public static function isUuid(string $uuid) : bool {
public static function isUuid(string $uuid): bool {
try {
Uuid::fromString($uuid);
} catch (\InvalidArgumentException $e) {
@@ -39,4 +40,17 @@ class StringHelper {
return true;
}
/**
* Returns a string with whitespace removed from the start and end of the
* string. Supports the removal of unicode whitespace.
*
* Based on the http://markushedlund.com/dev/trim-unicodeutf-8-whitespace-in-php
*
* @param string $string string to remove whitespaces
* @return string trimmed $string
*/
public static function trim(string $string): string {
return preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $string);
}
}