class StringUtil extends Text

CEO String utilities

None of these should be considered cryptographically secure. Yo.

Methods

static boolean
isUuid(string $str)

Determine if passed string is a UUIDv4

static string
uuid()

Generate a (hopefully) unique, time-based UUID

static string
random($length = 25, $prefix = '', $type = null)

Generate random string of a fixed length. Only uses alpha-numeric characters.

static array
parseSrn(string $srn)

Parse a SRN into its component parts. Returns an array with: * client * appid * resource * uuid * extra

static string
sluggify($str, $delim = '-')

Generate slugs

static string
htmlPurify(string $str)

Run dirty html fragments through the purifier

static string
generateToken(int $length = 10)

Generate a relatively random token of a given length.

Details

at line line 20
static boolean isUuid(string $str)

Determine if passed string is a UUIDv4

Parameters

string $str

Return Value

boolean

at line line 30
static string uuid()

Generate a (hopefully) unique, time-based UUID

Return Value

string UUID

at line line 42
static string random($length = 25, $prefix = '', $type = null)

Generate random string of a fixed length. Only uses alpha-numeric characters.

Parameters

$length
$prefix
$type

Return Value

string

at line line 78
static array parseSrn(string $srn)

Parse a SRN into its component parts. Returns an array with: * client * appid * resource * uuid * extra

Example:

    use Ceo\Core\Util\String;

    var_export(String::parseSrn('srn:tsn:ceo-core/user:ec3f361b-6ca7-4d97-8970-099ea4b19419'));

Would give you:

    [
        'client'     => 'tsn',
        'appid'      => 'ceo-core',
        'resource'   => 'user',
        'uuid'       => 'ec3f361b-6ca7-4d97-8970-099ea4b19419',
        'extra'      => ''
    ]

Parameters

string $srn

Return Value

array

at line line 114
static string sluggify($str, $delim = '-')

Generate slugs

Parameters

$str
$delim

Return Value

string slugged string

See also

\Phalcon\Utils\Slug in the incubator

at line line 136
static string htmlPurify(string $str)

Run dirty html fragments through the purifier

In theory, is HTML5 compliant

Parameters

string $str HTML fragment

Return Value

string cleaned fragment

at line line 155
static string generateToken(int $length = 10)

Generate a relatively random token of a given length.

THIS IS NOT CRYPTOGRAPHICALY SECURE and don't use it for that purpose. You're going to have a bad time.

Based on (https://stackoverflow.com/a/1516430) but improved for randomness and security.

Parameters

int $length

Return Value

string