\app\framework\Component\StdLib\StdObject\StringObjectValidatorTrait

StringObject validator trait.

Summary

Methods
Properties
Constants
contains()
containsAny()
equals()
stringPosition()
startsWith()
endsWith()
longerThan()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

contains()

contains(string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject  $needle) : boolean

Checks if a string contains the given $char.

If the $char is present, true is returned. If you wish to match a string to a regular expression use StringObject:match().

Parameters

string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject $needle

String you wish to check if it exits within the current string.

Returns

boolean —

True if current string contains the $needle. Otherwise false is returned.

containsAny()

containsAny(array|\app\framework\Component\StdLib\StdObject\ArrayObject\ArrayObject  $needle) : boolean

Checks if a string contains any of the given $char.

If any of given $char is present, true is returned.

Parameters

array|\app\framework\Component\StdLib\StdObject\ArrayObject\ArrayObject $needle

Array of characters you wish to check

Returns

boolean —

True if current string contains the $needle. Otherwise false is returned.

equals()

equals(string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject  $string) : boolean

Check if $string is equal to current string.

Note that this comparison is case sensitive and binary safe.

Parameters

string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject $string

String to compare.

Returns

boolean —

True if current string is equal to $string. Otherwise false is returned.

stringPosition()

stringPosition(string  $string, integer  $offset) : integer|boolean

Returns the position of the given $string inside the current string object.

Boolean false is returned if the $string is not present inside the current string. NOTE: Use type validation check in order no to mistake the position '0' (zero) for (bool) false.

Parameters

string $string
integer $offset

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

integer|boolean —

If $string is contained within the current string, the position of $string is returned, otherwise false.

startsWith()

startsWith(string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject  $string) : boolean

Checks if the current string starts with the given $string.

Parameters

string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject $string

String to check.

Returns

boolean —

If current string starts with $string, true is returned, otherwise false.

endsWith()

endsWith(string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject  $string) : boolean

Checks if the current string ends with the given $string.

Parameters

string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject $string

String to check.

Returns

boolean —

If current string ends with $string, true is returned, otherwise false.

longerThan()

longerThan(integer  $num, boolean  $inclusive = false) : boolean

Checks if the string length is great than the given length.

Parameters

integer $num

Length against which you wish to check.

boolean $inclusive

Do you want the check to be inclusive or not. Default is false (not inclusive).

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

boolean —

If current string size is longer than the given $num, true is returned, otherwise false.