public static function SafeStringTrait::create in Service Container 7.2
Same name and namespace in other branches
- 7 lib/Drupal/Component/Utility/SafeStringTrait.php \Drupal\Component\Utility\SafeStringTrait::create()
Creates a SafeString object if necessary.
If $string is equal to a blank string then it is not necessary to create a SafeString object. If $string is an object that implements SafeStringInterface it is returned unchanged.
Parameters
mixed $string: The string to mark as safe. This value will be cast to a string.
Return value
string|\Drupal\Component\Utility\SafeStringInterface A safe string.
File
- lib/
Drupal/ Component/ Utility/ SafeStringTrait.php, line 37 - Contains \Drupal\Component\Utility\SafeStringTrait.
Class
- SafeStringTrait
- Implements SafeStringInterface and Countable for rendered objects.
Namespace
Drupal\Component\UtilityCode
public static function create($string) {
if ($string instanceof SafeStringInterface) {
return $string;
}
$string = (string) $string;
if ($string === '') {
return '';
}
$safe_string = new static();
$safe_string->string = $string;
return $safe_string;
}