|
|
@@ -2,12 +2,7 @@
|
|
|
|
|
|
namespace yiins\helpers;
|
|
|
|
|
|
-/**
|
|
|
- * Created by PhpStorm.
|
|
|
- * User: AlexLcDee
|
|
|
- * Date: 06.02.2017
|
|
|
- * Time: 19:52
|
|
|
- */
|
|
|
+
|
|
|
class HtmlHelper
|
|
|
{
|
|
|
/**
|
|
|
@@ -17,6 +12,24 @@ class HtmlHelper
|
|
|
public static function modelName($model)
|
|
|
{
|
|
|
$modelNameArr = is_object($model) ? explode('\\', get_class($model)) : explode('\\', $model);
|
|
|
+
|
|
|
return array_pop($modelNameArr);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Wrap newlines with tag, passed as second argument
|
|
|
+ * @param string $content
|
|
|
+ * @param string $tag
|
|
|
+ * @param array $htmlOptions
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public static function wrapNewlines($content, $tag = 'p', $htmlOptions = [])
|
|
|
+ {
|
|
|
+ $filteredNewLinesContent = preg_replace('((\r?\n)(?:\r?\n))', '$2', $content);
|
|
|
+ $lines = preg_split('/\r?\n/', $filteredNewLinesContent);
|
|
|
+
|
|
|
+ return implode("\n", array_map(function ($line) use ($tag, $htmlOptions) {
|
|
|
+ return \CHtml::tag($tag, $htmlOptions, $line);
|
|
|
+ }, $lines));
|
|
|
+ }
|
|
|
}
|