12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace fphammerle\helpers;
- class StringHelper
- {
- /**
- * @return string
- */
- public static function prepend($prefix, $text)
- {
- if(is_array($text)) {
- $result = [];
- foreach($text as $key => $value) {
- $result[$key] = self::prepend($prefix, $value);
- }
- return $result;
- } else {
- return ($text === null) ? null : ($prefix . $text);
- }
- }
- /**
- * @return string
- */
- public static function append($text, $postfix)
- {
- if(is_array($text)) {
- $result = [];
- foreach($text as $key => $value) {
- $result[$key] = self::append($value, $postfix);
- }
- return $result;
- } else {
- return ($text === null) ? null : ($text . $postfix);
- }
- }
- /**
- * @return string
- */
- public static function embed($prefix, $text, $postfix)
- {
- return self::prepend($prefix, self::append($text, $postfix));
- }
- /**
- * @return string
- */
- public static function embrace($brace, $text)
- {
- return self::embed($brace, $text, $brace);
- }
- /**
- * @return string|null
- */
- public static function implode($glue, array $pieces)
- {
- $pieces = array_filter($pieces);
- if(sizeof($pieces) == 0) {
- return null;
- } else {
- return implode($glue, array_filter($pieces));
- }
- }
- }
|