File: /var/www/vhosts/creativefellows.nl/fvr.creativefellows.nl/src/Domain/Field/TextType.php
<?php
namespace App\Domain\Field;
/**
* Lease Term data
*/
final class TextType
{
private $value = null;
function __construct(string $value =null)
{
$this->value = $value;
}
public function value($html_tag = null,$element_class=null)
{
switch($html_tag)
{
default:
return $html_tag == null || !$this->value ? $this->value : "<$html_tag". $this->class($element_class) .">". $this->value ."</$html_tag>";
break;
case "intro":
return $this->makeIntro($this->value,$element_class);
break;
}
}
private function class($element_class)
{
return $element_class != null ? ' class="'. $element_class .'"' : '';
}
public function makeIntro($text,$length=null,$addParagraphtags=false,$sign=null){
$text = preg_replace('/<(h1|h2|h3|h4)[^>]*>([\s\S]*?)<\/(h1|h2|h3|h4)[^>]*>/', '', $text);
$text = trim(strip_tags($text));
$sign = ($sign == null) ? " …" : $sign;
$textlen = strlen($text);
if($textlen < $length && $length!=null) $return = $text;
else
{
$cropAfter = ($length != null) ? $length : 115;
$intro = substr(strip_tags($text), 0, $cropAfter);
$ls = strrpos($intro, " ");
$return = substr($intro, 0, $ls).$sign;
}
return $addParagraphtags == false ? $return : "<p>".$return."</p>";
}
}