mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Add modifiers match, ematch, replace, ereplace, split, esplit, join with documentation
This commit is contained in:
@@ -131,7 +131,11 @@ class Fenom
|
||||
"unescape" => 'Fenom\Modifier::unescape',
|
||||
"strip" => 'Fenom\Modifier::strip',
|
||||
"length" => 'Fenom\Modifier::length',
|
||||
"iterable" => 'Fenom\Modifier::isIterable'
|
||||
"iterable" => 'Fenom\Modifier::isIterable',
|
||||
"replace" => 'Fenom\Modifier::replace',
|
||||
"ereplace" => 'Fenom\Modifier::ereplace',
|
||||
"match" => 'Fenom\Modifier::match',
|
||||
"ematch" => 'Fenom\Modifier::ematch',
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -130,7 +130,7 @@ class Modifier
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip spaces symbols on edge of string end multiple spaces in string
|
||||
* Strip spaces symbols on edge of string end multiple spaces in the string
|
||||
*
|
||||
* @param string $str
|
||||
* @param bool $to_line strip line ends
|
||||
@@ -181,11 +181,102 @@ class Modifier
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public static function isIterable($value)
|
||||
{
|
||||
return is_array($value) || ($value instanceof \Iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all occurrences of the search string with the replacement string
|
||||
* @param string $value The string being searched and replaced on, otherwise known as the haystack.
|
||||
* @param string $search The value being searched for, otherwise known as the needle.
|
||||
* @param string $replace The replacement value that replaces found search
|
||||
* @return mixed
|
||||
*/
|
||||
public static function replace($value, $search, $replace)
|
||||
{
|
||||
return str_replace($search, $replace, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @param string $pattern
|
||||
* @param string $replacement
|
||||
* @return mixed
|
||||
*/
|
||||
public static function ereplace($value, $pattern, $replacement)
|
||||
{
|
||||
return preg_replace($pattern, $replacement, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string $pattern
|
||||
* @return bool
|
||||
*/
|
||||
public static function match($string, $pattern)
|
||||
{
|
||||
return fnmatch($pattern, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string $pattern
|
||||
* @return int
|
||||
*/
|
||||
public static function ematch($string, $pattern)
|
||||
{
|
||||
return preg_match($pattern, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @param string $delimiter
|
||||
* @return array
|
||||
*/
|
||||
public static function split($value, $delimiter = ",")
|
||||
{
|
||||
if(is_string($value)) {
|
||||
return explode($delimiter, $value);
|
||||
} elseif(is_array($value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param string $pattern
|
||||
* @return array
|
||||
*/
|
||||
public static function esplit($value, $pattern = '/,\s*/S')
|
||||
{
|
||||
if(is_string($pattern)) {
|
||||
return preg_split($pattern, $value);
|
||||
} elseif(is_array($value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param string $glue
|
||||
* @return string
|
||||
*/
|
||||
public static function join($value, $glue = ",")
|
||||
{
|
||||
if(is_array($value)) {
|
||||
return implode($glue, $value);
|
||||
} elseif(is_string($value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user