com\setasign\SetaFramework\Helper

StringHelper Class StringHelper

File: /SetaFramework/src/Helper/StringHelper.php

Class hierarchy

Summary

Static Methods

callableToString()

public static StringHelper::callableToString (
callable $callable
): string
Parameters
$callable : callable
 

contains()

WARNING: This method is marked as deprecated!

Use str_contains() instead.

public static StringHelper::contains (
string $haystack,
string $needle
): bool

Checks whether $haystack contains $needle.

Parameters
$haystack : string
 
$needle : string
 

endsWith()

WARNING: This method is marked as deprecated!

Use str_ends_with() instead.

public static StringHelper::endsWith (
string $haystack,
string $needle
): bool

Checks whether $haystack ends with $needle.

Parameters
$haystack : string
 
$needle : string
 

fromCamelCase()

public static StringHelper::fromCamelCase (
string $string,
string $delimiter = '-',
bool $ensureCamelcase = true
): string

Converts a camel case string into kebab case (delimiter '-'), snake case (delimiter '_') or normal case (delimiter ' ') string.

Parameters
$string : string
 
$delimiter : string
 
$ensureCamelcase : bool
 

prettyVarExport()

public static StringHelper::prettyVarExport (
mixed $var,
string $indent = '',
string $tab = ' '
): string
Parameters
$var : mixed
 
$indent : string
 
$tab : string
 

startsWith()

WARNING: This method is marked as deprecated!

Use str_starts_with() instead.

public static StringHelper::startsWith (
string $haystack,
string $needle
): bool

Checks whether $haystack starts with $needle.

Parameters
$haystack : string
 
$needle : string
 

toCamelCase()

public static StringHelper::toCamelCase (
string $string,
bool $lowerFirstChar = false
): string

Converts a string to camel case writing style

Parameters
$string : string
 
$lowerFirstChar : bool
 

toString()

public static StringHelper::toString (
callable $try,
?callable $catch = null,
string $fallback = ''
): string

__toString methods must not throw an exception. This helper will catch all exceptions and ignore the errors.

Parameters
$try : callable
 
$catch : ?callable

If $catch is null and an exception is thrown an empty string will be returned.

$fallback : string

Return value on error if $catch is null or throws an exception.

toStringErrorHandler()

public static StringHelper::toStringErrorHandler (
callable $try,
?callable $catch = null,
string $fallback = '',
string $errorLevel = \Psr\Log\LogLevel::ERROR
): string

__toString methods must not throw an exception.

This helper will catch all exceptions and add the exception to the catchedErrors of the errorHandler.

Parameters
$try : callable
 
$catch : ?callable

If $catch is null and an exception is thrown an empty string will be returned.

$fallback : string

Return value on error if $catch is null or throws an exception.

$errorLevel : string

Which error level should be used for the error if an error occurs.