18 return \substr($hay, 0, strlen($needle)) === $needle;
21 public static function contains($needle, $haystack) {
22 return \strpos($haystack, $needle) !==
false;
25 public static function containsValues(array $values,
string $haystack): bool {
26 foreach ($values as $v) {
27 if (\strpos($haystack, $v) !==
false) {
34 public static function endswith($hay, $needle) {
35 return \substr($hay, -strlen($needle)) === $needle;
39 return ($value ===
true || $value ===
'true' || $value == 1) ?
'true' :
'false';
43 return (!isset ($s) ||
null === $s ||
'' === $s);
47 return (isset ($s) &&
null !== $s &&
'' !== $s);
51 return filter_var($s, FILTER_VALIDATE_BOOLEAN) ===
true;
55 return \filter_var($s, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ===
false;
59 return \is_bool($value);
63 return filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !==
null;
75 public static function pluralize($count, $zero, $one, $other) {
79 } elseif ($count === 1) {
82 return \str_replace(
'{count}', $count, $result);
85 public static function firstReplace($haystack, $needle, $replace) {
86 $newstring = $haystack;
87 $pos = \strpos($haystack, $needle);
89 $newstring = \substr_replace($haystack, $replace, $pos, \strlen($needle));
95 $pattern =
'/' . \preg_quote($pattern,
'/') .
'/';
96 return \preg_replace($pattern, $replacement, $subject, 1);
99 public static function replaceArray($haystack, $needleArray, $replace) {
101 foreach ($needleArray as $needle) {
102 $result = self::firstReplace($result, $needle, $replace);
108 if (\is_string($value))
109 return \str_replace(
"\\",
"\\\\", $value);
114 $attr = \preg_replace(
'/[^a-zA-Z0-9\-]/s', $replacement, $attr);
115 while ($attr !== ($attr = \str_replace($replacement . $replacement, $replacement, $attr)))
120 public static function mask($secretString, $maskChar =
"*") {
121 return \str_repeat($maskChar, \strlen($secretString));
125 return \is_scalar($value) || (\is_object($value) && \method_exists($value,
'__toString'));
129 return \is_object(\json_decode($value));
139 if (self::isValid($value)) {
152 public static function explode($delimiters, $string) {
153 return \explode($delimiters [0], \str_replace($delimiters, $delimiters [0], $string));
163 return $v ==
'nonce' || self::startswith($v,
'$') || self::startswith($v,
'function')
164 || self::startswith($v,
'array(') || self::startswith($v,
'getenv(');
static isBooleanStr($value)
static mask($secretString, $maskChar="*")
static startswith($hay, $needle)
static doubleBackSlashes($value)
static endswith($hay, $needle)
static cleanAttribute($attr, $replacement="-")
static contains($needle, $haystack)
static isBooleanFalse($s)
static isExpression(string $v)
Returns true is value is a php expression.
static explode($delimiters, $string)
Explodes a string with an array of delimiters.
static replaceArray($haystack, $needleArray, $replace)
static toString($value)
Converts a value to a string.
static replaceFirstOccurrence($pattern, $replacement, $subject)
static pluralize($count, $zero, $one, $other)
Pluralize an expression.
static getBooleanStr($value)
static firstReplace($haystack, $needle, $replace)
static containsValues(array $values, string $haystack)