2017-06-22 02:03:54 +02:00
|
|
|
<?php
|
|
|
|
|
2017-10-09 15:23:27 +02:00
|
|
|
namespace dipl\Html;
|
2017-06-22 02:03:54 +02:00
|
|
|
|
|
|
|
class FormattedString implements ValidHtml
|
|
|
|
{
|
|
|
|
protected $escaped = true;
|
|
|
|
|
|
|
|
/** @var ValidHtml[] */
|
|
|
|
protected $arguments = [];
|
|
|
|
|
|
|
|
/** @var ValidHtml */
|
|
|
|
protected $string;
|
|
|
|
|
|
|
|
public function __construct($string, array $arguments = [])
|
|
|
|
{
|
|
|
|
$this->string = Util::wantHtml($string);
|
|
|
|
|
|
|
|
foreach ($arguments as $key => $val) {
|
|
|
|
$this->arguments[$key] = Util::wantHtml($val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function create($string)
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
2018-05-04 22:55:24 +02:00
|
|
|
array_shift($args);
|
|
|
|
|
|
|
|
return new static($string, $args);
|
2017-06-22 02:03:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return vsprintf(
|
|
|
|
$this->string->render(),
|
|
|
|
$this->arguments
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|