Download the PHP package starburst/utils without Composer
On this page you can find all versions of the php package starburst/utils. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package utils
Starburst Utils
Package that contain some common helper classes
Requirements
PHP 8.0 or higher.
Installation
Usage
Json
The Starburst\Utils\Json class provides static methods for encoding and
decoding Json in PHP.
Below, you'll find detailed documentation on how to use it:
encode(mixed $value, bool $encodeNull = true): ?string
This method accepts a variable of any type and converts it to a JSON string.
Parameters:
$value (mixed): The value you want to encode to JSON.$encodeNull (bool): If we should encodenullasstringor not
Returns:
- JSON Encoded string. If
$encodeNullis false this can also return null
Usage:
decode(string $value): mixed
This method accepts a JSON string and decodes it to the corresponding PHP value or array.
Parameters:
$value (string): The JSON string you want to decode.
Returns:
- The PHP value that was encoded in the JSON string. If json is an object it's returned as an assoc array
Usage:
decodeArray(string $value, bool $allowNull = false): ?array
This method decodes a JSON string to an associative array in PHP.
The method throws a JsonException if the decoded value is not an array.
Parameters:
$value (string): The JSON string you want to decode to an array.$allowNull (bool): Allow encoded null values to return null without exception
Returns:
- The associative array that was encoded in the JSON string.
Usage:
decodeList(string $value, bool $allowNull = false): ?array
This method decodes a JSON string to a numeric array (list) in PHP.
The method throws a JsonException if the decoded value is not a list.
Parameters:
$value (string): The JSON string you want to decode to an array.$allowNull (bool): Allow encoded null values to return null without exception
Returns:
- The numeric array (list) that was encoded in the JSON string.
Usage:
Validators
The Starburst\Utils\Validators class provides static methods to validate different types of input.
isUnicode(mixed $value): bool
This function checks if the provided value is a valid UTF-8 string.
Parameters:
$value (mixed): The value you want to check.
Returns:
- True or false. It will always return false for none string types
Usage:
isKennitala(mixed $value): bool
This function checks if the provided value is a valid kennitala.
Parameters:
$value (mixed): The value you want to check.
Returns:
- True or false
Usage:
isEmail(string $value): bool
This function checks if the provided string is a valid email address. Note that it only checks the syntax of the email and not if the email domain actually exists.
Parameters:
$value (string): The value you want to check.
Returns:
- True or false
Usage:
isIcelandicPhoneNumber(string $value): bool
This function checks if the provided string is a valid icelandic phone number.
Parameters:
$value (string): The value you want to check.
Returns:
- True or false
Usage:
Text
Static class that helps normalize texts
normalize(string $value): string
Removes control characters, normalizes line breaks to \n, removes leading and trailing blank lines,
trims end spaces on lines, normalizes UTF-8 to the normal form of NFC.
truncate(string $string, int $maxLen, string $append = "\u{2026}"): string
Truncates a UTF-8 string to a given maximal length while trying not to split whole words. Only if the string is truncated, an ellipsis (or something else set with the third argument) is appended to the string.
slugify(string $string, string $separator = '-', bool $allowPeriod = false, string $locale = 'is'): string
Converts a string into a URL-friendly slug by transliterating characters based on locale-specific rules.
Supported locales: 'de', 'is', 'en', 'ru', 'uk'
normalizeIcelandicPhoneNumber(string $phoneNumber): string
Normalizes a phone number to the format +3541234567.
If it's not a valid Icelandic phone number, throws InvalidArgumentException
GetArrayCopy
Trait that helps convert an object into an assoc array.
It supports value resolvers that can be used to format some properties in a custom way.
Example
Configure custom value resolvers
Path
The Path class provides utility methods for working with file paths in a platform-independent manner.
normalize(string $path): string
Normalizes a given file path.
During normalization, all slashes are replaced by forward slashes ("/"). It also makes sure to remove trailing slashes.
Contrary to canonicalize, this method does not remove invalid or dot path segments. Consequently,
it is much more efficient and should be used whenever the given path is known to be a valid, absolute system path.
Example:
canonicalize(string $path): string
Normalizes and canonicalizes a given file path.
Example:
join(string ...$parts): string
Joins multiple parts into on a normalized and canonicalized path
Example: