1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<?php
namespace ICanBoogie;
/**
* A formatted string.
*
* The string is formatted by replacing placeholders with the values provided.
*/
class FormattedString
{
/**
* String format.
*
* @var string
*/
protected $format;
/**
* An array of replacements for the placeholders.
*
* @var array
*/
protected $args;
/**
* Initializes the {@link $format} and {@link $args} properties.
*
* @param string $format String format.
* @param array $args Format arguments.
*
* @see format()
*/
public function __construct($format, $args=null)
{
if (!is_array($args))
{
$args = func_get_args();
array_shift($args);
}
$this->format = $format;
$this->args = (array) $args;
}
/**
* Returns the string formatted with the {@link format()} function.
*
* @return string
*/
public function __toString()
{
return format($this->format, $this->args);
}
}